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

PageCache and PageCacheImpl implement a LRU-strategy cache of B-tree pages used by CBTreeDB reader objects. More...

#include <stx-cbtreedb.h>

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

List of all members.

Public Member Functions

 PageCache (unsigned int maxpages)
 Create a new page cache containg maxsize pages.
 PageCache (const PageCache &pc)
 Copy Constructor: increment reference counter on base object.
 ~PageCache ()
 Destructor: decrement reference counter on buffer and possibly deallocate it.
PageCacheoperator= (const PageCache &pc)
 Assignment Operator: increment reference counter on base object.
void Clear ()
 Remove all pages from the cache and reset status.
void Store (void *btreeid, uint32_t pageid, const BTreePage &page)
 Store a page object in a cache cell identified by (btreeid,pageid).
bool Retrieve (void *btreeid, uint32_t pageid, BTreePage &outpage)
 Retrieve a cached page identified by (btreeid,pageid).
void SetMaxSize (unsigned int maxsize)
 Change maximum number of pages in cache, note that this does not immediately have effect.
std::vector< std::pair< void
*, uint32_t > > 
GetPagelist () const
 Return a vector listing all currently contained (btreeid,pageid) pairs in LRU order.
bool Verify () const
 Verify the integrity of the LRU list and hash table.

Protected Attributes

PageCacheImplm_impl
 pointer to implementation class.

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 >::PageCache

PageCache and PageCacheImpl implement a LRU-strategy cache of B-tree pages used by CBTreeDB reader objects.

One cache object can be shared between multiple readers. However, this page cache is not thread safe. You may have to wrap some mutex libraries if needed.

The cached pages are put into a hash table for quick lookup by (btreeid,pageid). Simultaneously the HashCells are linked into a doubly chained "LRU"-list with the most recently used page at the head. This allows O(1) algorithms for both Store() and Retrieve() functions. When the maximum number of pages is exceeded, the tail pages of the LRU-list are removed. The drawing below illustrates the data structure used by the class.

Structure of PageCache's arrays and nodes

Definition at line 1328 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 >::PageCache::PageCache ( unsigned int  maxpages  )  [inline, explicit]

Create a new page cache containg maxsize pages.

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

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

Copy Constructor: increment reference counter on base object.

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

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

Destructor: decrement reference counter on buffer and possibly deallocate it.

Definition at line 1352 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 >::PageCache::Clear (  )  [inline]

Remove all pages from the cache and reset status.

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

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
std::vector< std::pair<void*, uint32_t> > stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::PageCache::GetPagelist (  )  const [inline]

Return a vector listing all currently contained (btreeid,pageid) pairs in LRU order.

Used by the test cases for verification.

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

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
PageCache& stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::PageCache::operator= ( const PageCache pc  )  [inline]

Assignment Operator: increment reference counter on base object.

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

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::PageCache::Retrieve ( void *  btreeid,
uint32_t  pageid,
BTreePage outpage 
) [inline]

Retrieve a cached page identified by (btreeid,pageid).

Returns true if the page was found.

Definition at line 1387 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 >::PageCache::SetMaxSize ( unsigned int  maxsize  )  [inline]

Change maximum number of pages in cache, note that this does not immediately have effect.

Definition at line 1394 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 >::PageCache::Store ( void *  btreeid,
uint32_t  pageid,
const BTreePage page 
) [inline]

Store a page object in a cache cell identified by (btreeid,pageid).

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

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

Verify the integrity of the LRU list and hash table.

Definition at line 1407 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>
PageCacheImpl* stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::PageCache::m_impl [protected]

pointer to implementation class.

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


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