File: flint_btreebase.h

package info (click to toggle)
xapian-core 1.0.7-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 13,940 kB
  • ctags: 13,203
  • sloc: cpp: 69,340; sh: 9,355; ansic: 7,251; perl: 782; makefile: 471
file content (150 lines) | stat: -rw-r--r-- 4,140 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* flint_btreebase.h: Btree base file implementation
 *
 * Copyright 1999,2000,2001 BrightStation PLC
 * Copyright 2002,2004,2007,2008 Olly Betts
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#ifndef OM_HGUARD_FLINT_BTREEBASE_H
#define OM_HGUARD_FLINT_BTREEBASE_H

#include <string>

#include <xapian/visibility.h>

#include "flint_types.h"
#include "flint_btreeutil.h"

class XAPIAN_VISIBILITY_DEFAULT FlintTable_base {
    public:
	/** Construct an object with all zero fields. */
	FlintTable_base();

	/** Copy constructor */
	FlintTable_base(const FlintTable_base &other);

	/** Destructor - frees resources. */
	~FlintTable_base();

	/** Read values from a base file.
	 *
	 *  @param name		The base of the filename
	 *  @param ch		The suffix
	 *  @param err_msg	An error string which will be appended
	 *  			to for some errors instead of throwing
	 *  			an exception.
	 *
	 *  @return	true if the read succeeded, or false otherwise.
	 */
	bool read(const std::string &name, char ch, std::string &err_msg);

	uint4 get_revision() const { return revision; }
	uint4 get_block_size() const { return block_size; }
	uint4 get_root() const { return root; }
	uint4 get_level() const { return level; }
	uint4 get_bit_map_size() const { return bit_map_size; }
	uint4 get_item_count() const { return item_count; }
	uint4 get_last_block() const { return last_block; }
	bool get_have_fakeroot() const { return have_fakeroot; }
	bool get_sequential() const { return sequential; }

	void set_revision(uint4 revision_) {
	    revision = revision_;
	}
	void set_block_size(uint4 block_size_) {
	    block_size = block_size_;
	}
	void set_root(uint4 root_) {
	    root = root_;
	}
	void set_level(uint4 level_) {
	    level = level_;
	}
	void set_item_count(uint4 item_count_) {
	    item_count = item_count_;
	}
	void set_have_fakeroot(bool have_fakeroot_) {
	    have_fakeroot = have_fakeroot_;
	}
	void set_sequential(bool sequential_) {
	    sequential = sequential_;
	}

	/** Write the btree base file to disk. */
	void write_to_file(const std::string &filename);

	/* Methods dealing with the bitmap */
	/** true iff block n was free at the start of the transaction on
	 *  the B-tree.
	 */
	bool block_free_at_start(uint4 n) const;

	void free_block(uint4 n);

	uint4 next_free_block();

	bool block_free_now(uint4 n);

	void calculate_last_block();

	/* Only used with fake root blocks */
	void clear_bit_map();

	void commit();

	/* Used by FlintTable::check() */
	bool is_empty() const;

	void swap(FlintTable_base &other);

    private:
	/** private assignment operator - you probably want swap() instead */
	void operator=(const FlintTable_base &other);

	void extend_bit_map();

	/** Do most of the error handling from unpack_uint() */
	bool do_unpack_uint(const char **start, const char *end,
			    uint4 *dest, std::string &err_msg,
			    const std::string &basename,
			    const char *varname);

	/* Decoded values from the base file follow */
	uint4 revision;
	uint4 block_size;
	uint4 root;
	uint4 level;
	uint4 bit_map_size;
	uint4 item_count;
	uint4 last_block;
	bool have_fakeroot;
	bool sequential;

	/* Data related to the bitmap */
	/** byte offset into the bit map below which there
	   are no free blocks */
	uint4 bit_map_low;

	/** the initial state of the bit map of blocks: 1 means in
	   use, 0 means free */
	byte *bit_map0;

	/** the current state of the bit map of blocks */
	byte *bit_map;
};

#endif /* OM_HGUARD_FLINT_BTREEBASE_H */