diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-11-21 15:13:30 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-11-21 15:13:30 +0000 |
commit | 525b50abe6b5a6e06c2b4ba327c9490de5277a5b (patch) | |
tree | 682f8ac5f55bcdce83b0c8baf17ec3f6a4226835 /src | |
parent | bea5b488189383ddcaafbdc427555226003d2b00 (diff) | |
download | libbu++-525b50abe6b5a6e06c2b4ba327c9490de5277a5b.tar.gz libbu++-525b50abe6b5a6e06c2b4ba327c9490de5277a5b.tar.bz2 libbu++-525b50abe6b5a6e06c2b4ba327c9490de5277a5b.tar.xz libbu++-525b50abe6b5a6e06c2b4ba327c9490de5277a5b.zip |
OK, everything that did work works, but now the HashProxy is as fast as insert,
and has more options. Use [] all you want!
Diffstat (limited to '')
-rw-r--r-- | src/hash.h | 39 |
1 files changed, 24 insertions, 15 deletions
@@ -26,35 +26,43 @@ struct __calcNextTSize_fast | |||
26 | template<typename key, typename value, typename sizecalc = __calcNextTSize_fast, typename keyalloc = std::allocator<key>, typename valuealloc = std::allocator<value>, typename challoc = std::allocator<uint32_t> > | 26 | template<typename key, typename value, typename sizecalc = __calcNextTSize_fast, typename keyalloc = std::allocator<key>, typename valuealloc = std::allocator<value>, typename challoc = std::allocator<uint32_t> > |
27 | class Hash; | 27 | class Hash; |
28 | 28 | ||
29 | template< typename key, typename value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > | 29 | template< typename key, typename _value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > |
30 | struct HashProxy | 30 | 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, uint32_t hash ) : | 34 | HashProxy( Hash<key, _value, sizecalc, keyalloc, valuealloc, challoc> &h, key *k, uint32_t nPos, uint32_t hash ) : |
35 | hsh( h ), | 35 | hsh( h ), |
36 | pKey( k ), | 36 | pKey( k ), |
37 | pValue( v ), | 37 | nPos( nPos ), |
38 | hash( hash ), | 38 | hash( hash ), |
39 | bFilled( false ) | 39 | bFilled( false ) |
40 | { | 40 | { |
41 | } | 41 | } |
42 | 42 | ||
43 | HashProxy( Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &h, value *pValue ) : | 43 | HashProxy( Hash<key, _value, sizecalc, keyalloc, valuealloc, challoc> &h, _value *pValue ) : |
44 | hsh( h ), | 44 | hsh( h ), |
45 | pValue( pValue ), | 45 | pValue( pValue ), |
46 | bFilled( true ) | 46 | bFilled( true ) |
47 | { | 47 | { |
48 | } | 48 | } |
49 | 49 | ||
50 | Hash<key, value, sizecalc, keyalloc, valuealloc, challoc> &hsh; | 50 | Hash<key, _value, sizecalc, keyalloc, valuealloc, challoc> &hsh; |
51 | key *pKey; | 51 | key *pKey; |
52 | value *pValue; | 52 | _value *pValue; |
53 | bool bFilled; | 53 | bool bFilled; |
54 | uint32_t hash; | 54 | uint32_t hash; |
55 | uint32_t nPos; | ||
55 | 56 | ||
56 | public: | 57 | public: |
57 | operator value() | 58 | operator _value() |
59 | { | ||
60 | if( bFilled == false ) | ||
61 | throw "Nope, no data there"; | ||
62 | return *pValue; | ||
63 | } | ||
64 | |||
65 | _value value() | ||
58 | { | 66 | { |
59 | if( bFilled == false ) | 67 | if( bFilled == false ) |
60 | throw "Nope, no data there"; | 68 | throw "Nope, no data there"; |
@@ -66,15 +74,16 @@ public: | |||
66 | return bFilled; | 74 | return bFilled; |
67 | } | 75 | } |
68 | 76 | ||
69 | value operator=( value nval ) | 77 | _value operator=( _value nval ) |
70 | { | 78 | { |
71 | if( bFilled ) | 79 | if( bFilled ) |
72 | { | 80 | { |
73 | hsh.va.destroy( KEEP GOING HERE | 81 | hsh.va.destroy( pValue ); |
74 | hsh.insert( tKey, nval ); | 82 | hsh.va.construct( pValue, nval ); |
75 | } | 83 | } |
76 | else | 84 | else |
77 | { | 85 | { |
86 | hsh.fill( nPos, *pKey, nval, hash ); | ||
78 | } | 87 | } |
79 | 88 | ||
80 | return nval; | 89 | return nval; |
@@ -84,7 +93,7 @@ public: | |||
84 | template<typename key, typename value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > | 93 | template<typename key, typename value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > |
85 | class Hash | 94 | class Hash |
86 | { | 95 | { |
87 | friend HashProxy; | 96 | friend struct HashProxy<key, value, sizecalc, keyalloc, valuealloc, challoc>; |
88 | public: | 97 | public: |
89 | Hash() : | 98 | Hash() : |
90 | nCapacity( 11 ), | 99 | nCapacity( 11 ), |
@@ -379,9 +388,9 @@ private: | |||
379 | void fill( uint32_t loc, key &k, value &v, uint32_t hash ) | 388 | void fill( uint32_t loc, key &k, value &v, uint32_t hash ) |
380 | { | 389 | { |
381 | bFilled[loc/32] |= (1<<(loc%32)); | 390 | bFilled[loc/32] |= (1<<(loc%32)); |
382 | va.construct( &aValues[nPos], v ); | 391 | va.construct( &aValues[loc], v ); |
383 | ka.construct( &aKeys[nPos], k ); | 392 | ka.construct( &aKeys[loc], k ); |
384 | aHashCodes[nPos] = hash; | 393 | aHashCodes[loc] = hash; |
385 | nFilled++; | 394 | nFilled++; |
386 | } | 395 | } |
387 | 396 | ||