Doxygen
Cache< K, V > 模板类 参考

#include <cache.h>

+ 类 Cache< K, V > 继承关系图:

Public 类型

using kv_pair = std::pair< K, V >
 
using iterator = typename std::list< kv_pair >::iterator
 
using const_iterator = typename std::list< kv_pair >::const_iterator
 

Public 成员函数

 Cache (size_t capacity)
 creates a cache that can hold capacity elements 更多...
 
V * insert (const K &key, V &&value)
 Inserts value under key in the cache 更多...
 
V * insert (const K &key, const V &value)
 Inserts value under key in the cache 更多...
 
void remove (const K &key)
 Removes entry key from the cache. 更多...
 
V * find (const K &key)
 Finds a value in the cache given the corresponding key. 更多...
 
size_t size () const
 Returns the number of values stored in the cache. 更多...
 
size_t capacity () const
 Returns the maximum number of values that can be stored in the cache. 更多...
 
uint64_t hits () const
 Returns how many of the find() calls did find a value in the cache. 更多...
 
uint64_t misses () const
 Returns how many of the find() calls did not found a value in the cache. 更多...
 
void clear ()
 Clears all values in the cache. 更多...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 

Private 成员函数

void resize ()
 

Private 属性

size_t m_capacity
 
std::list< kv_pairm_cacheItemList
 
std::unordered_map< K, iteratorm_cacheItemMap
 
uint64_t m_hits =0
 
uint64_t m_misses =0
 

详细描述

template<typename K, typename V>
class Cache< K, V >

Fixed size cache for value type V using keys of type K.

When the maximum capacity has reached, the least recently used value is removed from the cache (LRU strategy).

在文件 cache.h30 行定义.

成员类型定义说明

◆ const_iterator

template<typename K , typename V >
using Cache< K, V >::const_iterator = typename std::list<kv_pair>::const_iterator

在文件 cache.h48 行定义.

◆ iterator

template<typename K , typename V >
using Cache< K, V >::iterator = typename std::list<kv_pair>::iterator

在文件 cache.h47 行定义.

◆ kv_pair

template<typename K , typename V >
using Cache< K, V >::kv_pair = std::pair<K,V>

在文件 cache.h46 行定义.

构造及析构函数说明

◆ Cache()

template<typename K , typename V >
Cache< K, V >::Cache ( size_t  capacity)
inline

creates a cache that can hold capacity elements

在文件 cache.h51 行定义.

58  {

成员函数说明

◆ begin() [1/2]

template<typename K , typename V >
iterator Cache< K, V >::begin ( )
inline

在文件 cache.h150 行定义.

◆ begin() [2/2]

template<typename K , typename V >
const_iterator Cache< K, V >::begin ( ) const
inline

在文件 cache.h152 行定义.

◆ capacity()

template<typename K , typename V >
size_t Cache< K, V >::capacity ( ) const
inline

Returns the maximum number of values that can be stored in the cache.

在文件 cache.h126 行定义.

126  {
127  return m_misses;
128  }
129 

◆ clear()

template<typename K , typename V >
void Cache< K, V >::clear ( )
inline

Clears all values in the cache.

在文件 cache.h144 行定义.

144  {
145  if (m_cacheItemMap.size() > m_capacity)
146  {
147  auto last_it = m_cacheItemList.end();
148  --last_it;

被这些函数引用 parseInput().

◆ end() [1/2]

template<typename K , typename V >
iterator Cache< K, V >::end ( )
inline

在文件 cache.h151 行定义.

◆ end() [2/2]

template<typename K , typename V >
const_iterator Cache< K, V >::end ( ) const
inline

在文件 cache.h153 行定义.

◆ find()

template<typename K , typename V >
V* Cache< K, V >::find ( const K &  key)
inline

Finds a value in the cache given the corresponding key.

返回
a pointer to the value or nullptr if the key is not found in the cache
注解
The hit and miss counters are updated, see hits() and misses().

在文件 cache.h99 行定义.

100  {
101  m_misses++;
102  }
103  return nullptr;
104  }
105 
106  //! Returns the number of values stored in the cache.
107  size_t size() const
108  {
109  return m_cacheItemMap.size();
110  }
111 
112  //! Returns the maximum number of values that can be stored in the cache.
113  size_t capacity() const
114  {
115  return m_capacity;
116  }
117 

被这些函数引用 SymbolResolver::Private::getResolvedClassRec().

◆ hits()

template<typename K , typename V >
uint64_t Cache< K, V >::hits ( ) const
inline

Returns how many of the find() calls did find a value in the cache.

在文件 cache.h132 行定义.

132  {
133  m_cacheItemMap.clear();
134  m_cacheItemList.clear();
135  }

◆ insert() [1/2]

template<typename K , typename V >
V* Cache< K, V >::insert ( const K &  key,
const V &  value 
)
inline

Inserts value under key in the cache

在文件 cache.h70 行定义.

73  {
74  // remove item if it already exists
75  auto it = m_cacheItemMap.find(key);
76  if (it != m_cacheItemMap.end())
77  {
78  m_cacheItemList.erase(it->second);
79  m_cacheItemMap.erase(it);
80  }
81  }

◆ insert() [2/2]

template<typename K , typename V >
V* Cache< K, V >::insert ( const K &  key,
V &&  value 
)
inline

Inserts value under key in the cache

在文件 cache.h56 行定义.

58  {
59  // remove item if it already exists
60  remove(key);
61  // store new item
62  m_cacheItemList.push_front(kv_pair(key,value));
63  V *result = &m_cacheItemList.front().second;
64  m_cacheItemMap[key] = m_cacheItemList.begin();
65  // remove least recently used item if cache is full
66  resize();
67  return result;

被这些函数引用 SymbolResolver::Private::getResolvedClassRec().

◆ misses()

template<typename K , typename V >
uint64_t Cache< K, V >::misses ( ) const
inline

Returns how many of the find() calls did not found a value in the cache.

在文件 cache.h138 行定义.

138  { return m_cacheItemList.end(); }
139  const_iterator begin() const { return m_cacheItemList.cbegin(); }
140  const_iterator end() const { return m_cacheItemList.cend(); }
141 

◆ remove()

template<typename K , typename V >
void Cache< K, V >::remove ( const K &  key)
inline

Removes entry key from the cache.

注解
this invalidates any iterators

在文件 cache.h85 行定义.

87  {
88  auto it = m_cacheItemMap.find(key);
89  if (it != m_cacheItemMap.end())
90  {
91  // move the item to the front of the list
92  m_cacheItemList.splice(m_cacheItemList.begin(),
94  it->second);

被这些函数引用 flushCachedTemplateRelations(), flushUnresolvedRelations() , 以及 Cache< std::string, LookupInfo >::insert().

◆ resize()

template<typename K , typename V >
void Cache< K, V >::resize ( )
inlineprivate

在文件 cache.h156 行定义.

被这些函数引用 Cache< std::string, LookupInfo >::insert().

◆ size()

template<typename K , typename V >
size_t Cache< K, V >::size ( ) const
inline

Returns the number of values stored in the cache.

在文件 cache.h120 行定义.

120  {
121  return m_hits;
122  }
123 

类成员变量说明

◆ m_cacheItemList

◆ m_cacheItemMap

template<typename K , typename V >
std::unordered_map<K,iterator> Cache< K, V >::m_cacheItemMap
private

◆ m_capacity

template<typename K , typename V >
size_t Cache< K, V >::m_capacity
private

在文件 cache.h166 行定义.

被这些函数引用 Cache< std::string, LookupInfo >::clear().

◆ m_hits

template<typename K , typename V >
uint64_t Cache< K, V >::m_hits =0
private

在文件 cache.h171 行定义.

被这些函数引用 Cache< std::string, LookupInfo >::remove() , 以及 Cache< std::string, LookupInfo >::size().

◆ m_misses

template<typename K , typename V >
uint64_t Cache< K, V >::m_misses =0
private

该类的文档由以下文件生成:
Cache::m_cacheItemMap
std::unordered_map< K, iterator > m_cacheItemMap
Definition: cache.h:170
Cache::end
iterator end()
Definition: cache.h:151
Cache::kv_pair
std::pair< K, V > kv_pair
Definition: cache.h:46
Cache::const_iterator
typename std::list< kv_pair >::const_iterator const_iterator
Definition: cache.h:48
Cache::m_capacity
size_t m_capacity
Definition: cache.h:166
Cache::resize
void resize()
Definition: cache.h:156
Cache::m_misses
uint64_t m_misses
Definition: cache.h:172
Cache::size
size_t size() const
Returns the number of values stored in the cache.
Definition: cache.h:120
Cache::capacity
size_t capacity() const
Returns the maximum number of values that can be stored in the cache.
Definition: cache.h:126
Cache::remove
void remove(const K &key)
Removes entry key from the cache.
Definition: cache.h:85
Cache::begin
iterator begin()
Definition: cache.h:150
Cache::m_hits
uint64_t m_hits
Definition: cache.h:171
Cache::m_cacheItemList
std::list< kv_pair > m_cacheItemList
Definition: cache.h:168