A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/ncbi__cache_8hpp_source.html below:

NCBI C++ ToolKit: include/util/ncbi_cache.hpp Source File

1 #ifndef CORELIB___NCBI_CACHE__HPP 2 #define CORELIB___NCBI_CACHE__HPP 61 template

<

class

TKey,

class

TSize>

80 template

<

class

TCacheElementPtr>

84  const

TCacheElementPtr& y)

const 87  if

(x->m_Weight != y->m_Weight) {

88  return

x->m_Weight < y->m_Weight;

90  return

x->m_Order < y->m_Order;

105 template

<

class

TKey,

class

TValue>

147 template

<

class

TKey,

151  class

TSize =

Uint4

>

325 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

328

: m_Capacity(capacity),

337 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

342  while

( !m_CacheSet.empty() ) {

349 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

354  _ASSERT

(set_iter != m_CacheSet.end());

355  _ASSERT

(map_iter != m_CacheMap.end());

358

m_Handler->RemoveElement(map_iter->first, map_iter->second.m_Value);

359

m_CacheMap.erase(map_iter);

360

m_CacheSet.erase(set_iter);

365 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

370  TCacheMap_I

map_iter = m_CacheMap.find((*set_iter)->m_Key);

371

x_EraseElement(set_iter, map_iter);

375 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

385  if

(adjusted_weight <

weight

) {

386

x_PackElementIndex();

388  if

(adjusted_weight <

weight

) {

390  "Cache element weight overflow"

);

395

m_CacheSet.insert(elem);

400 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

406  _ASSERT

(it != m_CacheSet.end());

408

m_CacheSet.erase(it);

409

elem->

m_Order

= x_GetNextCounter();

411

x_PackElementIndex();

414

m_CacheSet.insert(elem);

418 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

423

x_PackElementIndex();

429 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

435  if

( !m_CacheSet.empty() ) {

436  TWeight

weight_shift = (

TWeight

)((*m_CacheSet.begin())->m_Weight - 1);

437  TWeight

weight_max = weight_shift;

442  if

(e->

m_Order

>= (order_shift + order_min)/2) {

453

order_shift = (

TOrder

)(order_shift - order_min);

454  if

(order_shift < 2) {

459

orders.insert((*it)->m_Order);

461  if

(*orders.rbegin() < order_max) {

462

m_Counter = *orders.rbegin();

463

order_min = order_max;

471  ITERATE

(

typename

TOrderSet, it, orders) {

472  if

(*it -

last

> rg_to - rg_from) {

478  if

(rg_to - rg_from < 2) {

480  "Cache element index overflow"

);

483

order_shift = (

TOrder

)(rg_to - rg_from);

486  if

(weight_shift <= 1 && weight_max + 1 <= 0) {

489  "Cache element weight overflow"

);

501

m_Counter = (

TOrder

)(m_Counter - order_shift);

505 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

515  if

(it != m_CacheMap.end() ) {

516  if

((add_flags & fAdd_NoReplace) != 0) {

518

*

result

= eAdd_NotInserted;

522  TCacheSet_I

set_it = m_CacheSet.find(it->second.m_CacheElement);

523

x_EraseElement(set_it, it);

533

ins_flag = m_Handler->CanInsertElement(

key

,

value

)) {

535  while

(GetSize() >= m_Capacity) {

545

*

result

= eAdd_NotInserted;

550  if

( GetSize() == 0 ) {

553

*

result

= eAdd_NotInserted;

561

m_Handler->InsertElement(

key

,

value

);

571 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

578  if

(it != m_CacheMap.end()) {

579

x_UpdateElement(it->second.m_CacheElement);

580  return

it->second.m_Value;

588 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

597  if

(it != m_CacheMap.end()) {

598  if

((get_flags & fGet_NoTouch) == 0) {

599

x_UpdateElement(it->second.m_CacheElement);

604  return

it->second.m_Value;

608  if

((get_flags & fGet_NoCreate) != 0) {

610  "Can not find the requested key"

);

614  if

((get_flags & fGet_NoInsert) == 0) {

618

*

result

= eGet_CreatedAndAdded;

623

*

result

= eGet_CreatedNotAdded;

630 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

636  if

(it == m_CacheMap.end()) {

639  TCacheSet_I

set_it = m_CacheSet.find(it->second.m_CacheElement);

640

x_EraseElement(set_it, it);

645 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

648  if

(new_capacity <= 0) {

650  "Cache capacity must be positive"

);

653  while

(GetSize() > new_capacity) {

656

m_Capacity = new_capacity;

660 template

<

class

TKey,

class

TValue,

class

THandler,

class

TLock,

class

TSize>

664  while

(GetSize() > new_size) {

Default (NOP) element handler.

Exception thrown by CCache.

container_type::iterator iterator

const_iterator begin() const

parent_type::iterator iterator

void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler

Include a standard set of the NCBI C++ Toolkit most basic headers.

static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)

static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)

#define ITERATE(Type, Var, Cont)

ITERATE macro to sequence through container elements.

#define NON_CONST_ITERATE(Type, Var, Cont)

Non constant version of ITERATE macro.

EAddFlags

Flags to control the details of adding new elements to the cache via Add().

TLockType::TWriteLockGuard TGuardType

CCache & operator=(const CCache &)

TSizeType GetSize(void) const

Get current number of elements in the cache.

bool Remove(const TKeyType &key)

Remove element from cache. Do nothing if the key is not cached.

int TAddFlags

bitwise OR of EAddFlags

void SetSize(TSizeType new_size)

Truncate the cache leaving at most new_size elements.

bool operator()(const TCacheElementPtr &x, const TCacheElementPtr &y) const

TValueType Get(const TKeyType &key, TGetFlags get_flags=0, EGetResult *result=NULL)

Get an object from the cache by its key.

NCBI_EXCEPTION_DEFAULT(CCacheException, CException)

int TGetFlags

bitwise OR of EGetFlags

ECache_InsertFlag

Flag indicating if an element can be inserted into cache.

SCacheElement< TKeyType, TSizeType > TCacheElement

TValueType operator[](const TKeyType &key)

Get cache element by the key.

set< TCacheElement *, TCacheLess > TCacheSet

void SetCapacity(TSizeType new_capacity)

Set new capacity of the cache.

void RemoveElement(const TKey &, TValue &)

Special processing of a removed element (e.g. deleting the object)

unique_ptr< THandlerType > m_Handler

EGetFlags

Cache retrieval flags.

CMutex TCacheLock_Default

Default cache lock.

void x_UpdateElement(TCacheElement *elem)

TCacheElement * x_InsertElement(const TKeyType &key, TWeight weight)

map< TKeyType, SValueWithIndex > TCacheMap

void InsertElement(const TKey &, const TValue &)

Special processing of an element to be inserted (e.g.

TSizeType GetCapacity(void) const

Get current capacity of the cache (max allowed number of elements)

TCacheSet::iterator TCacheSet_I

CCacheElement_Less< TCacheElement * > TCacheLess

TWeight x_GetBaseWeight(void) const

TCacheMap::iterator TCacheMap_I

TValue CreateValue(const TKey &)

Element factory – to create elements by key.

TOrder x_GetNextCounter(void)

TCacheElement * m_CacheElement

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.

EAddResult

Result of element insertion.

void x_EraseElement(TCacheSet_I &set_iter, TCacheMap_I &map_iter)

void x_PackElementIndex(void)

CCache(TSizeType capacity, THandler *handler=NULL)

Create cache object with the given capacity.

ECache_InsertFlag CanInsertElement(const TKey &, const TValue &)

Check if the element can be inserted into the cache.

SCacheElement(const TKeyType &key, const TSizeType &weight, const TSizeType &order)

@ eIndexOverflow

Element index overflow.

@ eWeightOverflow

Element weight overflow.

@ eNotFound

The requested key was not found in the cache.

@ fAdd_NoReplace

Do not replace existing values if any.

@ eCache_CanInsert

The element can be inserted.

@ eCache_DoNotCache

The element can not be inserted (e.g. too big)

@ eCache_CheckSize

Insert the element after checking max cache size.

@ eCache_NeedCleanup

Need to cleanup cache before inserting the element.

@ fGet_NoTouch

Do not update the object's position.

@ fGet_NoInsert

Do not insert created values.

@ fGet_NoCreate

Do not create value if not found, throw an exception instead.

@ eGet_CreatedNotAdded

A new value was created but not cached.

@ eGet_CreatedAndAdded

A new value was created and cached.

@ eGet_Found

The key was found in the cache.

@ eAdd_NotInserted

The element was not added or replaced.

@ eAdd_Inserted

The element was added to the cache.

@ eAdd_Replaced

The element existed and was replaced.

#define NCBI_THROW(exception_class, err_code, message)

Generic macro to throw an exception, given the exception class, error code and message string.

EErrCode

Error types that an application can generate.

virtual const char * GetErrCodeString(void) const

Get error code interpreted as text.

uint32_t Uint4

4-byte (32-bit) unsigned integer

#define END_NCBI_SCOPE

End previously defined NCBI scope.

#define BEGIN_NCBI_SCOPE

Define ncbi namespace.

#define NCBI_XNCBI_EXPORT

const struct ncbi::grid::netcache::search::fields::KEY key

const GenericPointer< typename T::ValueType > T2 value

Multi-threading – mutexes; rw-locks; semaphore.

Compare cache elements by weight/order.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4