xapian-core  1.4.25
chert_cursor.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002,2003,2004,2006,2007,2008,2010 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_CURSOR_H
24 #define OM_HGUARD_CHERT_CURSOR_H
25 
26 #include "chert_types.h"
27 
28 #include <string>
29 using std::string;
30 
31 #define BLK_UNUSED uint4(-1)
32 
33 class Cursor {
34  private:
35  // Prevent copying
36  Cursor(const Cursor &);
37  Cursor & operator=(const Cursor &);
38 
39  public:
41  Cursor() : p(0), c(-1), n(BLK_UNUSED), rewrite(false)
42  {}
43 
45  uint8_t * p;
47  int c;
58  bool rewrite;
59 };
60 
61 class ChertTable;
62 
66 class ChertCursor {
67  private:
69  ChertCursor(const ChertCursor &);
70 
73 
78  void rebuild();
79 
80  protected:
87 
91 
92  private:
94  enum { UNREAD, UNCOMPRESSED, COMPRESSED } tag_status;
95 
96  protected:
98  const ChertTable * B;
99 
100  private:
103 
104  unsigned long version;
105 
107  int level;
108 
128  void get_key(string * key) const;
129 
130  public:
142  explicit ChertCursor(const ChertTable *B);
143 
145  ~ChertCursor();
146 
149  string current_key;
150 
154  string current_tag;
155 
168  bool read_tag(bool keep_compressed = false);
169 
184  bool next();
185 
191  bool prev();
192 
215  bool find_entry(const string &key);
216 
218  void find_entry_lt(const string &key) {
219  if (find_entry(key)) prev();
220  }
221 
227  bool find_entry_ge(const string &key);
228 
231  void to_end() { is_after_end = true; }
232 
238  bool after_end() const { return is_after_end; }
239 
241  const ChertTable * get_table() const { return B; }
242 };
243 
245  public:
259  explicit MutableChertCursor(ChertTable *B_) : ChertCursor(B_) { }
260 
266  bool del();
267 };
268 
269 #endif /* OM_HGUARD_CHERT_CURSOR_H */
bool is_positioned
Whether the cursor is positioned at a valid entry.
Definition: chert_cursor.h:86
Cursor & operator=(const Cursor &)
int c
offset in the block&#39;s directory
Definition: chert_cursor.h:47
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: chert_cursor.h:66
const ChertTable * B
The Btree table.
Definition: chert_cursor.h:98
int level
The value of level in the Btree structure.
Definition: chert_cursor.h:107
Cursor * C
Pointer to an array of Cursors.
Definition: chert_cursor.h:102
Class managing a Btree table in a Chert database.
Definition: chert_table.h:347
void to_end()
Set the cursor to be off the end of the table.
Definition: chert_cursor.h:231
#define BLK_UNUSED
Definition: chert_cursor.h:31
#define false
Definition: header.h:9
MutableChertCursor(ChertTable *B_)
Create a mutable cursor attached to a Btree.
Definition: chert_cursor.h:259
Types used by chert backend and the Btree manager.
string current_tag
Current tag pointed to by cursor.
Definition: chert_cursor.h:154
bool is_after_end
Whether the cursor is off the end of the table.
Definition: chert_cursor.h:90
uint32_t uint4
Definition: internaltypes.h:32
Cursor()
Constructor, to initialise important elements.
Definition: chert_cursor.h:41
bool rewrite
true if the block is not the same as on disk, and so needs rewriting
Definition: chert_cursor.h:58
uint8_t * p
pointer to a block
Definition: chert_cursor.h:45
bool after_end() const
Determine whether cursor is off the end of table.
Definition: chert_cursor.h:238
string current_key
Current key pointed to by cursor.
Definition: chert_cursor.h:149
uint4 n
block number
Definition: chert_cursor.h:56
void find_entry_lt(const string &key)
Position the cursor on the highest entry with key < key.
Definition: chert_cursor.h:218
unsigned long version
Definition: chert_cursor.h:104
const ChertTable * get_table() const
Return a pointer to the ChertTable we&#39;re a cursor for.
Definition: chert_cursor.h:241