NCBI C++ ToolKit
Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
CBDB_RangeMap< TBV > Class Template Reference

Search Toolkit Book for CBDB_RangeMap

Range map class, stores unsigned integer range mappings like 10 to 15 maps into 100 to 115. More...

#include <db/bdb/bdb_range_map.hpp>

+ Inheritance diagram for CBDB_RangeMap< TBV >:
+ Collaboration diagram for CBDB_RangeMap< TBV >:

Public Types

typedef TBV TBitVector
 
- Public Types inherited from CBDB_File
enum  EAfterWrite { eKeepData , eDiscardData }
 
typedef int TUnifiedFieldIndex
 CBDB_File keeps data in two buffers (key buffer and data buffer). More...
 
- Public Types inherited from CBDB_RawFile
enum  EOpenMode { eReadWrite , eReadOnly , eCreate , eReadWriteCreate }
 BDB file open mode. More...
 
enum  EDBType { eBtree , eQueue , eHash }
 Berkeley DB database type. More...
 
enum  EReallocMode { eReallocAllowed , eReallocForbidden }
 BLOB read mode, controld data buffer reallocation when there is not enough space in buffer. More...
 
enum  EDuplicateKeys { eDuplicatesDisable , eDuplicatesEnable }
 Control key duplicates in Btree. More...
 
enum  EIgnoreError { eIgnoreError , eThrowOnError }
 
enum  ECompact { eCompactNoFree , eCompactFreeExisting , eCompactFreeAll }
 BerkeleyDB compaction methods and flags. More...
 
enum  ECachePriority {
  eCache_Lowest , eCache_Low , eCache_Default , eCache_High ,
  eCache_Highest
}
 Set the priority for this database's pages in the buffer cache This is generally a temporary advisement, and works only if an environment is used. More...
 
typedef CSimpleBuffer TBuffer
 typedef for raw buffer operations More...
 
typedef bool(* FContinueCompact) (void)
 Extended version of compact This version performs iterative compacting and uses a callback to request an exit. More...
 

Public Member Functions

 CBDB_RangeMap ()
 
 ~CBDB_RangeMap ()
 
void LoadFreeList ()
 Load free list (Storage should be open first) More...
 
EBDB_ErrCode Save ()
 Save free list. More...
 
EBDB_ErrCode AddRange (unsigned from, unsigned to, unsigned dest, bool add_to_free_list)
 Add remapping range. More...
 
const TBitVectorGetFreeList () const
 Get list of free ids. More...
 
TBitVectorGetFreeList ()
 
unsigned Remap (unsigned id, bool ignore_free_list=false)
 Remap one single id. More...
 
void Remap (const TBitVector &bv_src, TBitVector *bv_dst, TBitVector *bv_remapped=0, bool ignore_free_list=false)
 Remap a bitvector into another bitvector. More...
 
- Public Member Functions inherited from CBDB_BLobFile
 CBDB_BLobFile (EDuplicateKeys dup_keys=eDuplicatesDisable, EDBType db_type=eBtree)
 
EBDB_ErrCode Insert (const void *data, size_t size)
 Insert BLOB into the database. More...
 
EBDB_ErrCode Insert (const TBuffer &buf)
 Insert BLOB. More...
 
unsigned Append (const void *data, size_t size)
 
EBDB_ErrCode UpdateInsert (const void *data, size_t size)
 Insert or update BLOB. More...
 
EBDB_ErrCode UpdateInsert (const TBuffer &buf)
 Insert or update BLOB. More...
 
EBDB_ErrCode Fetch ()
 Fetch the record corresponding to the current key value. More...
 
EBDB_ErrCode Fetch (void **buf, size_t buf_size, EReallocMode allow_realloc)
 Retrieve BLOB data. More...
 
size_t LobSize () const
 Get LOB size. Becomes available right after successfull Fetch. More...
 
size_t BlobSize () const
 Get LOB size. Becomes available right after successfull Fetch. More...
 
EBDB_ErrCode ReadRealloc (TBuffer &buffer)
 Read BLOB into vector. More...
 
EBDB_ErrCode GetData (void *buf, size_t size)
 Copy LOB data into the 'buf'. More...
 
CBDB_BLobStreamCreateStream ()
 Creates stream like object to retrieve or write BLOB by chunks. More...
 
CBDB_BlobReaderWriterCreateReaderWriter ()
 Creates stream like object to retrieve or write BLOB by chunks. More...
 
