Apollo 10.0
自动驾驶开放平台
apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache > 模板类 参考

The data structure of the LRUCache. 更多...

#include <base_map_cache.h>

apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache > 的协作图:

Public 类型

using DestroyFunc = std::function< bool(Element *)>
 

Public 成员函数

 MapNodeCache (unsigned int capacity, const DestroyFunc &destroy_func)
 The constructor.
 
 ~MapNodeCache ()
 The destructor.
 
bool Get (const Key &key, Element **value)
 Find element for key if it exists in the cache.
 
bool GetSilent (const Key &key, Element **value)
 Find element for key if it exists in the cache.
 
Element * Put (const Key &key, Element *value)
 Caches element for key.
 
Element * Remove (const Key &key)
 Remove element for key.
 
Element * ClearOne ()
 Remove the Least Recently Used element in the cache.
 
bool IsExist (const Key &key)
 Find element for key in the cache.
 
bool ChangeCapacity (int capacity)
 Change cache's max capacity.
 
unsigned int Size ()
 return cache's in use.
 
unsigned Capacity ()
 return cache's max capacity.
 

静态 Public 成员函数

static bool CacheL1Destroy (Element *value)
 
static bool CacheL2Destroy (Element *value)
 

详细描述

template<class Key, class Element, class MapLRUCache = LRUCache<Key, Element>>
class apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >

The data structure of the LRUCache.

在文件 base_map_cache.h33 行定义.

成员类型定义说明

◆ DestroyFunc

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
using apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::DestroyFunc = std::function<bool(Element*)>

在文件 base_map_cache.h35 行定义.

构造及析构函数说明

◆ MapNodeCache()

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::MapNodeCache ( unsigned int  capacity,
const DestroyFunc destroy_func 
)
inline

The constructor.

在文件 base_map_cache.h46 行定义.

47 : destroy_func_(destroy_func), lru_map_nodes_(capacity) {}

◆ ~MapNodeCache()

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::~MapNodeCache ( )
inline

The destructor.

在文件 base_map_cache.h49 行定义.

49{}

成员函数说明

◆ CacheL1Destroy()

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
static bool apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::CacheL1Destroy ( Element *  value)
inlinestatic

在文件 base_map_cache.h36 行定义.

36 {
37 value->SetIsReserved(false);
38 return true;
39 }

◆ CacheL2Destroy()

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
static bool apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::CacheL2Destroy ( Element *  value)
inlinestatic

在文件 base_map_cache.h40 行定义.

40 {
41 return !(value->GetIsReserved());
42 }

◆ Capacity()

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
unsigned apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::Capacity ( )
inline

return cache's max capacity.

在文件 base_map_cache.h79 行定义.

79{ return lru_map_nodes_.capacity(); }

◆ ChangeCapacity()

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
bool apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::ChangeCapacity ( int  capacity)
inline

Change cache's max capacity.

New capacity must be larger than size in use.

在文件 base_map_cache.h73 行定义.

73 {
74 return lru_map_nodes_.ChangeCapacity(capacity);
75 }

◆ ClearOne()

template<class Key , class Element , class MapLRUCache >
Element * apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::ClearOne ( )

Remove the Least Recently Used element in the cache.

return the removed element or null.

在文件 base_map_cache.h155 行定义.

155 {
156 auto* node_remove = lru_map_nodes_.Last();
157 if (!node_remove) {
158 return nullptr;
159 }
160 while (node_remove != lru_map_nodes_.First()) {
161 if (destroy_func_(node_remove->val)) {
162 lru_map_nodes_.Remove(node_remove->key);
163 return node_remove->val;
164 }
165 node_remove = node_remove->prev;
166 }
167 if (node_remove == lru_map_nodes_.First() &&
168 destroy_func_(node_remove->val)) {
169 lru_map_nodes_.Remove(node_remove->key);
170 return node_remove->val;
171 }
172 return nullptr;
173}

◆ Get()

template<class Key , class Element , class MapLRUCache >
bool apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::Get ( const Key &  key,
Element **  value 
)

Find element for key if it exists in the cache.

If not exist, return false.

在文件 base_map_cache.h91 行定义.

92 {
93 auto value_ptr = lru_map_nodes_.Get(key);
94 if (!value_ptr) {
95 return false;
96 }
97 *value = *value_ptr;
98 return true;
99}

◆ GetSilent()

template<class Key , class Element , class MapLRUCache >
bool apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::GetSilent ( const Key &  key,
Element **  value 
)

Find element for key if it exists in the cache.

If not exist, return false. This function is thread safe, but don't change position of element in LRU queue.

在文件 base_map_cache.h102 行定义.

103 {
104 auto value_ptr = lru_map_nodes_.GetSilently(key);
105 if (!value_ptr) {
106 return false;
107 }
108 *value = *value_ptr;
109 return true;
110}

◆ IsExist()

template<class Key , class Element , class MapLRUCache >
bool apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::IsExist ( const Key &  key)

Find element for key in the cache.

If it exists, move it to the head of queue.

在文件 base_map_cache.h176 行定义.

176 {
177 return lru_map_nodes_.Prioritize(key);
178}

◆ Put()

template<class Key , class Element , class MapLRUCache >
Element * apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::Put ( const Key &  key,
Element *  value 
)

Caches element for key.

If cache is full, return the removed element, otherwise return null.

在文件 base_map_cache.h113 行定义.

114 {
115 if (value == nullptr) {
116 AINFO << "LRUCache Warning: put a NULL";
117 return nullptr;
118 }
119
120 auto* value_ptr = lru_map_nodes_.Get(key);
121 Element* node_remove = nullptr;
122 if (value_ptr) {
123 node_remove = *value_ptr;
124 if (destroy_func_(node_remove)) {
125 *value_ptr = value;
126 } else {
127 node_remove = value;
128 }
129 return node_remove;
130 }
131
132 if (lru_map_nodes_.size() >= lru_map_nodes_.capacity()) {
133 auto* node = lru_map_nodes_.Last();
134 node_remove = node->val;
135 Key key_tmp;
136 lru_map_nodes_.PutAndGetObsolete(key, &value, &key_tmp);
137 return node_remove;
138 }
139
140 lru_map_nodes_.Put(key, std::move(value));
141 return node_remove;
142}
#define AINFO
Definition log.h:42

◆ Remove()

template<class Key , class Element , class MapLRUCache >
Element * apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::Remove ( const Key &  key)

Remove element for key.

if it exist in the cache, return the element, otherwise return null.

在文件 base_map_cache.h145 行定义.

145 {
146 auto* node_remove = lru_map_nodes_.GetSilently(key);
147 if (node_remove && lru_map_nodes_.Remove(key)) {
148 return *node_remove;
149 }
150
151 return nullptr;
152}

◆ Size()

template<class Key , class Element , class MapLRUCache = LRUCache<Key, Element>>
unsigned int apollo::localization::msf::MapNodeCache< Key, Element, MapLRUCache >::Size ( )
inline

return cache's in use.

在文件 base_map_cache.h77 行定义.

77{ return lru_map_nodes_.size(); }

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