NCBI C++ ToolKit
|
Search Toolkit Book for CCache
Cache template. More...
#include <util/ncbi_cache.hpp>
Classes | |
struct | SValueWithIndex |
Public Types | |
enum | EAddFlags { fAdd_NoReplace = (1 << 0) } |
Flags to control the details of adding new elements to the cache via Add(). More... | |
enum | EAddResult { eAdd_Inserted , eAdd_Replaced , eAdd_NotInserted } |
Result of element insertion. More... | |
enum | EGetFlags { fGet_NoTouch = (1 << 0) , fGet_NoCreate = (1 << 1) , fGet_NoInsert = (1 << 2) } |
Cache retrieval flags. More... | |
enum | EGetResult { eGet_Found , eGet_CreatedAndAdded , eGet_CreatedNotAdded } |
Get() result. More... | |
typedef TKey | TKeyType |
typedef TValue | TValueType |
typedef TSize | TSizeType |
typedef SCacheElement< TKeyType, TSizeType > | TCacheElement |
typedef TSizeType | TWeight |
typedef TSizeType | TOrder |
typedef int | TAddFlags |
bitwise OR of EAddFlags More... | |
typedef int | TGetFlags |
bitwise OR of EGetFlags More... | |
Public Member Functions | |
CCache (TSizeType capacity, THandler *handler=NULL) | |
Create cache object with the given capacity. More... | |
TValueType | operator[] (const TKeyType &key) |
Get cache element by the key. More... | |
TSizeType | GetCapacity (void) const |
Get current capacity of the cache (max allowed number of elements) More... | |
void | SetCapacity (TSizeType new_capacity) |
Set new capacity of the cache. More... | |
TSizeType | GetSize (void) const |
Get current number of elements in the cache. More... | |
void | SetSize (TSizeType new_size) |
Truncate the cache leaving at most new_size elements. More... | |
TOrder | Add (const TKeyType &key, const TValueType &value, TWeight weight=1, TAddFlags add_flags=0, EAddResult *result=NULL) |
Add new element to the cache or replace the existing value. More... | |
TValueType | Get (const TKeyType &key, TGetFlags get_flags=0, EGetResult *result=NULL) |
Get an object from the cache by its key. More... | |
bool | Remove (const TKeyType &key) |
Remove element from cache. Do nothing if the key is not cached. More... | |
~CCache (void) | |
Private Types | |
typedef CCacheElement_Less< TCacheElement * > | TCacheLess |
typedef set< TCacheElement *, TCacheLess > | TCacheSet |
typedef TCacheSet::iterator | TCacheSet_I |
typedef map< TKeyType, SValueWithIndex > | TCacheMap |
typedef TCacheMap::iterator | TCacheMap_I |
typedef TLock | TLockType |
typedef TLockType::TWriteLockGuard | TGuardType |
typedef THandler | THandlerType |
Private Member Functions | |
CCache (const CCache &) | |
CCache & | operator= (const CCache &) |
TOrder | x_GetNextCounter (void) |
void | x_PackElementIndex (void) |
TCacheElement * | x_InsertElement (const TKeyType &key, TWeight weight) |
void | x_UpdateElement (TCacheElement *elem) |
void | x_EraseElement (TCacheSet_I &set_iter, TCacheMap_I &map_iter) |
void | x_EraseLast (void) |
TWeight | x_GetBaseWeight (void) const |
Private Attributes | |
TLockType | m_Lock |
TSizeType | m_Capacity |
TCacheSet | m_CacheSet |
TCacheMap | m_CacheMap |
TOrder | m_Counter |
unique_ptr< THandlerType > | m_Handler |
Cache template.
TKey and TValue define types stored in the cache. TLock must define TWriteLockGuard subtype so that a value of type TLock can be used to initialize TWriteLockGuard. TSize is an integer type used for element indexing. THandler must provide the following callback methods: void RemoveElement(const TKey& key, TValue& value) void InsertElement(const TKey& key, const TValue& value) ECache_InsertFlag CanInsertElement(const TKey& key, const TValue& value) TValue CreateValue(const TKey& key)
Definition at line 152 of file ncbi_cache.hpp.