IReaderCreateReader ()
 Creates stream like object to read BLOB by chunks. More...
 
- Public Member Functions inherited from CBDB_File
 CBDB_File (EDuplicateKeys dup_keys=eDuplicatesDisable, EDBType db_type=eBtree)
 
void Open (const string &filename, EOpenMode open_mode, bool support_dirty_read=false, unsigned rec_len=0)
 Open file with specified access mode. More...
 
void Open (const string &filename, const string &database, EOpenMode open_mode, bool support_dirty_read=false, unsigned rec_len=0)
 Open file with specified filename and database name. More...
 
void Reopen (EOpenMode open_mode, bool support_dirty_read=false)
 Reopen the db file. More...
 
void Attach (CBDB_File &db_file)
 Attach external Berkeley DB file. More...
 
EBDB_ErrCode Fetch ()
 Fetches the record corresponding to the current key value. More...
 
EBDB_ErrCode FetchForUpdate ()
 Fetche the record corresponding to the current key value. More...
 
EBDB_ErrCode Insert (EAfterWrite write_flag=eDiscardData)
 Insert new record. More...
 
unsigned Append (EAfterWrite write_flag=eDiscardData)
 Append record to the queue (works only for DB_QUEUE database type) More...
 
EBDB_ErrCode Delete (EIgnoreError on_error=eThrowOnError)
 Delete record corresponding to the current key value. More...
 
EBDB_ErrCode UpdateInsert (EAfterWrite write_flag=eDiscardData)
 Update record corresponding to the current key value. More...
 
void BindKey (const char *field_name, CBDB_Field *key_field, size_t buf_size=0)
 
void BindData (const char *field_name, CBDB_Field *data_field, size_t buf_size=0, ENullable is_null=eNullable)
 
void DuplicateStructure (const CBDB_File &dbf)
 Create the same fieldset as in dbf and bind them to the current file. More...
 
const CBDB_BufferManagerGetKeyBuffer () const
 Get Buffer manager for key section of the file. More...
 
const CBDB_BufferManagerGetDataBuffer () const
 Get Buffer manager for data section of the file. More...
 
CBDB_BufferManagerGetKeyBuffer ()
 Get Buffer manager for key section of the file. More...
 
CBDB_BufferManagerGetDataBuffer ()
 Get Buffer manager for data section of the file. More...
 
void SetFieldCompareLimit (unsigned int n_fields)
 Sets maximum number of key fields participating in comparison Should be less than total number of key fields. More...
 
DBTCloneDBT_Key ()
 Create new copy of m_DBT_Key. More...
 
void SetLegacyStringsCheck (bool value)
 Set C-str detection. More...
 
TUnifiedFieldIndex GetFieldIdx (const string &name) const
 Get field index by name. More...
 
const CBDB_FieldGetField (TUnifiedFieldIndex idx) const
 Return field by field index. More...
 
CBDB_FieldGetField (TUnifiedFieldIndex idx)
 
void SetFieldOwnership (bool own_fields)
 Fields deletion is managed by the class when own_fields is TRUE. More...
 
bool IsOwnFields () const
 Return fields ownership flag. More...
 
void CopyFrom (const CBDB_File &dbf)
 Copy record (fields) from another BDB file (MUST have the same structure) More...
 
void Verify (const char *filename, const char *database, FILE *backup)
 Run database verification (DB->verify) More...
 
void EnablePrefixCompression ()
 Turn ON prefix compression. More...
 
- Public Member Functions inherited from CBDB_RawFile
 CBDB_RawFile (EDuplicateKeys dup_keys=eDuplicatesDisable, EDBType db_type=eBtree)
 
virtual ~CBDB_RawFile ()
 
void SetEnv (CBDB_Env &env)
 Associate file with environment. More...
 
CBDB_EnvGetEnv ()
 Get pointer on file environment Return NULL if no environment has been set. More...
 
void Open (const string &filename, EOpenMode open_mode, bool support_dirty_read=false, unsigned rec_len=0)
 Open file with specified access mode. More...
 
void Open (const string &filename, const string &database, EOpenMode open_mode, bool support_dirty_read=false, unsigned rec_len=0)
 Open file with specified filename and database name. More...
 
void Attach (CBDB_RawFile &bdb_file)
 Attach class to external BerkeleyDB file instance. More...
 
void Close ()
 Close file. More...
 
void Reopen (EOpenMode open_mode, bool support_dirty_read=false, unsigned rec_len=0)
 Reopen database file. (Should be already open). More...
 
void Remove (const string &filename, const string &database=kEmptyStr)
 Remove the database specified by the filename and database arguments. More...
 
unsigned int Truncate ()
 Empty the database. Return number of records removed. More...
 
unsigned int SafeTruncate ()
 Workaround for truncate of large databases. More...
 
void Rename (const string &fname, const string &old_name, const string &new_name)
 Rename a database. NOTE: This cannot be called on an opened file. More...
 
void Compact (ECompact compact_type=eCompactNoFree, int target_fill_pct=0)
 Compact the database. More...
 
void CompactEx (FContinueCompact compact_callback, ECompact compact_type=eCompactNoFree, int target_fill_pct=0)
 
void SetPageSize (unsigned int page_size)
 
unsigned int GetPageSize ()
 
void SetCacheSize (unsigned int cache_size)
 Set Berkeley DB memory cache size for the file (default is 256K). More...
 
void RevSplitOff ()
 Turn OFF reverse splitting. More...
 
void DisableCmpOverride ()
 Disable BTREE comparison override. More...
 
void SetCachePriority (ECachePriority priority)
 
const stringFileName () const
 
const stringDatabase () const
 
virtual void SetHash (DB *)
 Set hash function. More...
 
bool IsOpen () const
 Return TRUE if the file is open. More...
 
bool IsAttached () const
 
bool IsByteSwapped () const
 Return TRUE if the if the underlying database files were created on an architecture of the different byte order. More...
 
bool DuplicatesAllowed () const
 Return TRUE if file can contain duplicate keys. More...
 
EDuplicateKeys GetDupKeysMode () const
 Return the key duplicate mode value. More...
 
const stringGetFileName () const
 Return file name. More...
 
EOpenMode GetOpenMode () const
 Return the file open mode. More...
 
void Sync ()
 Flush any cached information to disk. More...
 
unsigned CountRecs (bool bFast=false)
 Compute database statistic, return number of records. More...
 
void PrintStat (CNcbiOstream &out)
 Print database statistics. More...
 
virtual void SetTransaction (ITransaction *trans)
 Establish transaction association. More...
 
