From 55f8e2c01fe4513d5e3de55f567c392b4a18ecc2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 13 Mar 2013 05:03:59 +0000 Subject: Added bind/unbind to the Cache system. Fixed typo in docs of heap. --- src/stable/heap.h | 2 +- src/tests/cache.cpp | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/stable/heap.h b/src/stable/heap.h index 2fcd387..d197b91 100644 --- a/src/stable/heap.h +++ b/src/stable/heap.h @@ -191,7 +191,7 @@ namespace Bu * objects enqueued must support less-than-comparison. Then every time an * item is dequeued it is always the least item in the heap. The heap * operates using a binary tree for storage, which allows most operations - * to be very fast. Enqueueing and dequeueing are both O(log(N)) operatoins + * to be very fast. Enqueueing and dequeueing are both O(log(N)) operations * whereas peeking is constant time. * * This heap implementation allows iterating, however please note that any diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp index 15662af..aa71c39 100644 --- a/src/tests/cache.cpp +++ b/src/tests/cache.cpp @@ -220,7 +220,7 @@ public: virtual ~CachePtr() { - release(); + unbind(); } const keytype &getKey() const @@ -230,31 +230,31 @@ public: obtype &operator*() { - checkRef(); + bind(); return pData; } const obtype &operator*() const { - checkRef(); + bind(); return pData; } obtype *operator->() { - checkRef(); + bind(); return pData; } const obtype *operator->() const { - checkRef(); + bind(); return pData; } MyType operator=( const MyType &rhs ) { - release(); + unbind(); pCache = rhs.pCache; kId = rhs.kId; pEnt = rhs.pEnt; @@ -275,22 +275,27 @@ public: return pCache != rhs.pCache || kId != rhs.kId; } + + void bind() + { + CachePtrInterface::checkRef( pCache, kId, pEnt, pData ); + } - void release() + void unbind() { CachePtrInterface::releaseRef( pCache, pEnt, pData ); } void lock() { - checkRef(); + bind(); if( pEnt ) pEnt->lock(); } void unlock() { - checkRef(); + bind(); if( pEnt ) pEnt->unlock(); } @@ -323,12 +328,6 @@ public: bool bLocked; }; -private: - void checkRef() - { - CachePtrInterface::checkRef( pCache, kId, pEnt, pData ); - } - private: CacheBase *pCache; mutable keytype kId; @@ -658,13 +657,13 @@ int main( int argc, char *argv[] ) c._debug(); - p1.release(); + p1.unbind(); c._debug(); Bu::println("Name: %1").arg( p1->getName() ); - p1.release(); + p1.unbind(); p1.lock(); p1.unlock(); -- cgit v1.2.3