FlintCursor Class Reference

A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches. More...

#include <flint_cursor.h>

Inheritance diagram for FlintCursor:

Inheritance graph
[legend]
Collaboration diagram for FlintCursor:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 FlintCursor (FlintTable *B)
 Create a cursor attached to a Btree.
 ~FlintCursor ()
 Destroy the FlintCursor.
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.
bool del ()
 Delete the current key/tag pair, leaving the cursor on the next entry.
FlintTableget_table () const
 Return a pointer to the FlintTable 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.

Private Types

enum  { UNREAD, UNCOMPRESSED, COMPRESSED }
 Status of the current_tag member. More...

Private Member Functions

 FlintCursor (const FlintCursor &)
 Copying not allowed.
FlintCursoroperator= (const FlintCursor &)
 Assignment not allowed.
void rebuild ()
 Rebuild the cursor.
void get_key (string *key) const
 Get the key.

Private 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.
enum FlintCursor:: { ... }  tag_status
 Status of the current_tag member.
FlintTableB
 The Btree table.
Cursor_C
 Pointer to an array of Cursors.
unsigned long version
int level
 The value of level in the Btree structure.


Detailed Description

A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.

Definition at line 67 of file flint_cursor.h.


Member Enumeration Documentation

anonymous enum [private]

Status of the current_tag member.

Enumerator:
UNREAD 
UNCOMPRESSED 
COMPRESSED 

Definition at line 93 of file flint_cursor.h.


Constructor & Destructor Documentation

FlintCursor::FlintCursor ( const FlintCursor  )  [private]

Copying not allowed.

FlintCursor::FlintCursor ( FlintTable 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 FlintCursor after the Btree it is attached to is destroyed. It's safe to destroy the FlintCursor after the Btree though, you just may not use the FlintCursor.

Definition at line 53 of file flint_cursor.cc.

References B, BLK_UNUSED, FlintTable::block_size, FlintTable::C, C, FlintTable::cursor_created_since_last_modification, level, Cursor_::n, and Cursor_::p.

FlintCursor::~FlintCursor (  ) 

Destroy the FlintCursor.

Definition at line 102 of file flint_cursor.cc.

References C, level, and Cursor_::p.


Member Function Documentation

bool FlintCursor::after_end (  )  const [inline]

bool FlintCursor::del (  ) 

Delete the current key/tag pair, leaving the cursor on the next entry.

Returns:
false if the cursor ends up unpositioned.

Definition at line 315 of file flint_cursor.cc.

References Assert, B, current_key, FlintTable::del(), find_entry_ge(), is_after_end, is_positioned, and next().

bool FlintCursor::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 FlintCursor::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.

Parameters:
key The key to look for in the table.
Returns:
true if the exact key was found in the table, false otherwise.

Definition at line 194 of file flint_cursor.cc.

References B, Cursor_::c, C, current_key, FlintTable::cursor_version, DIR_START, FlintTable::find(), FLINT_BTREE_MAX_KEY_LEN, FlintTable::form_key(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, FlintTable::prev(), rebuild(), RETURN, tag_status, UNREAD, and version.

Referenced by copy_docid_keyed(), copy_position(), copy_postlist(), copy_termlist(), copy_unchanged(), FlintSpellingWordsList::FlintSpellingWordsList(), FlintSynonymTermList::FlintSynonymTermList(), main(), FlintCompact::merge_docid_keyed(), FlintCompact::MergeCursor::MergeCursor(), next(), FlintCompact::PostlistCursor::PostlistCursor(), prev(), and FlintTable::really_empty().

bool FlintCursor::find_entry_ge ( const string &  key  ) 

void FlintCursor::find_entry_lt ( const string &  key  )  [inline]

Position the cursor on the highest entry with key < key.

Definition at line 215 of file flint_cursor.h.

Referenced by FlintMetadataTermList::FlintMetadataTermList(), and FlintSynonymTermList::FlintSynonymTermList().

void FlintCursor::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.

FlintCursor 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 flint_cursor.cc.

References Assert, B, C, is_positioned, level, and FlintTable::level.

Referenced by find_entry(), find_entry_ge(), next(), and prev().

FlintTable* FlintCursor::get_table (  )  const [inline]

Return a pointer to the FlintTable we're a cursor for.

Definition at line 245 of file flint_cursor.h.

Referenced by FlintCompact::MergeCursor::~MergeCursor(), and FlintCompact::PostlistCursor::~PostlistCursor().

bool FlintCursor::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, FlintCursor::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 FlintCompact::PostlistCursor.

Definition at line 157 of file flint_cursor.cc.

References Assert, B, C, current_key, FlintTable::cursor_version, find_entry(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, FlintTable::next(), RETURN, tag_status, UNREAD, and version.

Referenced by copy_docid_keyed(), copy_position(), copy_postlist(), copy_termlist(), copy_unchanged(), del(), do_until(), main(), FlintCompact::merge_docid_keyed(), FlintCompact::merge_spellings(), FlintCompact::merge_synonyms(), FlintCompact::MergeCursor::MergeCursor(), FlintSynonymTermList::next(), FlintSpellingWordsList::next(), FlintMetadataTermList::next(), FlintCompact::PostlistCursor::next(), FlintAllTermsList::next(), and FlintTable::really_empty().

FlintCursor& FlintCursor::operator= ( const FlintCursor  )  [private]

Assignment not allowed.

bool FlintCursor::prev (  ) 

Move to the previous key.

This is like FlintCursor::next, but BC is taken to the previous rather than next item.

Definition at line 113 of file flint_cursor.cc.

References Assert, B, C, current_key, FlintTable::cursor_version, find_entry(), get_key(), is_after_end, is_positioned, LOGCALL, LOGLINE, FlintTable::prev(), RETURN, tag_status, UNREAD, and version.

Referenced by do_until(), and main().

bool FlintCursor::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.

Parameters:
keep_compressed Don't uncompress the tag - e.g. useful if it's just being opaquely copied (default: false).
Returns:
true if current_tag holds compressed data (always false if keep_compressed was false).

Definition at line 292 of file flint_cursor.cc.

References Assert, B, C, COMPRESSED, current_tag, is_positioned, level, FlintTable::level, LOGCALL, LOGLINE, FlintTable::next(), FlintTable::read_tag(), RETURN, tag_status, UNCOMPRESSED, and UNREAD.

Referenced by copy_docid_keyed(), copy_position(), copy_postlist(), copy_termlist(), copy_unchanged(), do_until(), FlintSpellingWordsList::get_termfreq(), main(), FlintCompact::merge_docid_keyed(), FlintCompact::merge_spellings(), FlintCompact::merge_synonyms(), FlintCompact::PostlistCursor::next(), and FlintAllTermsList::read_termfreq_and_collfreq().

void FlintCursor::rebuild (  )  [private]

Rebuild the cursor.

Called when the table has changed.

Definition at line 73 of file flint_cursor.cc.

References B, BLK_UNUSED, FlintTable::block_size, FlintTable::C, C, FlintTable::cursor_version, level, FlintTable::level, Cursor_::n, Cursor_::p, and version.

Referenced by find_entry(), and find_entry_ge().

void FlintCursor::to_end (  )  [inline]


Member Data Documentation

The Btree table.

Definition at line 96 of file flint_cursor.h.

Referenced by del(), find_entry(), find_entry_ge(), FlintCursor(), get_key(), next(), prev(), read_tag(), and rebuild().

Cursor_* FlintCursor::C [private]

Pointer to an array of Cursors.

Definition at line 99 of file flint_cursor.h.

Referenced by find_entry(), find_entry_ge(), FlintCursor(), get_key(), next(), prev(), read_tag(), rebuild(), and ~FlintCursor().

bool FlintCursor::is_after_end [private]

Whether the cursor is off the end of the table.

Definition at line 90 of file flint_cursor.h.

Referenced by del(), find_entry(), find_entry_ge(), next(), and prev().

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 flint_cursor.h.

Referenced by del(), find_entry(), find_entry_ge(), get_key(), next(), prev(), and read_tag().

int FlintCursor::level [private]

The value of level in the Btree structure.

Definition at line 104 of file flint_cursor.h.

Referenced by FlintTable::empty(), FlintCursor(), get_key(), read_tag(), rebuild(), and ~FlintCursor().

enum { ... } FlintCursor::tag_status [private]

Status of the current_tag member.

Referenced by find_entry(), find_entry_ge(), next(), prev(), and read_tag().

unsigned long FlintCursor::version [private]

Definition at line 101 of file flint_cursor.h.

Referenced by find_entry(), find_entry_ge(), next(), prev(), and rebuild().


The documentation for this class was generated from the following files:

Documentation for Xapian (version 1.2.13).
Generated on 9 Jan 2013 by Doxygen 1.5.9.