backends/quartz/btree_base.h

Go to the documentation of this file.
00001 /* btree_base.h: Btree base file implementation
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002,2004,2007 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_BTREE_BASE_H
00023 #define OM_HGUARD_BTREE_BASE_H
00024 
00025 #include <xapian/visibility.h>
00026 
00027 #include "quartz_types.h"
00028 #include "btree_util.h"
00029 
00030 class XAPIAN_VISIBILITY_DEFAULT Btree_base {
00031     public:
00034         Btree_base();
00035 
00041         Btree_base(const std::string &name_, char ch);
00042 
00044         Btree_base(const Btree_base &other);
00045 
00047         ~Btree_base();
00048 
00059         bool read(const std::string &name, char ch, std::string &err_msg);
00060 
00061         uint4 get_revision() const { return revision; }
00062         uint4 get_block_size() const { return block_size; }
00063         uint4 get_root() const { return root; }
00064         uint4 get_level() const { return level; }
00065         uint4 get_bit_map_size() const { return bit_map_size; }
00066         uint4 get_item_count() const { return item_count; }
00067         uint4 get_last_block() const { return last_block; }
00068         bool get_have_fakeroot() const { return have_fakeroot; }
00069         bool get_sequential() const { return sequential; }
00070 
00071         void set_revision(uint4 revision_) {
00072             revision = revision_;
00073         }
00074         void set_block_size(uint4 block_size_) {
00075             block_size = block_size_;
00076         }
00077         void set_root(uint4 root_) {
00078             root = root_;
00079         }
00080         void set_level(uint4 level_) {
00081             level = level_;
00082         }
00083         void set_item_count(uint4 item_count_) {
00084             item_count = item_count_;
00085         }
00086         void set_have_fakeroot(bool have_fakeroot_) {
00087             have_fakeroot = have_fakeroot_;
00088         }
00089         void set_sequential(bool sequential_) {
00090             sequential = sequential_;
00091         }
00092 
00094         void write_to_file(const std::string &filename);
00095 
00096         /* Methods dealing with the bitmap */
00100         bool block_free_at_start(uint4 n) const;
00101 
00102         void free_block(uint4 n);
00103 
00104         uint4 next_free_block();
00105 
00106         bool block_free_now(uint4 n);
00107 
00108         void calculate_last_block();
00109 
00110         /* Only used with fake root blocks */
00111         void clear_bit_map();
00112 
00113         void commit();
00114 
00115         /* Used by Btree::check() */
00116         bool is_empty() const;
00117 
00118         void swap(Btree_base &other);
00119 
00120     private:
00122         void operator=(const Btree_base &other);
00123 
00124         void extend_bit_map();
00125 
00127         bool do_unpack_uint(const char **start, const char *end,
00128                             uint4 *dest, std::string &err_msg,
00129                             const std::string &basename,
00130                             const char *varname);
00131 
00132         /* Decoded values from the base file follow */
00133         uint4 revision;
00134         uint4 block_size;
00135         uint4 root;
00136         uint4 level;
00137         uint4 bit_map_size;
00138         uint4 item_count;
00139         uint4 last_block;
00140         bool have_fakeroot;
00141         bool sequential;
00142 
00143         /* Data related to the bitmap */
00146         uint4 bit_map_low;
00147 
00150         byte *bit_map0;
00151 
00153         byte *bit_map;
00154 };
00155 
00156 #endif /* OM_HGUARD_BTREE_BASE_H */

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.