diff options
author | Mike Buland <eichlan@xagasoft.com> | 2008-02-20 08:07:31 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2008-02-20 08:07:31 +0000 |
commit | 3cea09281c9f809fc78de6f2e79f4117976f74e4 (patch) | |
tree | 7dccb751019a38bf93bffce61e5683d72a1fe842 | |
parent | a4c22303b1044eee5ccbf0766895a879a8f4810e (diff) | |
download | libbu++-3cea09281c9f809fc78de6f2e79f4117976f74e4.tar.gz libbu++-3cea09281c9f809fc78de6f2e79f4117976f74e4.tar.bz2 libbu++-3cea09281c9f809fc78de6f2e79f4117976f74e4.tar.xz libbu++-3cea09281c9f809fc78de6f2e79f4117976f74e4.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/heap.h | 36 | ||||
-rw-r--r-- | src/list.h | 14 | ||||
-rw-r--r-- | src/set.h | 1 | ||||
-rw-r--r-- | src/util.h | 40 |
4 files changed, 50 insertions, 41 deletions
@@ -19,42 +19,6 @@ namespace Bu | |||
19 | { | 19 | { |
20 | subExceptionDecl( HeapException ); | 20 | subExceptionDecl( HeapException ); |
21 | 21 | ||
22 | template<typename item> | ||
23 | struct __basicLTCmp | ||
24 | { | ||
25 | bool operator()( const item &a, const item &b ) | ||
26 | { | ||
27 | return a < b; | ||
28 | } | ||
29 | }; | ||
30 | |||
31 | template<typename item> | ||
32 | struct __basicGTCmp | ||
33 | { | ||
34 | bool operator()( const item &a, const item &b ) | ||
35 | { | ||
36 | return a > b; | ||
37 | } | ||
38 | }; | ||
39 | |||
40 | template<typename item> | ||
41 | struct __basicPtrLTCmp | ||
42 | { | ||
43 | bool operator()( const item &a, const item &b ) | ||
44 | { | ||
45 | return *a < *b; | ||
46 | } | ||
47 | }; | ||
48 | |||
49 | template<typename item> | ||
50 | struct __basicPtrGTCmp | ||
51 | { | ||
52 | bool operator()( const item &a, const item &b ) | ||
53 | { | ||
54 | return *a > *b; | ||
55 | } | ||
56 | }; | ||
57 | |||
58 | template<typename item, typename cmpfunc=__basicLTCmp<item>, typename itemalloc=std::allocator<item> > | 22 | template<typename item, typename cmpfunc=__basicLTCmp<item>, typename itemalloc=std::allocator<item> > |
59 | class Heap | 23 | class Heap |
60 | { | 24 | { |
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include <memory> | 11 | #include <memory> |
12 | #include "bu/exceptionbase.h" | 12 | #include "bu/exceptionbase.h" |
13 | #include "bu/util.h" | ||
13 | 14 | ||
14 | namespace Bu | 15 | namespace Bu |
15 | { | 16 | { |
@@ -34,12 +35,14 @@ namespace Bu | |||
34 | *@param linkalloc (typename) Memory Allocator for the list links. | 35 | *@param linkalloc (typename) Memory Allocator for the list links. |
35 | *@ingroup Containers | 36 | *@ingroup Containers |
36 | */ | 37 | */ |
37 | template<typename value, typename valuealloc=std::allocator<value>, typename linkalloc=std::allocator<struct ListLink<value> > > | 38 | template<typename value, typename cmpfunc=__basicGTCmp<value>, |
39 | typename valuealloc=std::allocator<value>, | ||
40 | typename linkalloc=std::allocator<struct ListLink<value> > > | ||
38 | class List | 41 | class List |
39 | { | 42 | { |
40 | private: | 43 | private: |
41 | typedef struct ListLink<value> Link; | 44 | typedef struct ListLink<value> Link; |
42 | typedef class List<value, valuealloc, linkalloc> MyType; | 45 | typedef class List<value, cmpfunc, valuealloc, linkalloc> MyType; |
43 | 46 | ||
44 | public: | 47 | public: |
45 | List() : | 48 | List() : |
@@ -189,7 +192,7 @@ namespace Bu | |||
189 | Link *pCur = pFirst; | 192 | Link *pCur = pFirst; |
190 | for(;;) | 193 | for(;;) |
191 | { | 194 | { |
192 | if( !(v > *(pCur->pValue)) ) | 195 | if( !cmp( v, *(pCur->pValue)) ) |
193 | { | 196 | { |
194 | pNew->pNext = pCur; | 197 | pNew->pNext = pCur; |
195 | pNew->pPrev = pCur->pPrev; | 198 | pNew->pPrev = pCur->pPrev; |
@@ -218,7 +221,7 @@ namespace Bu | |||
218 | */ | 221 | */ |
219 | typedef struct iterator | 222 | typedef struct iterator |
220 | { | 223 | { |
221 | friend class List<value, valuealloc, linkalloc>; | 224 | friend class List<value, cmpfunc, valuealloc, linkalloc>; |
222 | private: | 225 | private: |
223 | Link *pLink; | 226 | Link *pLink; |
224 | MyType &rList; | 227 | MyType &rList; |
@@ -357,7 +360,7 @@ namespace Bu | |||
357 | */ | 360 | */ |
358 | typedef struct const_iterator | 361 | typedef struct const_iterator |
359 | { | 362 | { |
360 | friend class List<value, valuealloc, linkalloc>; | 363 | friend class List<value, cmpfunc, valuealloc, linkalloc>; |
361 | private: | 364 | private: |
362 | Link *pLink; | 365 | Link *pLink; |
363 | const MyType &rList; | 366 | const MyType &rList; |
@@ -584,6 +587,7 @@ namespace Bu | |||
584 | linkalloc la; | 587 | linkalloc la; |
585 | valuealloc va; | 588 | valuealloc va; |
586 | int nSize; | 589 | int nSize; |
590 | cmpfunc cmp; | ||
587 | }; | 591 | }; |
588 | } | 592 | } |
589 | 593 | ||
@@ -251,6 +251,7 @@ namespace Bu | |||
251 | if( isFilled( j ) ) | 251 | if( isFilled( j ) ) |
252 | if( !isDeleted( j ) ) | 252 | if( !isDeleted( j ) ) |
253 | { | 253 | { |
254 | _erase( j ); | ||
254 | onDelete(); | 255 | onDelete(); |
255 | } | 256 | } |
256 | } | 257 | } |
@@ -35,6 +35,46 @@ namespace Bu | |||
35 | { | 35 | { |
36 | return min( max( a, b ), c ); | 36 | return min( max( a, b ), c ); |
37 | } | 37 | } |
38 | |||
39 | // | ||
40 | // Basic comparison functors | ||
41 | // | ||
42 | template<typename item> | ||
43 | struct __basicLTCmp | ||
44 | { | ||
45 | bool operator()( const item &a, const item &b ) | ||
46 | { | ||
47 | return a < b; | ||
48 | } | ||
49 | }; | ||
50 | |||
51 | template<typename item> | ||
52 | struct __basicGTCmp | ||
53 | { | ||
54 | bool operator()( const item &a, const item &b ) | ||
55 | { | ||
56 | return a > b; | ||
57 | } | ||
58 | }; | ||
59 | |||
60 | template<typename item> | ||
61 | struct __basicPtrLTCmp | ||
62 | { | ||
63 | bool operator()( const item &a, const item &b ) | ||
64 | { | ||
65 | return *a < *b; | ||
66 | } | ||
67 | }; | ||
68 | |||
69 | template<typename item> | ||
70 | struct __basicPtrGTCmp | ||
71 | { | ||
72 | bool operator()( const item &a, const item &b ) | ||
73 | { | ||
74 | return *a > *b; | ||
75 | } | ||
76 | }; | ||
77 | |||
38 | }; | 78 | }; |
39 | 79 | ||
40 | #endif | 80 | #endif |