STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::hash_map::block_cache< BlockType > Class Template Reference

Detailed Description

template<class BlockType>
class stxxl::hash_map::block_cache< BlockType >

Cache of blocks contained in an external memory hash map. Uses the stxxl::lru_pager as eviction algorithm.

Definition at line 118 of file block_cache.h.

+ Inheritance diagram for stxxl::hash_map::block_cache< BlockType >:
+ Collaboration diagram for stxxl::hash_map::block_cache< BlockType >:

Classes

struct  bid_eq
 
struct  bid_hash
 

Public Types

typedef block_type::bid_type bid_type
 
typedef BlockType block_type
 
typedef subblock_type::bid_type subblock_bid_type
 
typedef block_type::value_type subblock_type
 

Public Member Functions

 block_cache (unsigned_type cache_size)
 Construct a new block-cache. More...
 
 ~block_cache ()
 
void clear ()
 Empty cache; don't write back dirty blocks. More...
 
void flush ()
 Write all dirty blocks back to disk. More...
 
subblock_typeget_subblock (const bid_type &bid, unsigned_type i_subblock)
 Retrieve a subblock from the cache. If not yet cached, only the subblock will be loaded. More...
 
bool make_dirty (const bid_type &bid)
 Set given block's dirty-flag. Note: If the given block was only partially loaded, it will be completely reloaded. More...
 
void prefetch_block (const bid_type &bid)
 Load a block in advance. More...
 
void print_statistics (std::ostream &o=std::cout) const
 Print statistics: Number of hits/misses, blocks forced from cache or written back. More...
 
bool release_block (const bid_type &bid)
 Release a block (decrement retain-count). If the retain-count reaches 0, a block may be kicked again. More...
 
void reset_statistics ()
 Reset all counters to zero. More...
 
bool retain_block (const bid_type &bid)
 Retain a block in cache. Blocks, that are retained by at least one client, won't get kicked. Make sure to release all retained blocks again. More...
 
unsigned_type size () const
 Return cache-size. More...
 
void swap (block_cache &obj)
 Exchange contents of two caches. More...
 

Protected Types

enum  { valid_all = block_type::size }
 
typedef compat_hash_map
< bid_type, unsigned_type,
bid_hash >::result 
bid_map_type
 
typedef stxxl::lru_pager pager_type
 
typedef
block_cache_write_buffer
< block_type
write_buffer_type
 

Protected Member Functions

void kick_block ()
 Force a block from the cache; write back to disk if dirty. More...
 

Protected Attributes

bid_map_type bid_map_
 
std::vector< bid_typebids_
 bids of cached blocks More...
 
std::vector< block_type * > blocks_
 cached blocks More...
 
std::vector< unsigned char > dirty_
 true iff block has been altered while in cache More...
 
std::vector< unsigned_typefree_blocks_
 free blocks as indices to blocks_-vector More...
 
int64 n_clean_forced
 
int64 n_found
 
int64 n_not_found
 
int64 n_read
 
int64 n_written
 
int64 n_wrong_subblock
 
pager_type pager_
 
std::vector< request_ptrreqs_
 
std::vector< unsigned_typeretain_count_
 
std::vector< unsigned_typevalid_subblock_
 valid_all or the actually loaded subblock's index More...
 
write_buffer_type write_buffer_
 

Additional Inherited Members

- Private Member Functions inherited from stxxl::noncopyable
 noncopyable ()
 

Member Typedef Documentation

template<class BlockType>
typedef compat_hash_map<bid_type, unsigned_type, bid_hash>::result stxxl::hash_map::block_cache< BlockType >::bid_map_type
protected

Definition at line 159 of file block_cache.h.

template<class BlockType>
typedef block_type::bid_type stxxl::hash_map::block_cache< BlockType >::bid_type

Definition at line 122 of file block_cache.h.

template<class BlockType>
typedef BlockType stxxl::hash_map::block_cache< BlockType >::block_type

Definition at line 121 of file block_cache.h.

template<class BlockType>
typedef stxxl::lru_pager stxxl::hash_map::block_cache< BlockType >::pager_type
protected

Definition at line 155 of file block_cache.h.

template<class BlockType>
typedef subblock_type::bid_type stxxl::hash_map::block_cache< BlockType >::subblock_bid_type

Definition at line 124 of file block_cache.h.

template<class BlockType>
typedef block_type::value_type stxxl::hash_map::block_cache< BlockType >::subblock_type

Definition at line 123 of file block_cache.h.

template<class BlockType>
typedef block_cache_write_buffer<block_type> stxxl::hash_map::block_cache< BlockType >::write_buffer_type
protected

Definition at line 156 of file block_cache.h.

Member Enumeration Documentation

template<class BlockType>
anonymous enum
protected
Enumerator
valid_all 

Definition at line 161 of file block_cache.h.

Constructor & Destructor Documentation

template<class BlockType>
stxxl::hash_map::block_cache< BlockType >::block_cache ( unsigned_type  cache_size)
inline

Construct a new block-cache.

Parameters
cache_sizecache-size in number of blocks

Definition at line 195 of file block_cache.h.

template<class BlockType>
stxxl::hash_map::block_cache< BlockType >::~block_cache ( )
inline

Definition at line 225 of file block_cache.h.

Member Function Documentation

