Exemplo n.º 1
0
Arquivo: lru.hpp Projeto: kouhate/ardb
			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;
			}
Exemplo n.º 2
0
 size_t Size()
 {
     return m_entry_map.size();
 }