00001 /* brass_btreebase.h: Btree base file implementation 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2002,2004,2007,2008,2009,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_BRASS_BTREEBASE_H 00023 #define OM_HGUARD_BRASS_BTREEBASE_H 00024 00025 #include <string> 00026 00027 #include <xapian/visibility.h> 00028 00029 #include "brass_types.h" 00030 00031 class XAPIAN_VISIBILITY_DEFAULT BrassTable_base { 00032 public: 00034 BrassTable_base(); 00035 00037 ~BrassTable_base(); 00038 00050 bool read(const std::string &name, char ch, bool read_bitmap, 00051 std::string &err_msg); 00052 00053 uint4 get_revision() const { return revision; } 00054 uint4 get_block_size() const { return block_size; } 00055 uint4 get_root() const { return root; } 00056 uint4 get_level() const { return level; } 00057 uint4 get_bit_map_size() const { return bit_map_size; } 00058 brass_tablesize_t get_item_count() const { return item_count; } 00059 uint4 get_last_block() const { return last_block; } 00060 bool get_have_fakeroot() const { return have_fakeroot; } 00061 bool get_sequential() const { return sequential; } 00062 00063 void set_revision(uint4 revision_) { 00064 revision = revision_; 00065 } 00066 void set_block_size(uint4 block_size_) { 00067 block_size = block_size_; 00068 } 00069 void set_root(uint4 root_) { 00070 root = root_; 00071 } 00072 void set_level(uint4 level_) { 00073 level = level_; 00074 } 00075 void set_item_count(brass_tablesize_t item_count_) { 00076 item_count = item_count_; 00077 } 00078 void set_have_fakeroot(bool have_fakeroot_) { 00079 have_fakeroot = have_fakeroot_; 00080 } 00081 void set_sequential(bool sequential_) { 00082 sequential = sequential_; 00083 } 00084 00086 void write_to_file(const std::string &filename, 00087 char base_letter, 00088 const std::string &tablename, 00089 int changes_fd, 00090 const std::string * changes_tail); 00091 00092 /* Methods dealing with the bitmap */ 00096 bool block_free_at_start(uint4 n) const; 00097 00098 void free_block(uint4 n); 00099 00100 uint4 next_free_block(); 00101 00106 bool find_changed_block(uint4 * n); 00107 00108 bool block_free_now(uint4 n); 00109 00110 void calculate_last_block(); 00111 00112 /* Only used with fake root blocks */ 00113 void clear_bit_map(); 00114 00115 void commit(); 00116 00117 /* Used by BrassTable::check() */ 00118 bool is_empty() const; 00119 00120 void swap(BrassTable_base &other); 00121 00122 private: 00124 BrassTable_base(const BrassTable_base &); 00125 00127 void operator=(const BrassTable_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 brass_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_BRASS_BTREEBASE_H */