xapian-core  1.4.21
chert_btreebase.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002,2004,2007,2008,2011,2012 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #ifndef OM_HGUARD_CHERT_BTREEBASE_H
24 #define OM_HGUARD_CHERT_BTREEBASE_H
25 
26 #include <string>
27 
28 #include "chert_types.h"
29 
31  public:
34 
37 
49  bool read(const std::string &name, char ch, bool read_bitmap,
50  std::string &err_msg);
51 
52  uint4 get_revision() const { return revision; }
53  uint4 get_block_size() const { return block_size; }
54  uint4 get_root() const { return root; }
55  uint4 get_level() const { return level; }
56  uint4 get_bit_map_size() const { return bit_map_size; }
58  uint4 get_last_block() const { return last_block; }
59  bool get_have_fakeroot() const { return have_fakeroot; }
60  bool get_sequential() const { return sequential; }
61 
62  void set_revision(uint4 revision_) {
63  revision = revision_;
64  }
65  void set_block_size(uint4 block_size_) {
66  block_size = block_size_;
67  }
68  void set_root(uint4 root_) {
69  root = root_;
70  }
71  void set_level(uint4 level_) {
72  level = level_;
73  }
74  void set_item_count(chert_tablesize_t item_count_) {
75  item_count = item_count_;
76  }
77  void set_have_fakeroot(bool have_fakeroot_) {
78  have_fakeroot = have_fakeroot_;
79  }
80  void set_sequential(bool sequential_) {
81  sequential = sequential_;
82  }
83 
85  void write_to_file(const std::string &filename,
86  char base_letter,
87  const std::string &tablename,
88  int changes_fd,
89  const std::string * changes_tail);
90 
91  /* Methods dealing with the bitmap */
95  bool block_free_at_start(uint4 n) const;
96 
97  void free_block(uint4 n);
98 
99  void mark_block(uint4 n);
100 
102 
107  bool find_changed_block(uint4 * n) const;
108 
109  bool block_free_now(uint4 n) const;
110 
111  void calculate_last_block();
112 
113  /* Only used with fake root blocks */
114  void clear_bit_map();
115 
116  void commit();
117 
118  void swap(ChertTable_base &other);
119 
120  private:
123 
125  void operator=(const ChertTable_base &other);
126 
127  void extend_bit_map();
128 
129  /* Decoded values from the base file follow */
139 
140  /* Data related to the bitmap */
144 
147  uint8_t *bit_map0;
148 
150  uint8_t *bit_map;
151 };
152 
153 #endif /* OM_HGUARD_CHERT_BTREEBASE_H */
uint4 bit_map_low
byte offset into the bit map below which there are no free blocks
bool get_sequential() const
bool get_have_fakeroot() const
void set_level(uint4 level_)
void swap(ChertTable_base &other)
~ChertTable_base()
Destructor - frees resources.
bool block_free_now(uint4 n) const
Types used by chert backend and the Btree manager.
chert_tablesize_t get_item_count() const
void set_have_fakeroot(bool have_fakeroot_)
chert_tablesize_t item_count
void set_sequential(bool sequential_)
uint4 get_block_size() const
uint32_t uint4
Definition: internaltypes.h:32
uint4 get_level() const
unsigned long long chert_tablesize_t
A type used to store the number of entries in a table.
Definition: chert_types.h:46
void set_root(uint4 root_)
bool find_changed_block(uint4 *n) const
Find the first changed block at or after position *n.
bool read(const std::string &name, char ch, bool read_bitmap, std::string &err_msg)
Read values from a base file.
void set_item_count(chert_tablesize_t item_count_)
uint4 get_root() const
void set_block_size(uint4 block_size_)
uint4 get_revision() const
uint4 get_bit_map_size() const
void operator=(const ChertTable_base &other)
private assignment operator - you probably want swap() instead
void write_to_file(const std::string &filename, char base_letter, const std::string &tablename, int changes_fd, const std::string *changes_tail)
Write the btree base file to disk.
bool block_free_at_start(uint4 n) const
true iff block n was free at the start of the transaction on the B-tree.
uint8_t * bit_map
the current state of the bit map of blocks
uint4 get_last_block() const
void mark_block(uint4 n)
void free_block(uint4 n)
Definition: header.h:151
uint8_t * bit_map0
the initial state of the bit map of blocks: 1 means in use, 0 means free
ChertTable_base()
Construct an object with all zero fields.
void set_revision(uint4 revision_)