stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential Class Reference

WriterSequential is used to construct a constant B-tree database from an _ordered_ input sequence. More...

#include <stx-cbtreedb.h>

Collaboration diagram for stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 WriterSequential (const key_compare &key_less=key_compare())
 Constructor.
void Add (const key_type &key, uint32_t size)
 Add a new key -> value size mapping to the database.
size_t Size () const
 Return number of pairs inserted into mapping.
void SetSignature (const char *newsignature)
 Change the database signature from 'cbtreedb' to a custom string.
void WriteHeader (std::ostream &os)
 Write header and b-tree to file stream. Starts Phase 2.
void WriteValue (const key_type &key, const void *data, uint32_t size)
 Sequentially write value blobs to file.
void WriteValue (const key_type &key, const std::string &data)
 Sequentially write value blobs to file.
void WriteFinalize ()
 Finalize database file.

Protected Attributes

key_compare m_key_less
 key comparison functional
BTreeBuilder m_btree
 phase 1: b-tree object built from sequential predeclared sequence
uint64_t m_dataoffset
 phase 1: value data offset counter for predeclared sequence
char m_signaturestr [8]
 signature characters to begin file with
SignaturePage m_signature
 signature page of current written file
std::ostream * m_ostream
 phase 2: output stream
uint32_t m_currpos
 phase 2: current position in array
uint64_t m_curroffset
 phase 2: current offset in output stream
SHA256 m_datasha
 phase 2: running digest of the value area

Detailed Description

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
class stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential

WriterSequential is used to construct a constant B-tree database from an _ordered_ input sequence.

The writer class is fed in two phases. In phase one the ordered sequence of keys together with their value data size (without contents) is delivered to the class via the Add() function. Phase two is started by calling WriteHeader() followed by a sequence to WriteValue() calls for each of the predeclared key-value pairs. The value data is written directly to the file and not buffered. The write loop is terminated by WriteFinalize(), which finalizes the database file.

Definition at line 2775 of file stx-cbtreedb.h.


Constructor & Destructor Documentation

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::WriterSequential ( const key_compare key_less = key_compare()  )  [inline]

Constructor.

Definition at line 2807 of file stx-cbtreedb.h.


Member Function Documentation

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::Add ( const key_type key,
uint32_t  size 
) [inline]

Add a new key -> value size mapping to the database.

The keys must be added in ascending order.

Definition at line 2819 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::SetSignature ( const char *  newsignature  )  [inline]

Change the database signature from 'cbtreedb' to a custom string.

The signature is always 8 bytes long. Longer strings are truncated, shorter ones padded with nulls.

Definition at line 2841 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
size_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::Size (  )  const [inline]

Return number of pairs inserted into mapping.

Definition at line 2831 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::WriteFinalize (  )  [inline]

Finalize database file.

Definition at line 2935 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::WriteHeader ( std::ostream &  os  )  [inline]

Write header and b-tree to file stream. Starts Phase 2.

Definition at line 2852 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::WriteValue ( const key_type key,
const std::string &  data 
) [inline]

Sequentially write value blobs to file.

The key-value sequence must match the pre-declared sequence.

Definition at line 2929 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::WriteValue ( const key_type key,
const void *  data,
uint32_t  size 
) [inline]

Sequentially write value blobs to file.

The key-value sequence must match the pre-declared sequence.

Definition at line 2896 of file stx-cbtreedb.h.


Member Data Documentation

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
BTreeBuilder stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_btree [protected]

phase 1: b-tree object built from sequential predeclared sequence

Definition at line 2782 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
uint64_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_curroffset [protected]

phase 2: current offset in output stream

Definition at line 2800 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
uint32_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_currpos [protected]

phase 2: current position in array

Definition at line 2797 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
uint64_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_dataoffset [protected]

phase 1: value data offset counter for predeclared sequence

Definition at line 2785 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
SHA256 stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_datasha [protected]

phase 2: running digest of the value area

Definition at line 2803 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
key_compare stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_key_less [protected]

key comparison functional

Definition at line 2779 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
std::ostream* stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_ostream [protected]

phase 2: output stream

Definition at line 2794 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
SignaturePage stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_signature [protected]

signature page of current written file

Definition at line 2791 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
char stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::WriterSequential::m_signaturestr[8] [protected]

signature characters to begin file with

Definition at line 2788 of file stx-cbtreedb.h.


The documentation for this class was generated from the following file:
Generated on Wed Apr 14 13:43:42 2010 for stx-cbtreedb by  doxygen 1.6.3