xapian-core
1.4.26
|
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches. More...
#include <chert_cursor.h>
Public Member Functions | |
ChertCursor (const ChertTable *B) | |
Create a cursor attached to a Btree. More... | |
~ChertCursor () | |
Destroy the ChertCursor. More... | |
bool | read_tag (bool keep_compressed=false) |
Read the tag from the table and store it in current_tag. More... | |
bool | next () |
Advance to the next key. More... | |
bool | prev () |
Move to the previous key. More... | |
bool | find_entry (const string &key) |
Position the cursor on the highest entry with key <= key. More... | |
void | find_entry_lt (const string &key) |
Position the cursor on the highest entry with key < key. More... | |
bool | find_entry_ge (const string &key) |
Position the cursor on the lowest entry with key >= key. More... | |
void | to_end () |
Set the cursor to be off the end of the table. More... | |
bool | after_end () const |
Determine whether cursor is off the end of table. More... | |
const ChertTable * | get_table () const |
Return a pointer to the ChertTable we're a cursor for. More... | |
Public Attributes | |
string | current_key |
Current key pointed to by cursor. More... | |
string | current_tag |
Current tag pointed to by cursor. More... | |
Protected Attributes | |
bool | is_positioned |
Whether the cursor is positioned at a valid entry. More... | |
bool | is_after_end |
Whether the cursor is off the end of the table. More... | |
const ChertTable * | B |
The Btree table. More... | |
Private Types | |
enum | { UNREAD, UNCOMPRESSED, COMPRESSED } |
Status of the current_tag member. More... | |
Private Member Functions | |
ChertCursor (const ChertCursor &) | |
Copying not allowed. More... | |
ChertCursor & | operator= (const ChertCursor &) |
Assignment not allowed. More... | |
void | rebuild () |
Rebuild the cursor. More... | |
void | get_key (string *key) const |
Get the key. More... | |
Private Attributes | |
enum ChertCursor:: { ... } | tag_status |
Status of the current_tag member. More... | |
Cursor * | C |
Pointer to an array of Cursors. More... | |
unsigned long | version |
int | level |
The value of level in the Btree structure. More... | |
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition at line 66 of file chert_cursor.h.
|
private |
Status of the current_tag member.
Enumerator | |
---|---|
UNREAD | |
UNCOMPRESSED | |
COMPRESSED |
Definition at line 94 of file chert_cursor.h.
|
private |
Copying not allowed.
|
explicit |
Create a cursor attached to a Btree.
Creates a cursor, which can be used to remember a position inside the B-tree. The position is simply the item (key and tag) to which the cursor points. A cursor is either positioned or unpositioned, and is initially unpositioned.
NB: You must not try to use a ChertCursor after the Btree it is attached to is destroyed. It's safe to destroy the ChertCursor after the Btree though, you just may not use the ChertCursor.
Definition at line 53 of file chert_cursor.cc.
References BLK_UNUSED, C, level, Cursor::n, and Cursor::p.
ChertCursor::~ChertCursor | ( | ) |
Destroy the ChertCursor.
Definition at line 103 of file chert_cursor.cc.
|
inline |
Determine whether cursor is off the end of table.
Definition at line 238 of file chert_cursor.h.
Referenced by ChertMetadataTermList::at_end(), ChertSpellingWordsList::at_end(), ChertAllTermsList::at_end(), ChertMetadataTermList::next(), ChertSpellingWordsList::next(), ChertAllTermsList::next(), ChertCompact::CursorGt::operator()(), ChertMetadataTermList::skip_to(), ChertSpellingWordsList::skip_to(), and ChertAllTermsList::skip_to().
bool ChertCursor::find_entry | ( | const string & | key | ) |
Position the cursor on the highest entry with key <= key.
If the exact key is found in the table, the cursor will be set to point to it, and the method will return true.
If the key is not found, the cursor will be set to point to the key preceding that asked for, and the method will return false. If there is no key preceding that asked for, the cursor will point to a null key.
Note: Since the B-tree always contains a null key, which precedes everything, a call to ChertCursor::find_entry always results in a valid key being pointed to by the cursor.
Note: Calling this method with a null key, then calling next() will leave the cursor pointing to the first key.
key | The key to look for in the table. |
Definition at line 195 of file chert_cursor.cc.
References Cursor::c, C, CHERT_BTREE_MAX_KEY_LEN, Item_base< T >::component_of(), current_key, DIR_START, get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, rebuild(), RETURN, tag_status, UNREAD, and version.
Referenced by ChertSpellingWordsList::ChertSpellingWordsList(), ChertSynonymTermList::ChertSynonymTermList(), ChertPostListTable::merge_changes(), ChertCompact::merge_docid_keyed(), next(), prev(), and ChertTable::really_empty().
bool ChertCursor::find_entry_ge | ( | const string & | key | ) |
Position the cursor on the lowest entry with key >= key.
Definition at line 243 of file chert_cursor.cc.
References Assert, C, CHERT_BTREE_MAX_KEY_LEN, current_key, get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, rebuild(), RETURN, tag_status, UNREAD, and version.
Referenced by MutableChertCursor::del(), ChertAllTermsList::next(), ChertMetadataTermList::skip_to(), ChertSpellingWordsList::skip_to(), and ChertAllTermsList::skip_to().
|
inline |
Position the cursor on the highest entry with key < key.
Definition at line 218 of file chert_cursor.h.
Referenced by ChertMetadataTermList::ChertMetadataTermList(), and ChertSynonymTermList::ChertSynonymTermList().
|
private |
Get the key.
The key of the item at the cursor is copied into key.
The cursor must be positioned before calling this method.
e.g.
ChertCursor BC(&btree); string key;
// Now do something to each key in the Btree BC.find_entry(string()); // must give result true
while (BC.next()) { BC.get_key(&key); do_something_to(key); }
Definition at line 284 of file chert_cursor.cc.
References Assert, C, is_positioned, Item_base< T >::key(), level, and Key::read().
Referenced by find_entry(), find_entry_ge(), next(), and prev().
|
inline |
Return a pointer to the ChertTable we're a cursor for.
Definition at line 241 of file chert_cursor.h.
bool ChertCursor::next | ( | ) |
Advance to the next key.
If cursor is unpositioned, the result is simply false.
If cursor is positioned, and points to the very last item in the Btree the cursor is made unpositioned, and the result is false. Otherwise the cursor is moved to the next item in the B-tree, and the result is true.
Effectively, ChertCursor::next() loses the position of BC when it drops off the end of the list of items. If this is awkward, one can always arrange for a key to be present which has a rightmost position in a set of keys,
Definition at line 158 of file chert_cursor.cc.
References Assert, C, Item_base< T >::component_of(), current_key, find_entry(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, RETURN, tag_status, UNREAD, and version.
Referenced by MutableChertCursor::del(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), ChertMetadataTermList::next(), ChertSpellingWordsList::next(), ChertAllTermsList::next(), ChertCompact::PostlistCursor::next(), and ChertTable::really_empty().
|
private |
Assignment not allowed.
bool ChertCursor::prev | ( | ) |
Move to the previous key.
This is like ChertCursor::next, but BC is taken to the previous rather than next item.
Definition at line 114 of file chert_cursor.cc.
References Assert, C, current_key, find_entry(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, RETURN, tag_status, UNREAD, and version.
bool ChertCursor::read_tag | ( | bool | keep_compressed = false | ) |
Read the tag from the table and store it in current_tag.
Some cursor users don't need the tag, so for efficiency we only read it when asked to.
keep_compressed | Don't uncompress the tag - e.g. useful if it's just being opaquely copied (default: false). |
Definition at line 293 of file chert_cursor.cc.
References Assert, C, COMPRESSED, current_tag, is_positioned, level, LOGCALL, LOGLINE, RETURN, tag_status, UNCOMPRESSED, and UNREAD.
Referenced by ChertSpellingWordsList::get_termfreq(), ChertTable::is_open(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), and ChertAllTermsList::read_termfreq().
|
private |
Rebuild the cursor.
Called when the table has changed.
Definition at line 73 of file chert_cursor.cc.
References BLK_UNUSED, C, level, Cursor::n, Cursor::p, and version.
Referenced by find_entry(), and find_entry_ge().
|
inline |
Set the cursor to be off the end of the table.
Definition at line 231 of file chert_cursor.h.
Referenced by ChertMetadataTermList::next(), ChertSpellingWordsList::next(), ChertAllTermsList::next(), ChertMetadataTermList::skip_to(), ChertSpellingWordsList::skip_to(), and ChertAllTermsList::skip_to().
|
protected |
The Btree table.
Definition at line 98 of file chert_cursor.h.
Referenced by MutableChertCursor::del().
|
private |
Pointer to an array of Cursors.
Definition at line 102 of file chert_cursor.h.
Referenced by ChertCursor(), find_entry(), find_entry_ge(), get_key(), next(), prev(), read_tag(), rebuild(), and ~ChertCursor().
string ChertCursor::current_key |
Current key pointed to by cursor.
Definition at line 149 of file chert_cursor.h.
Referenced by MutableChertCursor::del(), find_entry(), find_entry_ge(), ChertSpellingWordsList::get_termfreq(), ChertMetadataTermList::get_termname(), ChertSpellingWordsList::get_termname(), ChertPostListTable::merge_changes(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), ChertMetadataTermList::next(), ChertSpellingWordsList::next(), ChertAllTermsList::next(), next(), ChertCompact::CursorGt::operator()(), prev(), ChertMetadataTermList::skip_to(), ChertSpellingWordsList::skip_to(), and ChertAllTermsList::skip_to().
string ChertCursor::current_tag |
Current tag pointed to by cursor.
You must call read_tag to make this value available.
Definition at line 154 of file chert_cursor.h.
Referenced by ChertSpellingWordsList::get_termfreq(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), read_tag(), and ChertAllTermsList::read_termfreq().
|
protected |
Whether the cursor is off the end of the table.
Definition at line 90 of file chert_cursor.h.
Referenced by MutableChertCursor::del(), find_entry(), find_entry_ge(), next(), and prev().
|
protected |
Whether the cursor is positioned at a valid entry.
false initially, and after the cursor has dropped off either end of the list of items
Definition at line 86 of file chert_cursor.h.
Referenced by MutableChertCursor::del(), find_entry(), find_entry_ge(), get_key(), next(), prev(), and read_tag().
|
private |
The value of level in the Btree structure.
Definition at line 107 of file chert_cursor.h.
Referenced by ChertCursor(), ChertTable::empty(), get_key(), read_tag(), rebuild(), and ~ChertCursor().
enum { ... } ChertCursor::tag_status |
Status of the current_tag member.
Referenced by find_entry(), find_entry_ge(), next(), prev(), and read_tag().
|
private |
Definition at line 104 of file chert_cursor.h.
Referenced by find_entry(), find_entry_ge(), next(), prev(), and rebuild().