root / tags / 1.0.8 / xapian-core / backends / flint / flint_btreebase.h

Revision 10154, 4.0 kB (checked in by olly, 10 months ago)

Backport change from trunk:
backends/flint/flint_btreebase.cc,backends/flint/flint_btreebase.h:
Fix assorted comment errors.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* flint_btreebase.h: Btree base file implementation
2 *
3 * Copyright 1999,2000,2001 BrightStation PLC
4 * Copyright 2002,2004,2007,2008 Olly Betts
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19 * USA
20 */
21
22#ifndef OM_HGUARD_FLINT_BTREEBASE_H
23#define OM_HGUARD_FLINT_BTREEBASE_H
24
25#include <string>
26
27#include <xapian/visibility.h>
28
29#include "flint_types.h"
30#include "flint_btreeutil.h"
31
32class XAPIAN_VISIBILITY_DEFAULT FlintTable_base {
33    public:
34        /** Construct an object with all zero fields. */
35        FlintTable_base();
36
37        /** Copy constructor */
38        FlintTable_base(const FlintTable_base &other);
39
40        /** Destructor - frees resources. */
41        ~FlintTable_base();
42
43        /** Read values from a base file.
44         *
45         *  @param name         The base of the filename
46         *  @param ch           The suffix
47         *  @param err_msg      An error string which will be appended
48         *                      to for some errors instead of throwing
49         *                      an exception.
50         *
51         *  @return     true if the read succeeded, or false otherwise.
52         */
53        bool read(const std::string &name, char ch, std::string &err_msg);
54
55        uint4 get_revision() const { return revision; }
56        uint4 get_block_size() const { return block_size; }
57        uint4 get_root() const { return root; }
58        uint4 get_level() const { return level; }
59        uint4 get_bit_map_size() const { return bit_map_size; }
60        uint4 get_item_count() const { return item_count; }
61        uint4 get_last_block() const { return last_block; }
62        bool get_have_fakeroot() const { return have_fakeroot; }
63        bool get_sequential() const { return sequential; }
64
65        void set_revision(uint4 revision_) {
66            revision = revision_;
67        }
68        void set_block_size(uint4 block_size_) {
69            block_size = block_size_;
70        }
71        void set_root(uint4 root_) {
72            root = root_;
73        }
74        void set_level(uint4 level_) {
75            level = level_;
76        }
77        void set_item_count(uint4 item_count_) {
78            item_count = item_count_;
79        }
80        void set_have_fakeroot(bool have_fakeroot_) {
81            have_fakeroot = have_fakeroot_;
82        }
83        void set_sequential(bool sequential_) {
84            sequential = sequential_;
85        }
86
87        /** Write the btree base file to disk. */
88        void write_to_file(const std::string &filename);
89
90        /* Methods dealing with the bitmap */
91        /** true iff block n was free at the start of the transaction on
92         *  the B-tree.
93         */
94        bool block_free_at_start(uint4 n) const;
95
96        void free_block(uint4 n);
97
98        uint4 next_free_block();
99
100        bool block_free_now(uint4 n);
101
102        void calculate_last_block();
103
104        /* Only used with fake root blocks */
105        void clear_bit_map();
106
107        void commit();
108
109        /* Used by FlintTable::check() */
110        bool is_empty() const;
111
112        void swap(FlintTable_base &other);
113
114    private:
115        /** private assignment operator - you probably want swap() instead */
116        void operator=(const FlintTable_base &other);
117
118        void extend_bit_map();
119
120        /** Do most of the error handling from unpack_uint() */
121        bool do_unpack_uint(const char **start, const char *end,
122                            uint4 *dest, std::string &err_msg,
123                            const std::string &basename,
124                            const char *varname);
125
126        /* Decoded values from the base file follow */
127        uint4 revision;
128        uint4 block_size;
129        uint4 root;
130        uint4 level;
131        uint4 bit_map_size;
132        uint4 item_count;
133        uint4 last_block;
134        bool have_fakeroot;
135        bool sequential;
136
137        /* Data related to the bitmap */
138        /** byte offset into the bit map below which there
139           are no free blocks */
140        uint4 bit_map_low;
141
142        /** the initial state of the bit map of blocks: 1 means in
143           use, 0 means free */
144        byte *bit_map0;
145
146        /** the current state of the bit map of blocks */
147        byte *bit_map;
148};
149
150#endif /* OM_HGUARD_FLINT_BTREEBASE_H */
Note: See TracBrowser for help on using the browser.