template<class BlockType>
void stxxl::hash_map::block_cache< BlockType >::flush ( )
inline
template<class BlockType>
subblock_type* stxxl::hash_map::block_cache< BlockType >::get_subblock ( const bid_type bid,
unsigned_type  i_subblock 
)
inline

Retrieve a subblock from the cache. If not yet cached, only the subblock will be loaded.

Parameters
bidblock, to which the requested subblock belongs
i_subblockindex of requested subblock
Returns
pointer to subblock

Definition at line 361 of file block_cache.h.

Referenced by stxxl::hash_map::hash_map< KeyType, MappedType, HashType, CompareType, SubBlockSize, SubBlocksPerBlock, AllocType >::_load_subblock().

template<class BlockType>
void stxxl::hash_map::block_cache< BlockType >::kick_block ( )
inlineprotected

Force a block from the cache; write back to disk if dirty.

Definition at line 250 of file block_cache.h.

template<class BlockType>
bool stxxl::hash_map::block_cache< BlockType >::make_dirty ( const bid_type bid)
inline

Set given block's dirty-flag. Note: If the given block was only partially loaded, it will be completely reloaded.

Returns
true if block cached, false otherwise

Definition at line 331 of file block_cache.h.

template<class BlockType>
void stxxl::hash_map::block_cache< BlockType >::prefetch_block ( const bid_type bid)
inline

Load a block in advance.

Parameters
bidIdentifier of the block to load

Definition at line 433 of file block_cache.h.

template<class BlockType>
void stxxl::hash_map::block_cache< BlockType >::print_statistics ( std::ostream &  o = std::cout) const
inline

Print statistics: Number of hits/misses, blocks forced from cache or written back.

Definition at line 507 of file block_cache.h.

Referenced by stxxl::hash_map::hash_map< KeyType, MappedType, HashType, CompareType, SubBlockSize, SubBlocksPerBlock, AllocType >::print_statistics().

template<class BlockType>
bool stxxl::hash_map::block_cache< BlockType >::release_block ( const bid_type bid)
inline

Release a block (decrement retain-count). If the retain-count reaches 0, a block may be kicked again.

Parameters
bidblock, whose retain-count is to be decremented
Returns
true if operation was successfull (block cached and retain-count > 0), false otherwise

Definition at line 313 of file block_cache.h.

template<class BlockType>
void stxxl::hash_map::block_cache< BlockType >::reset_statistics ( )
inline
template<class BlockType>
bool stxxl::hash_map::block_cache< BlockType >::retain_block ( const bid_type bid)
inline

Retain a block in cache. Blocks, that are retained by at least one client, won't get kicked. Make sure to release all retained blocks again.

Parameters
bidblock, whose retain-count is to be increased
Returns
true if block was cached, false otherwise

Definition at line 296 of file block_cache.h.

template<class BlockType>
unsigned_type stxxl::hash_map::block_cache< BlockType >::size ( ) const
inline

Return cache-size.

Definition at line 220 of file block_cache.h.

template<class BlockType>
void stxxl::hash_map::block_cache< BlockType >::swap ( block_cache< BlockType > &  obj)
inline

Exchange contents of two caches.

Parameters
objcache to swap contents with

Definition at line 530 of file block_cache.h.

Member Data Documentation

template<class BlockType>
bid_map_type stxxl::hash_map::block_cache< BlockType >::bid_map_
protected

Definition at line 181 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
std::vector<bid_type> stxxl::hash_map::block_cache< BlockType >::bids_
protected

bids of cached blocks

Definition at line 168 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
std::vector<block_type*> stxxl::hash_map::block_cache< BlockType >::blocks_
protected

cached blocks

Definition at line 166 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
std::vector<unsigned char> stxxl::hash_map::block_cache< BlockType >::dirty_
protected

true iff block has been altered while in cache

Definition at line 172 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
std::vector<unsigned_type> stxxl::hash_map::block_cache< BlockType >::free_blocks_
protected

free blocks as indices to blocks_-vector

Definition at line 178 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
int64 stxxl::hash_map::block_cache< BlockType >::n_clean_forced
protected

Definition at line 189 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
int64 stxxl::hash_map::block_cache< BlockType >::n_found
protected

Definition at line 185 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
int64 stxxl::hash_map::block_cache< BlockType >::n_not_found
protected

Definition at line 186 of file block_cache.h.

template<class BlockType>
int64 stxxl::hash_map::block_cache< BlockType >::n_read
protected

Definition at line 187 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
int64 stxxl::hash_map::block_cache< BlockType >::n_written
protected

Definition at line 188 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
int64 stxxl::hash_map::block_cache< BlockType >::n_wrong_subblock
protected

Definition at line 190 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
pager_type stxxl::hash_map::block_cache< BlockType >::pager_
protected

Definition at line 182 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
std::vector<request_ptr> stxxl::hash_map::block_cache< BlockType >::reqs_
protected

Definition at line 179 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
std::vector<unsigned_type> stxxl::hash_map::block_cache< BlockType >::retain_count_
protected

Definition at line 169 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
std::vector<unsigned_type> stxxl::hash_map::block_cache< BlockType >::valid_subblock_
protected

valid_all or the actually loaded subblock's index

Definition at line 175 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().

template<class BlockType>
write_buffer_type stxxl::hash_map::block_cache< BlockType >::write_buffer_
protected

Definition at line 163 of file block_cache.h.

Referenced by stxxl::hash_map::block_cache< block_type >::swap().


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