00001 /* chert_btreebase.h: Btree base file implementation 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2002,2004,2007,2008,2011 Olly Betts 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License as 00008 * published by the Free Software Foundation; either version 2 of the 00009 * License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00019 * USA 00020 */ 00021 00022 #ifndef OM_HGUARD_CHERT_BTREEBASE_H 00023 #define OM_HGUARD_CHERT_BTREEBASE_H 00024 00025 #include <string> 00026 00027 #include <xapian/visibility.h> 00028 00029 #include "chert_types.h" 00030 00031 class XAPIAN_VISIBILITY_DEFAULT ChertTable_base { 00032 public: 00034 ChertTable_base(); 00035 00037 ChertTable_base(const ChertTable_base &other); 00038 00040 ~ChertTable_base(); 00041 00053 bool read(const std::string &name, char ch, bool read_bitmap, 00054 std::string &err_msg); 00055 00056 uint4 get_revision() const { return revision; } 00057 uint4 get_block_size() const { return block_size; } 00058 uint4 get_root() const { return root; } 00059 uint4 get_level() const { return level; } 00060 uint4 get_bit_map_size() const { return bit_map_size; } 00061 chert_tablesize_t get_item_count() const { return item_count; } 00062 uint4 get_last_block() const { return last_block; } 00063 bool get_have_fakeroot() const { return have_fakeroot; } 00064 bool get_sequential() const { return sequential; } 00065 00066 void set_revision(uint4 revision_) { 00067 revision = revision_; 00068 } 00069 void set_block_size(uint4 block_size_) { 00070 block_size = block_size_; 00071 } 00072 void set_root(uint4 root_) { 00073 root = root_; 00074 } 00075 void set_level(uint4 level_) { 00076 level = level_; 00077 } 00078 void set_item_count(chert_tablesize_t item_count_) { 00079 item_count = item_count_; 00080 } 00081 void set_have_fakeroot(bool have_fakeroot_) { 00082 have_fakeroot = have_fakeroot_; 00083 } 00084 void set_sequential(bool sequential_) { 00085 sequential = sequential_; 00086 } 00087 00089 void write_to_file(const std::string &filename, 00090 char base_letter, 00091 const std::string &tablename, 00092 int changes_fd, 00093 const std::string * changes_tail); 00094 00095 /* Methods dealing with the bitmap */ 00099 bool block_free_at_start(uint4 n) const; 00100 00101 void free_block(uint4 n); 00102 00103 uint4 next_free_block(); 00104 00109 bool find_changed_block(uint4 * n); 00110 00111 bool block_free_now(uint4 n); 00112 00113 void calculate_last_block(); 00114 00115 /* Only used with fake root blocks */ 00116 void clear_bit_map(); 00117 00118 void commit(); 00119 00120 /* Used by ChertTable::check() */ 00121 bool is_empty() const; 00122 00123 void swap(ChertTable_base &other); 00124 00125 private: 00127 void operator=(const ChertTable_base &other); 00128 00129 void extend_bit_map(); 00130 00131 /* Decoded values from the base file follow */ 00132 uint4 revision; 00133 uint4 block_size; 00134 uint4 root; 00135 uint4 level; 00136 uint4 bit_map_size; 00137 chert_tablesize_t item_count; 00138 uint4 last_block; 00139 bool have_fakeroot; 00140 bool sequential; 00141 00142 /* Data related to the bitmap */ 00145 uint4 bit_map_low; 00146 00149 byte *bit_map0; 00150 00152 byte *bit_map; 00153 }; 00154 00155 #endif /* OM_HGUARD_CHERT_BTREEBASE_H */