#include <chert_cursor.h>


Public Member Functions | |
| ChertCursor (const ChertTable *B) | |
| Create a cursor attached to a Btree. | |
| ~ChertCursor () | |
| Destroy the ChertCursor. | |
| bool | read_tag (bool keep_compressed=false) |
| Read the tag from the table and store it in current_tag. | |
| bool | next () |
| Advance to the next key. | |
| bool | prev () |
| Move to the previous key. | |
| bool | find_entry (const string &key) |
| Position the cursor on the highest entry with key <= key. | |
| void | find_entry_lt (const string &key) |
| Position the cursor on the highest entry with key < key. | |
| bool | find_entry_ge (const string &key) |
| Position the cursor on the lowest entry with key >= key. | |
| void | to_end () |
| Set the cursor to be off the end of the table. | |
| bool | after_end () const |
| Determine whether cursor is off the end of table. | |
| const ChertTable * | get_table () const |
| Return a pointer to the ChertTable we're a cursor for. | |
Public Attributes | |
| string | current_key |
| Current key pointed to by cursor. | |
| string | current_tag |
| Current tag pointed to by cursor. | |
Protected Attributes | |
| bool | is_positioned |
| Whether the cursor is positioned at a valid entry. | |
| bool | is_after_end |
| Whether the cursor is off the end of the table. | |
| const ChertTable * | B |
| The Btree table. | |
Private Types | |
| enum | { UNREAD, UNCOMPRESSED, COMPRESSED } |
| Status of the current_tag member. More... | |
Private Member Functions | |
| ChertCursor (const ChertCursor &) | |
| Copying not allowed. | |
| ChertCursor & | operator= (const ChertCursor &) |
| Assignment not allowed. | |
| void | rebuild () |
| Rebuild the cursor. | |
| void | get_key (string *key) const |
| Get the key. | |
Private Attributes | |
| enum ChertCursor:: { ... } | tag_status |
| Status of the current_tag member. | |
| Cursor * | C |
| Pointer to an array of Cursors. | |
| unsigned long | version |
| int | level |
| The value of level in the Btree structure. | |
Definition at line 67 of file chert_cursor.h.
anonymous enum [private] |
| ChertCursor::ChertCursor | ( | const ChertCursor & | ) | [private] |
Copying not allowed.
| ChertCursor::ChertCursor | ( | const ChertTable * | B | ) |
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 B, BLK_UNUSED, ChertTable::block_size, ChertTable::C, C, ChertTable::cursor_created_since_last_modification, level, Cursor::n, and Cursor::p.
| ChertCursor::~ChertCursor | ( | ) |
| bool ChertCursor::after_end | ( | ) | const [inline] |
Determine whether cursor is off the end of table.
Definition at line 239 of file chert_cursor.h.
Referenced by ChertSynonymTermList::at_end(), ChertSpellingWordsList::at_end(), ChertMetadataTermList::at_end(), ChertAllTermsList::at_end(), ChertValueList::check(), ChertValueList::next(), ChertSynonymTermList::next(), ChertSpellingWordsList::next(), ChertMetadataTermList::next(), ChertAllTermsList::next(), ChertCompact::CursorGt::operator()(), ChertValueList::skip_to(), ChertSynonymTermList::skip_to(), ChertSpellingWordsList::skip_to(), ChertMetadataTermList::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 194 of file chert_cursor.cc.
References B, Cursor::c, C, CHERT_BTREE_MAX_KEY_LEN, current_key, ChertTable::cursor_version, DIR_START, ChertTable::find(), ChertTable::form_key(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, ChertTable::prev(), rebuild(), RETURN, tag_status, UNREAD, and version.
Referenced by ChertValueList::check(), ChertSpellingWordsList::ChertSpellingWordsList(), ChertSynonymTermList::ChertSynonymTermList(), ChertPostListTable::merge_changes(), ChertCompact::merge_docid_keyed(), ChertCompact::MergeCursor::MergeCursor(), next(), ChertCompact::PostlistCursor::PostlistCursor(), prev(), ChertTable::really_empty(), and ChertValueList::skip_to().
| bool ChertCursor::find_entry_ge | ( | const string & | key | ) |
Position the cursor on the lowest entry with key >= key.
Definition at line 242 of file chert_cursor.cc.
References Assert, B, C, CHERT_BTREE_MAX_KEY_LEN, current_key, ChertTable::cursor_version, ChertTable::find(), ChertTable::form_key(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, ChertTable::next(), rebuild(), RETURN, tag_status, UNREAD, and version.
Referenced by MutableChertCursor::del(), ChertValueList::next(), ChertAllTermsList::next(), ChertSynonymTermList::skip_to(), ChertSpellingWordsList::skip_to(), ChertMetadataTermList::skip_to(), and ChertAllTermsList::skip_to().
| void ChertCursor::find_entry_lt | ( | const string & | key | ) | [inline] |
Position the cursor on the highest entry with key < key.
Definition at line 219 of file chert_cursor.h.
Referenced by ChertMetadataTermList::ChertMetadataTermList(), and ChertSynonymTermList::ChertSynonymTermList().
| void ChertCursor::get_key | ( | string * | key | ) | const [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 283 of file chert_cursor.cc.
References Assert, B, C, is_positioned, level, and ChertTable::level.
Referenced by find_entry(), find_entry_ge(), next(), and prev().
| const ChertTable* ChertCursor::get_table | ( | ) | const [inline] |
Return a pointer to the ChertTable we're a cursor for.
Definition at line 242 of file chert_cursor.h.
Referenced by ChertCompact::MergeCursor::~MergeCursor(), and ChertCompact::PostlistCursor::~PostlistCursor().
| 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,
Reimplemented in ChertCompact::PostlistCursor.
Definition at line 157 of file chert_cursor.cc.
References Assert, B, C, current_key, ChertTable::cursor_version, find_entry(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, ChertTable::next(), RETURN, tag_status, UNREAD, and version.
Referenced by MutableChertCursor::del(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), ChertCompact::MergeCursor::MergeCursor(), ChertValueList::next(), ChertSynonymTermList::next(), ChertSpellingWordsList::next(), ChertMetadataTermList::next(), ChertCompact::PostlistCursor::next(), ChertAllTermsList::next(), ChertTable::really_empty(), and ChertValueList::skip_to().
| ChertCursor& ChertCursor::operator= | ( | const ChertCursor & | ) | [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 113 of file chert_cursor.cc.
References Assert, B, C, current_key, ChertTable::cursor_version, find_entry(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, ChertTable::prev(), 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 292 of file chert_cursor.cc.
References Assert, B, C, COMPRESSED, current_tag, is_positioned, level, ChertTable::level, LOGCALL, LOGLINE, ChertTable::next(), ChertTable::read_tag(), RETURN, tag_status, UNCOMPRESSED, and UNREAD.
Referenced by ChertSpellingWordsList::get_termfreq(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), ChertCompact::PostlistCursor::next(), ChertAllTermsList::read_termfreq_and_collfreq(), and ChertValueList::update_reader().
| void ChertCursor::rebuild | ( | ) | [private] |
Rebuild the cursor.
Called when the table has changed.
Definition at line 73 of file chert_cursor.cc.
References B, BLK_UNUSED, ChertTable::block_size, ChertTable::C, C, ChertTable::cursor_version, level, ChertTable::level, Cursor::n, Cursor::p, and version.
Referenced by find_entry(), and find_entry_ge().
| void ChertCursor::to_end | ( | ) | [inline] |
Set the cursor to be off the end of the table.
Definition at line 232 of file chert_cursor.h.
Referenced by ChertSynonymTermList::next(), ChertSpellingWordsList::next(), ChertMetadataTermList::next(), ChertAllTermsList::next(), ChertSynonymTermList::skip_to(), ChertSpellingWordsList::skip_to(), ChertMetadataTermList::skip_to(), and ChertAllTermsList::skip_to().
const ChertTable* ChertCursor::B [protected] |
The Btree table.
Definition at line 99 of file chert_cursor.h.
Referenced by ChertCursor(), MutableChertCursor::del(), find_entry(), find_entry_ge(), get_key(), next(), prev(), read_tag(), and rebuild().
Cursor* ChertCursor::C [private] |
Pointer to an array of Cursors.
Definition at line 103 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 150 of file chert_cursor.h.
Referenced by MutableChertCursor::del(), find_entry(), find_entry_ge(), ChertSpellingWordsList::get_termfreq(), ChertSynonymTermList::get_termname(), ChertSpellingWordsList::get_termname(), ChertMetadataTermList::get_termname(), ChertPostListTable::merge_changes(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), ChertSynonymTermList::next(), ChertSpellingWordsList::next(), ChertMetadataTermList::next(), next(), ChertCompact::PostlistCursor::next(), ChertAllTermsList::next(), ChertCompact::CursorGt::operator()(), prev(), ChertSynonymTermList::skip_to(), ChertSpellingWordsList::skip_to(), ChertMetadataTermList::skip_to(), ChertAllTermsList::skip_to(), and ChertValueList::update_reader().
| string ChertCursor::current_tag |
Current tag pointed to by cursor.
You must call read_tag to make this value available.
Definition at line 155 of file chert_cursor.h.
Referenced by ChertSpellingWordsList::get_termfreq(), ChertCompact::merge_docid_keyed(), ChertCompact::merge_spellings(), ChertCompact::merge_synonyms(), ChertCompact::PostlistCursor::next(), read_tag(), ChertAllTermsList::read_termfreq_and_collfreq(), and ChertValueList::update_reader().
bool ChertCursor::is_after_end [protected] |
Whether the cursor is off the end of the table.
Definition at line 91 of file chert_cursor.h.
Referenced by MutableChertCursor::del(), find_entry(), find_entry_ge(), next(), and prev().
bool ChertCursor::is_positioned [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 87 of file chert_cursor.h.
Referenced by MutableChertCursor::del(), find_entry(), find_entry_ge(), get_key(), next(), prev(), and read_tag().
int ChertCursor::level [private] |
The value of level in the Btree structure.
Definition at line 108 of file chert_cursor.h.
Referenced by ChertCursor(), ChertTable::empty(), get_key(), read_tag(), rebuild(), and ~ChertCursor().
enum { ... } ChertCursor::tag_status [private] |
Status of the current_tag member.
Referenced by find_entry(), find_entry_ge(), next(), prev(), and read_tag().
unsigned long ChertCursor::version [private] |
Definition at line 105 of file chert_cursor.h.
Referenced by find_entry(), find_entry_ge(), next(), prev(), and rebuild().