Пример #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 Contains(const key_type& key)
 {
     typename CacheEntryMap::iterator found = m_entry_map.find(key);
     return found != m_entry_map.end();
 }