Apollo 10.0
自动驾驶开放平台
apollo::common::util::LRUCache< K, V > 模板类 参考

#include <lru_cache.h>

apollo::common::util::LRUCache< K, V > 的协作图:

Public 成员函数

 LRUCache (const size_t capacity=kDefaultCapacity)
 
 ~LRUCache ()
 
void GetCache (std::map< K, V > *cache)
 
V & operator[] (const K &key)
 
void GetAllSilently (std::vector< V * > *ret)
 
template<typename VV >
bool Put (const K &key, VV &&val)
 
template<typename VV >
bool Update (const K &key, VV &&val)
 
template<typename VV >
bool UpdateSilently (const K &key, VV *val)
 
template<typename VV >
bool Add (const K &key, VV *val)
 
template<typename VV >
bool PutAndGetObsolete (const K &key, VV *val, K *obs)
 
template<typename VV >
bool AddAndGetObsolete (const K &key, VV *val, K *obs)
 
V * GetSilently (const K &key)
 
V * Get (const K &key)
 
bool GetCopySilently (const K &key, V *const val)
 
bool GetCopy (const K &key, V *const val)
 
size_t size ()
 
bool Full ()
 
bool Empty ()
 
size_t capacity ()
 
Node< K, V > * First ()
 
Node< K, V > * Last ()
 
bool Contains (const K &key)
 
bool Prioritize (const K &key)
 
void Clear ()
 
bool Remove (const K &key)
 
bool ChangeCapacity (const size_t capacity)
 

详细描述

template<class K, class V>
class apollo::common::util::LRUCache< K, V >

在文件 lru_cache.h43 行定义.

构造及析构函数说明

◆ LRUCache()

template<class K , class V >
apollo::common::util::LRUCache< K, V >::LRUCache ( const size_t  capacity = kDefaultCapacity)
inlineexplicit

在文件 lru_cache.h45 行定义.

46 : capacity_(capacity), head_(), tail_() {
47 Init();
48 }

◆ ~LRUCache()

template<class K , class V >
apollo::common::util::LRUCache< K, V >::~LRUCache ( )
inline

在文件 lru_cache.h50 行定义.

成员函数说明

◆ Add()

template<class K , class V >
template<typename VV >
bool apollo::common::util::LRUCache< K, V >::Add ( const K &  key,
VV *  val 
)
inline

在文件 lru_cache.h112 行定义.

112 {
113 K tmp;
114 return Update(key, std::forward<VV>(*val), &tmp, true, false);
115 }
bool Update(const K &key, VV &&val)
Definition lru_cache.h:88

◆ AddAndGetObsolete()

template<class K , class V >
template<typename VV >
bool apollo::common::util::LRUCache< K, V >::AddAndGetObsolete ( const K &  key,
VV *  val,
K *  obs 
)
inline

在文件 lru_cache.h123 行定义.

123 {
124 return Update(key, std::forward<VV>(*val), obs, true, false);
125 }

◆ capacity()

template<class K , class V >
size_t apollo::common::util::LRUCache< K, V >::capacity ( )
inline

在文件 lru_cache.h143 行定义.

143{ return capacity_; }

◆ ChangeCapacity()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::ChangeCapacity ( const size_t  capacity)
inline

在文件 lru_cache.h185 行定义.

185 {
186 if (size() > capacity) {
187 return false;
188 }
189 capacity_ = capacity;
190 return true;
191 }

◆ Clear()

template<class K , class V >
void apollo::common::util::LRUCache< K, V >::Clear ( )
inline

在文件 lru_cache.h171 行定义.

171 {
172 map_.clear();
173 Init();
174 }

◆ Contains()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::Contains ( const K &  key)
inline

在文件 lru_cache.h159 行定义.

159{ return map_.find(key) != map_.end(); }

◆ Empty()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::Empty ( )
inline

在文件 lru_cache.h141 行定义.

141{ return size() == 0; }

◆ First()

template<class K , class V >
Node< K, V > * apollo::common::util::LRUCache< K, V >::First ( )
inline

在文件 lru_cache.h145 行定义.

145 {
146 if (size()) {
147 return head_.next;
148 }
149 return nullptr;
150 }

◆ Full()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::Full ( )
inline

在文件 lru_cache.h139 行定义.

139{ return size() > 0 && size() >= capacity_; }

◆ Get()

template<class K , class V >
V * apollo::common::util::LRUCache< K, V >::Get ( const K &  key)
inline

在文件 lru_cache.h129 行定义.

