Kaydet (Commit) 11311b92 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

untabify

Change-Id: Iad53e9cea28c3c7f3a8a2eaa1186d1e1be72affc
üst c35db5ca
...@@ -49,35 +49,35 @@ public: ...@@ -49,35 +49,35 @@ public:
} }
IdxType add( const T& rContent, bool* pbFound) { IdxType add( const T& rContent, bool* pbFound) {
assert( pbFound != NULL); assert( pbFound != NULL);
if( !size_) { if( !size_) {
*pbFound = false; *pbFound = false;
return cache::ignore; return cache::ignore;
} }
// try to insert into the map // try to insert into the map
list_.push_front( rContent); // create a temp entry list_.push_front( rContent); // create a temp entry
typedef std::pair<typename LruList::iterator, IdxType> MappedType; typedef std::pair<typename LruList::iterator, IdxType> MappedType;
typedef std::pair<typename LruItMap::iterator,bool> MapPair; typedef std::pair<typename LruItMap::iterator,bool> MapPair;
MapPair aMP = map_.insert( MappedType( list_.begin(), 0)); MapPair aMP = map_.insert( MappedType( list_.begin(), 0));
*pbFound = !aMP.second; *pbFound = !aMP.second;
if( !aMP.second) { // insertion not needed => found the entry if( !aMP.second) { // insertion not needed => found the entry
list_.pop_front(); // remove the temp entry list_.pop_front(); // remove the temp entry
list_.splice( list_.begin(), list_, aMP.first->first); // the found entry is moved to front list_.splice( list_.begin(), list_, aMP.first->first); // the found entry is moved to front
return aMP.first->second; return aMP.first->second;
} }
// test insertion successful => it was new so we keep it // test insertion successful => it was new so we keep it
IdxType n = static_cast<IdxType>( map_.size() - 1); IdxType n = static_cast<IdxType>( map_.size() - 1);
if( n >= size_) { // cache full => replace the LRU entry if( n >= size_) { // cache full => replace the LRU entry
// find the least recently used element in the map // find the least recently used element in the map
typename LruItMap::iterator it = map_.find( --list_.end()); typename LruItMap::iterator it = map_.find( --list_.end());
n = it->second; n = it->second;
map_.erase( it); // remove it from the map map_.erase( it); // remove it from the map
list_.pop_back(); // remove from the list list_.pop_back(); // remove from the list
} }
aMP.first->second = n; aMP.first->second = n;
return n; return n;
} }
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment