xapian-core  1.4.25
Public Member Functions | Private Member Functions | Private Attributes | List of all members
GlassSpellingTable Class Reference

#include <glass_spelling.h>

+ Inheritance diagram for GlassSpellingTable:
+ Collaboration diagram for GlassSpellingTable:

Public Member Functions

 GlassSpellingTable (const std::string &dbdir, bool readonly)
 Create a new GlassSpellingTable object. More...
 
 GlassSpellingTable (int fd, off_t offset_, bool readonly)
 
void merge_changes ()
 Merge in batched-up changes. More...
 
void add_word (const std::string &word, Xapian::termcount freqinc)
 
void remove_word (const std::string &word, Xapian::termcount freqdec)
 
TermListopen_termlist (const std::string &word)
 
Xapian::doccount get_word_frequency (const std::string &word) const
 
void set_wordfreq_upper_bound (Xapian::termcount ub)
 
bool is_modified () const
 Override methods of GlassTable. More...
 
Xapian::termcount flush_db ()
 Returns updated wordfreq upper bound. More...
 
void cancel (const RootInfo &root_info, glass_revision_number_t rev)
 Override methods of GlassTable. More...
 
- Public Member Functions inherited from GlassLazyTable
 GlassLazyTable (const char *name_, const std::string &path, bool readonly)
 Create a new lazy table. More...
 
 GlassLazyTable (const char *name_, int fd, off_t offset_, bool readonly)
 
- Public Member Functions inherited from GlassTable
 GlassTable (const char *tablename_, const std::string &path_, bool readonly_, bool lazy=false)
 Create a new Btree object. More...
 
 GlassTable (const char *tablename_, int fd, off_t offset_, bool readonly_, bool lazy=false)
 
 ~GlassTable ()
 Close the Btree. More...
 
void close (bool permanent=false)
 Close the Btree. More...
 
bool readahead_key (const string &key) const
 
bool exists () const
 Determine whether the btree exists on disk. More...
 
void open (int flags_, const RootInfo &root_info, glass_revision_number_t rev)
 Open the btree. More...
 
bool is_open () const
 Return true if this table is open. More...
 
bool is_writable () const
 Return true if this table is writable. More...
 
void flush_db ()
 Flush any outstanding changes to the DB file of the table. More...
 
void commit (glass_revision_number_t revision, RootInfo *root_info)
 Commit any outstanding changes to the table. More...
 
bool sync ()
 
void cancel (const RootInfo &root_info, glass_revision_number_t rev)
 Cancel any outstanding changes. More...
 
bool get_exact_entry (const std::string &key, std::string &tag) const
 Read an entry from the table, if and only if it is exactly that being asked for. More...
 
bool key_exists (const std::string &key) const
 Check if a key exists in the Btree. More...
 
bool read_tag (Glass::Cursor *C_, std::string *tag, bool keep_compressed) const
 Read the tag value for the key pointed to by cursor C_. More...
 
void add (const std::string &key, const std::string &tag, bool already_compressed=false)
 Add a key/tag pair to the table, replacing any existing pair with the same key. More...
 
bool del (const std::string &key)
 Delete an entry from the table. More...
 
int get_flags () const
 
void create_and_open (int flags_, const RootInfo &root_info)
 Create a new empty btree structure on disk and open it at the initial revision. More...
 
void set_full_compaction (bool parity)
 
glass_revision_number_t get_open_revision_number () const
 Get the revision number at which this table is currently open. More...
 
glass_tablesize_t get_entry_count () const
 Return a count of the number of entries in the table. More...
 
bool empty () const
 Return true if there are no entries in the table. More...
 
GlassCursorcursor_get () const
 Get a cursor for reading from the table. More...
 
bool is_modified () const
 Determine whether the object contains uncommitted modifications. More...
 
void set_max_item_size (size_t block_capacity)
 Set the maximum item size given the block capacity. More...
 
void set_changes (GlassChanges *changes)
 Set the GlassChanges object to write changed blocks to. More...
 
string get_path () const
 

Private Member Functions

void toggle_word (const std::string &word)
 
void toggle_fragment (Glass::fragment frag, const std::string &word)
 

Private Attributes

std::map< std::string, Xapian::termcountwordfreq_changes
 
std::map< Glass::fragment, std::set< std::string > > termlist_deltas
 Changes to make to the termlists. More...
 
Xapian::termcount wordfreq_upper_bound = 0
 Used to track an upper bound on wordfreq. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from GlassTable
static void throw_database_closed ()
 Throw an exception indicating that the database is closed. More...
 
- Protected Member Functions inherited from GlassTable
bool find (Glass::Cursor *) const
 find(C_) searches for the key of B->kt in the B-tree. More...
 
int delete_kt ()
 
void read_block (uint4 n, uint8_t *p) const
 read_block(n, p) reads block n of the DB file to address p. More...
 
void write_block (uint4 n, const uint8_t *p, bool appending=false) const
 write_block(n, p, appending) writes block n in the DB file from address p. More...
 
void set_overwritten () const
 