virtual void RemoveTransaction (ITransaction *trans)
 Remove transaction association (must be established by SetTransaction. More...
 
virtual ITransactionGetTransaction ()
 Get current transaction. More...
 
CBDB_TransactionGetBDBTransaction ()
 Get current transaction. More...
 
unsigned GetRecLen () const
 Get record length Works for fixed length record DBs only (Queue) More...
 
void SetHashFillFactor (unsigned h_ffactor)
 Set hash table density (fill factor) More...
 
void SetHashNelem (unsigned h_nelem)
 Set an estimate of hash table final size. More...
 
void DisableHashOverride ()
 Disable hash method override (Berkeley DB will use it's own default hashing method) More...
 
void SetBtreeMinKeysPerPage (unsigned int keys_per_page)
 Set the minimum number of keys per page (BTREE access methods only) More...
 
unsigned int GetBtreeMinKeysPerPage ()
 
void SetCompressor (ICompression *compressor, EOwnership own=eTakeOwnership)
 Set record compressor. More...
 
- Public Member Functions inherited from ITransactional
virtual ~ITransactional ()
 

Public Attributes

CBDB_FieldUint4 FromId
 From id. More...
 
CBDB_FieldUint4 ToId
 To id. More...
 

Protected Attributes

TBitVectorm_FreeList
 
- Protected Attributes inherited from CBDB_RawFile
EDBType m_DB_Type
 
DBm_DB
 
DBTm_DBT_Key
 
DBTm_DBT_Data
 
CBDB_Envm_Env
 
CBDB_Transactionm_Trans
 
int m_TransAssociation
 
unsigned m_RecLen
 
unsigned m_H_ffactor
 
unsigned m_H_nelem
 
unsigned m_BT_minkey
 
AutoPtr< ICompressionm_Compressor
 Record compressor. More...
 
TBuffer m_CompressBuffer
 

Additional Inherited Members

- Static Public Member Functions inherited from CBDB_File
static void DestroyDBT_Clone (DBT *dbt)
 Free the DBT structure created by CloneDBT_Key. More...
 
- Static Public Attributes inherited from CBDB_RawFile
static const char kDefaultDatabase [] = "_table"
 
- Protected Member Functions inherited from CBDB_File
void Discard ()
 Unpack internal record buffers. More...
 
virtual void SetCmp (DB *)
 Set comparison function. More...
 
EBDB_ErrCode ReadCursor (DBC *dbc, unsigned int bdb_flag)
 Read DB cursor. More...
 
EBDB_ErrCode ReadCursor (DBC *dbc, unsigned int bdb_flag, void **buf, size_t buf_size, EReallocMode allow_realloc)
 Read DB cursor (BLOB) More...
 
EBDB_ErrCode ReadCursor (DBC *dbc, unsigned int bdb_flag, TBuffer *buf)
 Read DB cursor (BLOB) More...
 
EBDB_ErrCode ReadCursor (DBC *dbc, unsigned int bdb_flag, CBDB_MultiRowBuffer *multirow_buf, bool multirow_only)
 Multiple-row read into a buffer Buffer is to be traversed using DB_MULTIPLE_KEY_NEXT (BerkeleyDB) More...
 
EBDB_ErrCode WriteCursor (DBC *dbc, unsigned int bdb_flag, EAfterWrite write_flag)
 Write DB cursor. More...
 
EBDB_ErrCode WriteCursor (const void *data, size_t size, DBC *dbc, unsigned int bdb_flag, EAfterWrite write_flag)
 Write BLOB to DB cursor. More...
 
EBDB_ErrCode DeleteCursor (DBC *dbc, EIgnoreError)
 Delete DB cursor. More...
 
void CheckNullDataConstraint () const
 Check if all NOT NULL fields are assigned. More...
 
void DisableDataBufProcessing ()
 Function disables processing of m_DBT_data. More...
 
void DisableNull ()
 Disable NULL/not NULL in data fields (Performance tweak, call before BindData) More...
 
void DisableDataPacking ()
 Disable packing of variable length fields in the data buffer (Call after BindData) More...
 
EBDB_ErrCode x_Fetch (unsigned int flags)
 Wrapper around get operation. More...
 
virtual void x_SetByteSwapped (bool bswp)
 Set byte order swapping. More...
 
- Protected Member Functions inherited from CBDB_RawFile
void x_Open (const char *filename, const char *database, EOpenMode open_mode, bool support_dirty_read, unsigned rec_len)
 
void x_Create (const char *filename, const char *database)
 
void x_Close (EIgnoreError close_mode)
 
void x_CreateDB (unsigned rec_len)
 Create m_DB member, set page, cache parameters. More...
 
void x_SetTransaction (CBDB_Transaction *trans)
 Set current transaction. More...
 
void x_RemoveTransaction (CBDB_Transaction *trans)
 
DB_TXNGetTxn ()
 Get transaction handler. More...
 
DBCCreateCursor (CBDB_Transaction *trans=0, unsigned int flags=0) const
 Create DB cursor. More...
 
int x_DB_Fetch (DBT *key, DBT *data, unsigned flags)
 Internal override for DB->get(...) This method overrides destination buffer and uses compressor: Should only be used with DB_DBT_USERMEM flag. More...
 
int x_DBC_Fetch (DBC *dbc, DBT *key, DBT *data, unsigned flags)
 Internal override for DBC->c_get(...) This method overrides destination buffer and uses compressor: Should only be used with DB_DBT_USERMEM flag. More...
 
int x_DB_Put (DBT *key, DBT *data, unsigned flags)
 Override for DB->put(...) Handles compression. More...
 
int x_DB_CPut (DBC *dbc, DBT *key, DBT *data, unsigned flags)
 Override for DBC->c_put(...) Handles compression. More...
 
int x_FetchBufferDecompress (DBT *data, void *usr_data)
 

Detailed Description

template<class TBV>
class CBDB_RangeMap< TBV >

Range map class, stores unsigned integer range mappings like 10 to 15 maps into 100 to 115.

This class also maitains free list of mappings (inside the mapping regions) The free list can be used externally to do id assignments, so ids fall into some predefined regions of the mapped list

Range 0-0 is RESERVED for the free list storage.

Example:
   10-15 --> 100-115
   20-30 --> 1020-1030
   Free list: { 11,12,23 }

Typical use case: add a range of ids and take them out excluding out of free list. When the free list is empty - add a new range.

Definition at line 73 of file bdb_range_map.hpp.

Member Typedef Documentation

◆ TBitVector

template<class TBV >
typedef TBV CBDB_RangeMap< TBV >::TBitVector

Definition at line 76 of file bdb_range_map.hpp.

Constructor & Destructor Documentation

◆ CBDB_RangeMap()

template<class TBV >
CBDB_RangeMap< TBV >::CBDB_RangeMap

◆ ~CBDB_RangeMap()

template<class TBV >
CBDB_RangeMap< TBV >::~CBDB_RangeMap

Definition at line 138 of file bdb_range_map.hpp.

References ERR_POST_XX, CException::GetMsg(), and CException::what().

Member Function Documentation

◆ AddRange()

template<class TBV >
EBDB_ErrCode CBDB_RangeMap< TBV >::AddRange ( unsigned  from,
unsigned  to,
unsigned  dest,
bool  add_to_free_list 
)

Add remapping range.

The range should NOT intersect with any existing range Optionally new range can be added to the free id list.

Definition at line 183 of file bdb_range_map.hpp.

References BDB_THROW, eBDB_Ok, CBDB_FileCursor::eGE, CBDB_FileCursor::eLE, CBDB_FileCursor::FetchFirst(), CBDB_FileCursor::From, and CBDB_FileCursor::SetCondition().

◆ GetFreeList() [1/2]

template<class TBV >
TBitVector& CBDB_RangeMap< TBV >::GetFreeList ( )
inline

Definition at line 98 of file bdb_range_map.hpp.

References CBDB_RangeMap< TBV >::m_FreeList.

◆ GetFreeList() [2/2]

template<class TBV >
const TBitVector& CBDB_RangeMap< TBV >::GetFreeList ( ) const
inline

Get list of free ids.

Definition at line 97 of file bdb_range_map.hpp.

References CBDB_RangeMap< TBV >::m_FreeList.

◆ LoadFreeList()

template<class TBV >
void CBDB_RangeMap< TBV >::LoadFreeList

Load free list (Storage should be open first)

Definition at line 156 of file bdb_range_map.hpp.

References _ASSERT, buf, bm::deserialize(), eBDB_Ok, and CBDB_BLobFile::ReadRealloc().

◆ Remap() [1/2]

template<class TBV >
void CBDB_RangeMap< TBV >::Remap ( const TBitVector bv_src,
TBitVector bv_dst,
TBitVector bv_remapped = 0,
bool  ignore_free_list = false 
)

Remap a bitvector into another bitvector.

Parameters
bv_srcSource bit vector
bv_dstDestination set
bv_remappedSet of successfully remapped ids

Definition at line 272 of file bdb_range_map.hpp.

References eBDB_Ok, CBDB_FileCursor::eLE, CBDB_FileCursor::FetchFirst(), CBDB_FileCursor::From, and CBDB_FileCursor::SetCondition().

◆ Remap() [2/2]

template<class TBV >
unsigned CBDB_RangeMap< TBV >::Remap ( unsigned  id,
bool  ignore_free_list = false 
)

Remap one single id.

Returns
Remapped id or 0 if remapping is impossible

Definition at line 245 of file bdb_range_map.hpp.

References eBDB_Ok, CBDB_FileCursor::eLE, CBDB_FileCursor::FetchFirst(), CBDB_FileCursor::From, and CBDB_FileCursor::SetCondition().

◆ Save()

template<class TBV >
EBDB_ErrCode CBDB_RangeMap< TBV >::Save

Save free list.

Definition at line 172 of file bdb_range_map.hpp.

References _ASSERT, buf, and BV_Serialize().

Member Data Documentation

◆ FromId

template<class TBV >
CBDB_FieldUint4 CBDB_RangeMap< TBV >::FromId

From id.

Definition at line 79 of file bdb_range_map.hpp.

Referenced by CBDB_RangeMap< TBV >::CBDB_RangeMap().

◆ m_FreeList

template<class TBV >
TBitVector* CBDB_RangeMap< TBV >::m_FreeList
protected

Definition at line 120 of file bdb_range_map.hpp.

Referenced by CBDB_RangeMap< TBV >::GetFreeList().

◆ ToId

template<class TBV >
CBDB_FieldUint4 CBDB_RangeMap< TBV >::ToId

To id.

Definition at line 80 of file bdb_range_map.hpp.

Referenced by CBDB_RangeMap< TBV >::CBDB_RangeMap().


The documentation for this class was generated from the following file:
Modified on Wed Apr 17 13:09:25 2024 by modify_doxy.py rev. 669887