129{ return Get(key, false); }

◆ GetAllSilently()

template<class K , class V >
void apollo::common::util::LRUCache< K, V >::GetAllSilently ( std::vector< V * > *  ret)
inline

在文件 lru_cache.h69 行定义.

69 {
70 for (auto it = map_.begin(); it != map_.end(); ++it) {
71 ret->push_back(&it->second.val);
72 }
73 }

◆ GetCache()

template<class K , class V >
void apollo::common::util::LRUCache< K, V >::GetCache ( std::map< K, V > *  cache)
inline

在文件 lru_cache.h52 行定义.

52 {
53 for (auto it = map_.begin(); it != map_.end(); ++it) {
54 cache->emplace(it->first, it->second.val);
55 }
56 }

◆ GetCopy()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::GetCopy ( const K &  key,
V *const  val 
)
inline

在文件 lru_cache.h135 行定义.

135{ return GetCopy(key, val, false); }
bool GetCopy(const K &key, V *const val)
Definition lru_cache.h:135

◆ GetCopySilently()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::GetCopySilently ( const K &  key,
V *const  val 
)
inline

在文件 lru_cache.h131 行定义.

131 {
132 return GetCopy(key, val, true);
133 }

◆ GetSilently()

template<class K , class V >
V * apollo::common::util::LRUCache< K, V >::GetSilently ( const K &  key)
inline

在文件 lru_cache.h127 行定义.

127{ return Get(key, true); }

◆ Last()

template<class K , class V >
Node< K, V > * apollo::common::util::LRUCache< K, V >::Last ( )
inline

在文件 lru_cache.h152 行定义.

152 {
153 if (size()) {
154 return tail_.prev;
155 }
156 return nullptr;
157 }

◆ operator[]()

template<class K , class V >
V & apollo::common::util::LRUCache< K, V >::operator[] ( const K &  key)
inline

在文件 lru_cache.h58 行定义.

58 {
59 if (!Contains(key)) {
60 K obsolete;
61 GetObsolete(&obsolete);
62 }
63 return map_[key].val;
64 }
bool Contains(const K &key)
Definition lru_cache.h:159

◆ Prioritize()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::Prioritize ( const K &  key)
inline

在文件 lru_cache.h161 行定义.

161 {
162 if (Contains(key)) {
163 auto* node = &map_[key];
164 Detach(node);
165 Attach(node);
166 return true;
167 }
168 return false;
169 }

◆ Put()

template<class K , class V >
template<typename VV >
bool apollo::common::util::LRUCache< K, V >::Put ( const K &  key,
VV &&  val 
)
inline

在文件 lru_cache.h79 行定义.

79 {
80 K tmp;
81 return Update(key, std::forward<VV>(val), &tmp, false, false);
82 }

◆ PutAndGetObsolete()

template<class K , class V >
template<typename VV >
bool apollo::common::util::LRUCache< K, V >::PutAndGetObsolete ( const K &  key,
VV *  val,
K *  obs 
)
inline

在文件 lru_cache.h118 行定义.

118 {
119 return Update(key, std::forward<VV>(*val), obs, false, false);
120 }

◆ Remove()

template<class K , class V >
bool apollo::common::util::LRUCache< K, V >::Remove ( const K &  key)
inline

在文件 lru_cache.h176 行定义.

176 {
177 if (!Contains(key)) {
178 return false;
179 }
180 auto* node = &map_[key];
181 Detach(node);
182 return true;
183 }

◆ size()

template<class K , class V >
size_t apollo::common::util::LRUCache< K, V >::size ( )
inline

在文件 lru_cache.h137 行定义.

137{ return size_; }

◆ Update()

template<class K , class V >
template<typename VV >
bool apollo::common::util::LRUCache< K, V >::Update ( const K &  key,
VV &&  val 
)
inline

在文件 lru_cache.h88 行定义.

88 {
89 if (!Contains(key)) {
90 return false;
91 }
92 K tmp;
93 return Update(key, std::forward<VV>(val), &tmp, true, false);
94 }

◆ UpdateSilently()

template<class K , class V >
template<typename VV >
bool apollo::common::util::LRUCache< K, V >::UpdateSilently ( const K &  key,
VV *  val 
)
inline

在文件 lru_cache.h100 行定义.

100 {
101 if (!Contains(key)) {
102 return false;
103 }
104 K tmp;
105 return Update(key, std::forward<VV>(*val), &tmp, true, true);
106 }

该类的文档由以下文件生成: