diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
commit | ac517a2b7625e0aa0862679e961c6349f859ea3b (patch) | |
tree | e3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/old/ordhash.h | |
parent | f8d4301e9fa4f3709258505941e37fab2eadadc6 (diff) | |
parent | bd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff) | |
download | libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2 libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip |
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to 'src/old/ordhash.h')
-rw-r--r-- | src/old/ordhash.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/old/ordhash.h b/src/old/ordhash.h new file mode 100644 index 0000000..e946f95 --- /dev/null +++ b/src/old/ordhash.h | |||
@@ -0,0 +1,104 @@ | |||
1 | #ifndef ORD_HASH_H | ||
2 | #define ORD_HASH_H | ||
3 | |||
4 | #include "hash.h" | ||
5 | #include "tqsort.h" | ||
6 | |||
7 | template<typename key, typename value, typename cmpfnc, typename sizecalc = __calcNextTSize_fast, typename keyalloc = std::allocator<key>, typename valuealloc = std::allocator<value>, typename challoc = std::allocator<uint32_t> > | ||
8 | class OrdHash : public Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> | ||
9 | { | ||
10 | public: | ||
11 | OrdHash() : | ||
12 | bSorted( false ), | ||
13 | aData( NULL ) | ||
14 | { | ||
15 | } | ||
16 | |||
17 | virtual ~OrdHash() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | protected: | ||
22 | virtual void invalidate() | ||
23 | { | ||
24 | bSorted = false; | ||
25 | delete[] aData; | ||
26 | aData = NULL; | ||
27 | } | ||
28 | |||
29 | virtual void onInsert() | ||
30 | { | ||
31 | invalidate(); | ||
32 | } | ||
33 | |||
34 | virtual void onUpdate() | ||
35 | { | ||
36 | invalidate(); | ||
37 | } | ||
38 | |||
39 | virtual void onDelete() | ||
40 | { | ||
41 | invalidate(); | ||
42 | } | ||
43 | |||
44 | virtual void onReHash() | ||
45 | { | ||
46 | invalidate(); | ||
47 | } | ||
48 | |||
49 | virtual std::pair<key,value> getAtPos( uint32_t nPos ) | ||
50 | { | ||
51 | return Hash<key, value, sizecalc, keyalloc, valuealloc, challoc>::getAtPos( aData[nPos].nIndex ); | ||
52 | } | ||
53 | |||
54 | virtual void buildIndex() | ||
55 | { | ||
56 | aData = new struct ind[this->nFilled]; | ||
57 | uint32_t k = 0; | ||
58 | for( uint32_t j = 0; j < this->nCapacity; j++ ) | ||
59 | { | ||
60 | if( this->isFilled( j ) ) | ||
61 | { | ||
62 | if( !this->isDeleted( j ) ) | ||
63 | { | ||
64 | aData[k].pVal = &(this->aValues[j]); | ||
65 | aData[k].nIndex = j; | ||
66 | k++; | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | tqsort<typename OrdHash<key, value, cmpfnc, sizecalc, keyalloc, valuealloc, challoc>::ind, cmpfnc, value **>( aData, this->nFilled ); | ||
72 | |||
73 | bSorted = true; | ||
74 | } | ||
75 | |||
76 | virtual uint32_t getFirstPos( bool &bFinished ) | ||
77 | { | ||
78 | if( bSorted == false ) | ||
79 | buildIndex(); | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | virtual uint32_t getNextPos( uint32_t nPos, bool &bFinished ) | ||
85 | { | ||
86 | if( nPos+1 >= this->nFilled ) | ||
87 | { | ||
88 | bFinished = true; | ||
89 | return 0; | ||
90 | } | ||
91 | return ++nPos; | ||
92 | } | ||
93 | public: | ||
94 | typedef struct ind | ||
95 | { | ||
96 | value *pVal; | ||
97 | uint32_t nIndex; | ||
98 | } ind; | ||
99 | private: | ||
100 | bool bSorted; | ||
101 | ind *aData; | ||
102 | }; | ||
103 | |||
104 | #endif | ||