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; }
bool Erase(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_entry_map.erase(found); return true; } return false; }
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; }
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; }