From 4808617ef54d40efcf1a3ed30525898defb74e10 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 9 Oct 2008 20:20:34 +0000 Subject: More cache development. I'm going to have to switch from template functions to functors. I like template functions a little more, but functors can be at least as fast. It won't be much of a change. --- src/cache.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/cache.h') diff --git a/src/cache.h b/src/cache.h index 24ef652..344d1c6 100644 --- a/src/cache.h +++ b/src/cache.h @@ -1,20 +1,69 @@ #ifndef BU_CACHE_H #define BU_CACHE_H +#include "bu/cptr.h" +#include "bu/hash.h" + +#define BU_TRACE +#include "bu/trace.h" + namespace Bu { + template class Cache; + template long getCacheId( const obtype *o ); + template class Cache { + friend class Bu::CPtr; + typedef Bu::CPtr Ptr; + public: + typedef long cid; /**< Cache ID type. Unique cache entry ID. */ + public: Cache() { + TRACE(); } virtual ~Cache() { + TRACE(); + } + + Ptr insert( obtype *pData ) + { + TRACE(); + CacheEntry e = {pData, 0}; + hEnt.insert( getCacheId( pData ), e ); + return Ptr( *this, pData ); } + private: + void incRef( obtype *pData ) + { + TRACE(); + hEnt.get( getCacheId( pData ) ).iRefs++; + } + + void decRef( obtype *pData ) + { + TRACE(); + CacheEntry &e = hEnt.get( getCacheId( pData ) ); + e.iRefs--; + } + + private: + typedef struct CacheEntry + { + obtype *pData; + int iRefs; + } CacheEntry; + + //typedef Bu::Hash RefHash; + typedef Bu::Hash CidHash; + //RefHash hRefs; + CidHash hEnt; }; }; -- cgit v1.2.3