diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-11-21 14:46:50 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-11-21 14:46:50 +0000 |
commit | bea5b488189383ddcaafbdc427555226003d2b00 (patch) | |
tree | 48515a1c9ad44a21d1a5588142c0b52f7dc73cf9 | |
parent | 4b8bad3d711f39db84f094edf83c5496a3f02cd6 (diff) | |
download | libbu++-bea5b488189383ddcaafbdc427555226003d2b00.tar.gz libbu++-bea5b488189383ddcaafbdc427555226003d2b00.tar.bz2 libbu++-bea5b488189383ddcaafbdc427555226003d2b00.tar.xz libbu++-bea5b488189383ddcaafbdc427555226003d2b00.zip |
Many good updates, but I'm gonna' switch computers, it'll build again in a sec.
-rw-r--r-- | src/hash.h | 63 |
1 files changed, 39 insertions, 24 deletions
@@ -31,45 +31,60 @@ struct HashProxy | |||
31 | { | 31 | { |
32 | friend class Hash<key, value, sizecalc, keyalloc, valuealloc, challoc>; | 32 | friend class Hash<key, value, sizecalc, keyalloc, valuealloc, challoc>; |
33 | private: | 33 | private: |
34 | HashProxy( Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &h, key k, value v ) : | 34 | HashProxy( Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &h, key *k, value *v, uint32_t hash ) : |
35 | hsh( h ), | 35 | hsh( h ), |
36 | tKey( k ), | 36 | pKey( k ), |
37 | tValue( v ), | 37 | pValue( v ), |
38 | bFilled( true ) | 38 | hash( hash ), |
39 | bFilled( false ) | ||
39 | { | 40 | { |
40 | } | 41 | } |
41 | 42 | ||
42 | HashProxy( Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &h, key k ) : | 43 | HashProxy( Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &h, value *pValue ) : |
43 | hsh( h ), | 44 | hsh( h ), |
44 | tKey( k ), | 45 | pValue( pValue ), |
45 | bFilled( false ) | 46 | bFilled( true ) |
46 | { | 47 | { |
47 | } | 48 | } |
48 | 49 | ||
49 | Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &hsh; | 50 | Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &hsh; |
50 | key tKey; | 51 | key *pKey; |
51 | value tValue; | 52 | value *pValue; |
52 | bool bFilled; | 53 | bool bFilled; |
54 | uint32_t hash; | ||
53 | 55 | ||
54 | public: | 56 | public: |
55 | operator value() | 57 | operator value() |
56 | { | 58 | { |
57 | if( bFilled == false ) | 59 | if( bFilled == false ) |
58 | throw "Nope, no data there"; | 60 | throw "Nope, no data there"; |
59 | return tValue; | 61 | return *pValue; |
62 | } | ||
63 | |||
64 | bool isFilled() | ||
65 | { | ||
66 | return bFilled; | ||
60 | } | 67 | } |
61 | 68 | ||
62 | value operator=( value nval ) | 69 | value operator=( value nval ) |
63 | { | 70 | { |
64 | hsh.insert( tKey, nval ); | 71 | if( bFilled ) |
72 | { | ||
73 | hsh.va.destroy( KEEP GOING HERE | ||
74 | hsh.insert( tKey, nval ); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | } | ||
79 | |||
65 | return nval; | 80 | return nval; |
66 | } | 81 | } |
67 | |||
68 | }; | 82 | }; |
69 | 83 | ||
70 | template<typename key, typename value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > | 84 | template<typename key, typename value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > |
71 | class Hash | 85 | class Hash |
72 | { | 86 | { |
87 | friend HashProxy; | ||
73 | public: | 88 | public: |
74 | Hash() : | 89 | Hash() : |
75 | nCapacity( 11 ), | 90 | nCapacity( 11 ), |
@@ -143,11 +158,11 @@ public: | |||
143 | 158 | ||
144 | if( bFill ) | 159 | if( bFill ) |
145 | { | 160 | { |
146 | return HashProxy<key, value, sizecalc, keyalloc, valuealloc, challoc>( *this, aKeys[nPos], aValues[nPos] ); | 161 | return HashProxy<key, value, sizecalc, keyalloc, valuealloc, challoc>( *this, &aValues[nPos] ); |
147 | } | 162 | } |
148 | else | 163 | else |
149 | { | 164 | { |
150 | return HashProxy<key, value, sizecalc, keyalloc, valuealloc, challoc>( *this, k ); | 165 | return HashProxy<key, value, sizecalc, keyalloc, valuealloc, challoc>( *this, &k, nPos, hash ); |
151 | } | 166 | } |
152 | } | 167 | } |
153 | 168 | ||
@@ -164,11 +179,7 @@ public: | |||
164 | } | 179 | } |
165 | else | 180 | else |
166 | { | 181 | { |
167 | va.construct( &aValues[nPos], v ); | 182 | fill( nPos, k, v, hash ); |
168 | ka.construct( &aKeys[nPos], k ); | ||
169 | fill( nPos ); | ||
170 | aHashCodes[nPos] = hash; | ||
171 | nFilled++; | ||
172 | } | 183 | } |
173 | } | 184 | } |
174 | 185 | ||
@@ -276,11 +287,6 @@ public: | |||
276 | ca.deallocate( aOldHashCodes, nOldCapacity ); | 287 | ca.deallocate( aOldHashCodes, nOldCapacity ); |
277 | } | 288 | } |
278 | 289 | ||
279 | void fill( uint32_t loc ) | ||
280 | { | ||
281 | bFilled[loc/32] |= (1<<(loc%32)); | ||
282 | } | ||
283 | |||
284 | bool isFilled( uint32_t loc ) | 290 | bool isFilled( uint32_t loc ) |
285 | { | 291 | { |
286 | return (bFilled[loc/32]&(1<<(loc%32)))!=0; | 292 | return (bFilled[loc/32]&(1<<(loc%32)))!=0; |
@@ -370,6 +376,15 @@ public: | |||
370 | } | 376 | } |
371 | 377 | ||
372 | private: | 378 | private: |
379 | void fill( uint32_t loc, key &k, value &v, uint32_t hash ) | ||
380 | { | ||
381 | bFilled[loc/32] |= (1<<(loc%32)); | ||
382 | va.construct( &aValues[nPos], v ); | ||
383 | ka.construct( &aKeys[nPos], k ); | ||
384 | aHashCodes[nPos] = hash; | ||
385 | nFilled++; | ||
386 | } | ||
387 | |||
373 | std::pair<key,value> getAtPos( uint32_t nPos ) | 388 | std::pair<key,value> getAtPos( uint32_t nPos ) |
374 | { | 389 | { |
375 | return std::pair<key,value>(aKeys[nPos],aValues[nPos]); | 390 | return std::pair<key,value>(aKeys[nPos],aValues[nPos]); |