Optimizing the update of counters for the EvictAging policy.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@795 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
d42dc485d9
commit
401fdba600
1 changed files with 19 additions and 6 deletions
|
@ -322,6 +322,7 @@ namespace Loki
|
||||||
// and returns the lower bound of the sorted container
|
// and returns the lower bound of the sorted container
|
||||||
DT& getLowerBound(){
|
DT& getLowerBound(){
|
||||||
assert(!m_mHitCount.empty());
|
assert(!m_mHitCount.empty());
|
||||||
|
// inserting the swapped pair into a multimap
|
||||||
SwappedHitMap copyMap;
|
SwappedHitMap copyMap;
|
||||||
for(HitMapItr itr = m_mHitCount.begin(); itr != m_mHitCount.end(); ++itr)
|
for(HitMapItr itr = m_mHitCount.begin(); itr != m_mHitCount.end(); ++itr)
|
||||||
copyMap.insert(SwappedPair(itr->second, itr->first));
|
copyMap.insert(SwappedPair(itr->second, itr->first));
|
||||||
|
@ -412,6 +413,18 @@ namespace Loki
|
||||||
typedef EvictionHelper< ST, DT > EH;
|
typedef EvictionHelper< ST, DT > EH;
|
||||||
typedef typename EH::HitMap HitMap;
|
typedef typename EH::HitMap HitMap;
|
||||||
typedef typename EH::HitMapItr HitMapItr;
|
typedef typename EH::HitMapItr HitMapItr;
|
||||||
|
|
||||||
|
// update the counter
|
||||||
|
template<class T> struct updateCounter : public std::unary_function<T, void>
|
||||||
|
{
|
||||||
|
updateCounter(const DT& key): key_(key){}
|
||||||
|
void operator()(T x)
|
||||||
|
{
|
||||||
|
x.second = (x.first == key_ ? (x.second >> 1) | ( 1 << ((sizeof(ST)-1)*8) ) : x.second >> 1);
|
||||||
|
D( std::cout << x.second << std::endl; )
|
||||||
|
}
|
||||||
|
const DT &key_;
|
||||||
|
};
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual ~EvictAging(){}
|
virtual ~EvictAging(){}
|
||||||
|
@ -432,10 +445,7 @@ namespace Loki
|
||||||
// the counter is shifted to the left
|
// the counter is shifted to the left
|
||||||
void onRelease(const DT& key)
|
void onRelease(const DT& key)
|
||||||
{
|
{
|
||||||
for( HitMapItr itr = EH::m_mHitCount.begin(); itr != EH::m_mHitCount.end(); ++itr){
|
std::for_each(EH::m_mHitCount.begin(), EH::m_mHitCount.end(), updateCounter< typename HitMap::value_type >(key));
|
||||||
itr->second = (itr->first == key ? (itr->second >> 1) | ( 1 << ((sizeof(ST)-1)*8) ) : itr->second >> 1);
|
|
||||||
D( std::cout << itr->second << std::endl; )
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDestroy(const DT& key)
|
void onDestroy(const DT& key)
|
||||||
|
@ -490,7 +500,8 @@ namespace Loki
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDestroy(const DT& key){
|
void onDestroy(const DT& key){
|
||||||
m_vKeys.erase(remove_if(m_vKeys.begin(), m_vKeys.end(), std::bind2nd(std::equal_to< DT >(), key)), m_vKeys.end());
|
using namespace std;
|
||||||
|
m_vKeys.erase(remove_if(m_vKeys.begin(), m_vKeys.end(), bind2nd(equal_to< DT >(), key)), m_vKeys.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implemented in Cache and redirected to the Storage Policy
|
// Implemented in Cache and redirected to the Storage Policy
|
||||||
|
@ -802,7 +813,9 @@ namespace Loki
|
||||||
// debug information
|
// debug information
|
||||||
SP::onDebug();
|
SP::onDebug();
|
||||||
// cleaning the Cache
|
// cleaning the Cache
|
||||||
for_each(fromKeyToObjVector.begin(), fromKeyToObjVector.end(), deleteVectorObjects< typename KeyToObjVectorMap::value_type >() );
|
for_each(fromKeyToObjVector.begin(), fromKeyToObjVector.end(),
|
||||||
|
deleteVectorObjects< typename KeyToObjVectorMap::value_type >()
|
||||||
|
);
|
||||||
if(!providedObjects.empty())
|
if(!providedObjects.empty())
|
||||||
{
|
{
|
||||||
// The factory is responsible for the creation and destruction of objects.
|
// The factory is responsible for the creation and destruction of objects.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue