aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/heap.h36
-rw-r--r--src/list.h14
-rw-r--r--src/set.h1
-rw-r--r--src/util.h40
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
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 {
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 @@
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
14namespace Bu 15namespace 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
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
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 }
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
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