From 3cea09281c9f809fc78de6f2e79f4117976f74e4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 20 Feb 2008 08:07:31 +0000 Subject: Applied an update from Hash to Set (they're basically the same logic/code, in fact, I need to get in there and change all the comments and exceptions in Set to refer to Set and not Hash). Util has the functors in it that are shared now, and List actually uses those functors for it's insertSorted function, that thing has come in so handy. --- src/heap.h | 36 ------------------------------------ src/list.h | 14 +++++++++----- src/set.h | 1 + src/util.h | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/heap.h b/src/heap.h index dd2764f..2741818 100644 --- a/src/heap.h +++ b/src/heap.h @@ -19,42 +19,6 @@ namespace Bu { subExceptionDecl( HeapException ); - template - struct __basicLTCmp - { - bool operator()( const item &a, const item &b ) - { - return a < b; - } - }; - - template - struct __basicGTCmp - { - bool operator()( const item &a, const item &b ) - { - return a > b; - } - }; - - template - struct __basicPtrLTCmp - { - bool operator()( const item &a, const item &b ) - { - return *a < *b; - } - }; - - template - struct __basicPtrGTCmp - { - bool operator()( const item &a, const item &b ) - { - return *a > *b; - } - }; - template, typename itemalloc=std::allocator > class Heap { diff --git a/src/list.h b/src/list.h index d8ddd08..30edf71 100644 --- a/src/list.h +++ b/src/list.h @@ -10,6 +10,7 @@ #include #include "bu/exceptionbase.h" +#include "bu/util.h" namespace Bu { @@ -34,12 +35,14 @@ namespace Bu *@param linkalloc (typename) Memory Allocator for the list links. *@ingroup Containers */ - template, typename linkalloc=std::allocator > > + template, + typename valuealloc=std::allocator, + typename linkalloc=std::allocator > > class List { private: typedef struct ListLink Link; - typedef class List MyType; + typedef class List MyType; public: List() : @@ -189,7 +192,7 @@ namespace Bu Link *pCur = pFirst; for(;;) { - if( !(v > *(pCur->pValue)) ) + if( !cmp( v, *(pCur->pValue)) ) { pNew->pNext = pCur; pNew->pPrev = pCur->pPrev; @@ -218,7 +221,7 @@ namespace Bu */ typedef struct iterator { - friend class List; + friend class List; private: Link *pLink; MyType &rList; @@ -357,7 +360,7 @@ namespace Bu */ typedef struct const_iterator { - friend class List; + friend class List; private: Link *pLink; const MyType &rList; @@ -584,6 +587,7 @@ namespace Bu linkalloc la; valuealloc va; int nSize; + cmpfunc cmp; }; } diff --git a/src/set.h b/src/set.h index 3ba7c9a..d6f7ae8 100644 --- a/src/set.h +++ b/src/set.h @@ -251,6 +251,7 @@ namespace Bu if( isFilled( j ) ) if( !isDeleted( j ) ) { + _erase( j ); onDelete(); } } diff --git a/src/util.h b/src/util.h index 977645c..25eb795 100644 --- a/src/util.h +++ b/src/util.h @@ -35,6 +35,46 @@ namespace Bu { return min( max( a, b ), c ); } + + // + // Basic comparison functors + // + template + struct __basicLTCmp + { + bool operator()( const item &a, const item &b ) + { + return a < b; + } + }; + + template + struct __basicGTCmp + { + bool operator()( const item &a, const item &b ) + { + return a > b; + } + }; + + template + struct __basicPtrLTCmp + { + bool operator()( const item &a, const item &b ) + { + return *a < *b; + } + }; + + template + struct __basicPtrGTCmp + { + bool operator()( const item &a, const item &b ) + { + return *a > *b; + } + }; + }; #endif -- cgit v1.2.3