void block_to_cursor (Glass::Cursor *C_, int j, uint4 n) const
 
void alter ()
 Btree::alter(); is called when the B-tree is to be altered. More...
 
void compact (uint8_t *p)
 compact(p) compact the block at p by shuffling all the items up to the end. More...
 
void enter_key_above_leaf (Glass::LeafItem previtem, Glass::LeafItem newitem)
 enter_key_above_leaf(previtem, newitem) is called after a leaf block split. More...
 
void enter_key_above_branch (int j, Glass::BItem newitem)
 enter_key_above_branch(j, newkey) is called after a branch block split. More...
 
int mid_point (uint8_t *p) const
 mid_point(p) finds the directory entry in c that determines the approximate mid point of the data in the block at p. More...
 
void add_item_to_leaf (uint8_t *p, Glass::LeafItem kt, int c)
 add_item_to_leaf(p, kt_, c) adds item kt_ to the leaf block at p. More...
 
void add_item_to_branch (uint8_t *p, Glass::BItem kt, int c)
 add_item_to_branch(p, kt_, c) adds item kt_ to the branch block at p. More...
 
void add_leaf_item (Glass::LeafItem kt)
 GlassTable::add_leaf_item(kt_) adds item kt_ to the leaf block. More...
 
void add_branch_item (Glass::BItem kt, int j)
 GlassTable::add_item(kt_, j) adds item kt_ to the block at cursor level C[j]. More...
 
void delete_leaf_item (bool repeatedly)
 GlassTable::delete_leaf_item(repeatedly) is (almost) the converse of add_leaf_item. More...
 
void delete_branch_item (int j)
 GlassTable::delete_branch_item(j, repeatedly) is (almost) the converse of add_branch_item. More...
 
int add_kt (bool found)
 add_kt(found) adds the item (key-tag pair) at B->kt into the B-tree, using cursor C. More...
 
void read_root ()
 
void split_root (uint4 split_n)
 Btree needs to gain a new level to insert more items: so split root block and construct a new one. More...
 
void form_key (const std::string &key) const
 
bool single_file () const
 
bool prev (Glass::Cursor *C_, int j) const
 
bool next (Glass::Cursor *C_, int j) const
 
bool prev_default (Glass::Cursor *C_, int j) const
 
bool next_default (Glass::Cursor *C_, int j) const
 
bool prev_for_sequential (Glass::Cursor *C_, int dummy) const
 
bool next_for_sequential (Glass::Cursor *C_, int dummy) const
 
- Static Protected Member Functions inherited from GlassTable
static int find_in_leaf (const uint8_t *p, Glass::LeafItem item, int c, bool &exact)
 find_in_leaf(p, key, c, exact) searches for the key in the leaf block at p. More...
 
static int find_in_branch (const uint8_t *p, Glass::LeafItem item, int c)
 
static int find_in_branch (const uint8_t *p, Glass::BItem item, int c)
 
static uint4 block_given_by (const uint8_t *p, int c)
 block_given_by(p, c) finds the item at block address p, directory offset c, and returns its tag value as an integer. More...
 
- Protected Attributes inherited from GlassTable
const char * tablename
 The name of the table (used when writing changesets). More...
 
glass_revision_number_t revision_number
 revision number of the opened B-tree. More...
 
glass_tablesize_t item_count
 keeps a count of the number of items in the B-tree. More...
 
unsigned int block_size
 block size of the B tree in bytes More...
 
int flags
 Flags like DB_NO_SYNC and DB_DANGEROUS. More...
 
bool faked_root_block
 true if the root block is faked (not written to disk). More...
 
bool sequential
 true iff the data has been written in a single write in sequential order. More...
 
int handle
 File descriptor of the table. More...
 
int level
 number of levels, counting from 0 More...
 
uint4 root
 the root block of the B-tree More...
 
Glass::LeafItem_wr kt
 buffer of size block_size for making up key-tag items More...
 
uint8_t * buffer
 buffer of size block_size for reforming blocks More...
 
GlassFreeList free_list
 List of free blocks. More...
 
std::string name
 The path name of the B tree. More...
 
int seq_count
 count of the number of successive instances of purely sequential addition, starting at SEQ_START_POINT (neg) and going up to zero. More...
 
uint4 changed_n
 the last block to be changed by an addition More...
 
int changed_c
 directory offset corresponding to last block to be changed by an addition More...
 
size_t max_item_size
 maximum size of an item (key-tag pair) More...
 
bool Btree_modified
 Set to true the first time the B-tree is modified. More...
 
bool full_compaction
 set to true when full compaction is to be achieved More...
 
bool writable
 Set to true when the database is opened to write. More...
 
bool cursor_created_since_last_modification
 Flag for tracking when cursors need to rebuild. More...
 
unsigned long cursor_version
 Version count for tracking when cursors need to rebuild. More...
 
GlassChangeschanges_obj
 The GlassChanges object to write block changes to. More...
 
Glass::Cursor C [GLASS_BTREE_CURSOR_LEVELS]
 
uint8_t * split_p
 Buffer used when splitting a block. More...
 
uint4 compress_min
 Minimum size tag to try compressing (0 for no compression). More...
 
CompressionStream comp_stream
 
bool lazy
 If true, don't create the table until it's needed. More...
 
uint4 last_readahead
 Last block readahead_key() preread. More...
 
off_t offset
 offset to start of table in file. More...
 

Detailed Description

Definition at line 63 of file glass_spelling.h.

Constructor & Destructor Documentation

◆ GlassSpellingTable() [1/2]

GlassSpellingTable::GlassSpellingTable ( const std::string &  dbdir,
bool  readonly 
)
inline

Create a new GlassSpellingTable object.

This method does not create or open the table on disk - you must call the create() or open() methods respectively!

Parameters
dbdirThe directory the glass database is stored in.
readonlytrue if we're opening read-only, else false.

Definition at line 91 of file glass_spelling.h.

◆ GlassSpellingTable() [2/2]

GlassSpellingTable::GlassSpellingTable ( int  fd,
off_t  offset_,
bool  readonly 
)
inline

Definition at line 94 of file glass_spelling.h.

Member Function Documentation

◆ add_word()

void GlassSpellingTable::add_word ( const std::string &  word,
Xapian::termcount  freqinc 
)

Definition at line 129 of file glass_spelling.cc.

References unpack_uint_last().

Referenced by GlassWritableDatabase::add_spelling().

◆ cancel()

void GlassSpellingTable::cancel ( const RootInfo root_info,
glass_revision_number_t  rev 
)
inline

Override methods of GlassTable.

NB: these aren't virtual, but we always call them on the subclass in cases where it matters.

Definition at line 132 of file glass_spelling.h.

References GlassTable::cancel().

Referenced by GlassDatabase::cancel().

◆ flush_db()

Xapian::termcount GlassSpellingTable::flush_db ( )
inline

Returns updated wordfreq upper bound.

Definition at line 126 of file glass_spelling.h.

References GlassTable::flush_db().

Referenced by GlassDatabase::set_revision_number().

◆ get_word_frequency()

Xapian::doccount GlassSpellingTable::get_word_frequency ( const std::string &  word) const

Definition at line 374 of file glass_spelling.cc.

References unpack_uint_last().

Referenced by GlassDatabase::get_spelling_frequency().

◆ is_modified()

bool GlassSpellingTable::is_modified ( ) const
inline

Override methods of GlassTable.

NB: these aren't virtual, but we always call them on the subclass in cases where it matters.

Definition at line 121 of file glass_spelling.h.

References GlassTable::is_modified().

Referenced by GlassDatabase::apply(), and GlassWritableDatabase::has_uncommitted_changes().

◆ merge_changes()

void GlassSpellingTable::merge_changes ( )

Merge in batched-up changes.

Returns
Updated upperbound on the word frequency.

Definition at line 45 of file glass_spelling.cc.

References PrefixCompressedStringWriter::append(), Assert, PrefixCompressedStringItor::at_end(), and pack_uint_last().

Referenced by GlassWritableDatabase::open_spelling_wordlist().

◆ open_termlist()

TermList * GlassSpellingTable::open_termlist ( const std::string &  word)

Definition at line 258 of file glass_spelling.cc.

References Assert, AssertRel, and Glass::fragment::data.

Referenced by GlassDatabase::open_spelling_termlist().

◆ remove_word()

void GlassSpellingTable::remove_word ( const std::string &  word,
Xapian::termcount  freqdec 
)

Definition at line 164 of file glass_spelling.cc.

References unpack_uint_last().

Referenced by GlassWritableDatabase::remove_spelling().

◆ set_wordfreq_upper_bound()

void GlassSpellingTable::set_wordfreq_upper_bound ( Xapian::termcount  ub)
inline

Definition at line 110 of file glass_spelling.h.

Referenced by GlassDatabase::cancel(), and GlassDatabase::open_tables().

◆ toggle_fragment()

void GlassSpellingTable::toggle_fragment ( Glass::fragment  frag,
const std::string &  word 
)
private

Definition at line 113 of file glass_spelling.cc.

◆ toggle_word()

void GlassSpellingTable::toggle_word ( const std::string &  word)
private

Definition at line 208 of file glass_spelling.cc.

References Glass::fragment::data.

Member Data Documentation

◆ termlist_deltas

std::map<Glass::fragment, std::set<std::string> > GlassSpellingTable::termlist_deltas
private

Changes to make to the termlists.

This list is essentially xor-ed with the list on disk, so an entry here either means a new entry needs to be added on disk, or an existing entry on disk needs to be removed. We do it this way so we don't need to store an additional add/remove flag for every word.

Definition at line 77 of file glass_spelling.h.

◆ wordfreq_changes

std::map<std::string, Xapian::termcount> GlassSpellingTable::wordfreq_changes
private

Definition at line 67 of file glass_spelling.h.

◆ wordfreq_upper_bound

Xapian::termcount GlassSpellingTable::wordfreq_upper_bound = 0
private

Used to track an upper bound on wordfreq.

Definition at line 80 of file glass_spelling.h.


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