Пример #1
0
			bool Insert(const key_type& key, const value_type& value,
					value_type* erase_value)
			{
				typename CacheEntryMap::iterator found = m_entry_map.find(key);
				bool erased_old = false;
				if (found != m_entry_map.end())
				{
					erased_old = true;
					if (NULL != erase_value)
					{
						(*erase_value) = (*found->second);
					}
					m_cache_list.erase(found->second);
				}
				m_cache_list.push_front(std::make_pair(key, value));
				m_entry_map[key] = m_cache_list.begin();
				if (m_entry_map.size() > m_max_size)
				{
					if (NULL != erase_value)
					{
						(*erase_value) = m_cache_list.back();
					}
					m_entry_map.erase(m_cache_list.back().first);
					m_cache_list.pop_back();
					erased_old = true;
				}
				return erased_old;
			}
Пример #2
0
 bool Peek(const key_type& key, value_type& value)
 {
     typename CacheEntryMap::iterator found = m_entry_map.find(key);
     if (found != m_entry_map.end())
     {
         typename CacheList::iterator list_it = found->second;
         value = list_it->second;
         return true;
     }
     return false;
 }
Пример #3
0
 bool Get(const key_type& key, value_type& value)
 {
     typename CacheEntryMap::iterator found = m_entry_map.find(key);
     if (found != m_entry_map.end())
     {
         typename CacheList::iterator list_it = found->second;
         value = list_it->second;
         m_cache_list.erase(list_it);
         m_cache_list.push_front(std::make_pair(key, value));
         m_entry_map[key] = m_cache_list.begin();
         return true;
     }
     return false;
 }
Пример #4
0
 bool GetLRUElement(CacheEntry& value, bool remove)
 {
     if (m_cache_list.empty())
     {
         return false;
     }
     value = m_cache_list.back();
     if (remove)
     {
         m_entry_map.erase(value.first);
         m_cache_list.pop_back();
     }
     return true;
 }
Пример #5
0
			bool GetLRUElement(value_type& value, bool remove)
			{
				if (m_cache_list.empty())
				{
					return false;
				}
				CacheEntry & entry = m_cache_list.back();
				value = entry.second;
				if (remove)
				{
					m_entry_map.erase(entry.first);
					m_cache_list.pop_back();
				}
				return true;
			}
Пример #6
0
 bool Contains(const key_type& key)
 {
     typename CacheEntryMap::iterator found = m_entry_map.find(key);
     return found != m_entry_map.end();
 }
Пример #7
0
 size_t Size()
 {
     return m_entry_map.size();
 }
Пример #8
0
 void Clear()
 {
     m_cache_list.clear();
     m_entry_map.clear();
 }