From 525b50abe6b5a6e06c2b4ba327c9490de5277a5b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 21 Nov 2006 15:13:30 +0000 Subject: OK, everything that did work works, but now the HashProxy is as fast as insert, and has more options. Use [] all you want! --- src/hash.h | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/hash.h b/src/hash.h index 2dac257..c4f4b43 100644 --- a/src/hash.h +++ b/src/hash.h @@ -26,35 +26,43 @@ struct __calcNextTSize_fast template, typename valuealloc = std::allocator, typename challoc = std::allocator > class Hash; -template< typename key, typename value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > +template< typename key, typename _value, typename sizecalc, typename keyalloc, typename valuealloc, typename challoc > struct HashProxy { - friend class Hash; + friend class Hash; private: - HashProxy( Hash &h, key *k, value *v, uint32_t hash ) : + HashProxy( Hash &h, key *k, uint32_t nPos, uint32_t hash ) : hsh( h ), pKey( k ), - pValue( v ), + nPos( nPos ), hash( hash ), bFilled( false ) { } - HashProxy( Hash &h, value *pValue ) : + HashProxy( Hash &h, _value *pValue ) : hsh( h ), pValue( pValue ), bFilled( true ) { } - Hash &hsh; + Hash &hsh; key *pKey; - value *pValue; + _value *pValue; bool bFilled; uint32_t hash; + uint32_t nPos; public: - operator value() + operator _value() + { + if( bFilled == false ) + throw "Nope, no data there"; + return *pValue; + } + + _value value() { if( bFilled == false ) throw "Nope, no data there"; @@ -66,15 +74,16 @@ public: return bFilled; } - value operator=( value nval ) + _value operator=( _value nval ) { if( bFilled ) { - hsh.va.destroy( KEEP GOING HERE - hsh.insert( tKey, nval ); + hsh.va.destroy( pValue ); + hsh.va.construct( pValue, nval ); } else { + hsh.fill( nPos, *pKey, nval, hash ); } return nval; @@ -84,7 +93,7 @@ public: template class Hash { - friend HashProxy; + friend struct HashProxy; public: Hash() : nCapacity( 11 ), @@ -379,9 +388,9 @@ private: void fill( uint32_t loc, key &k, value &v, uint32_t hash ) { bFilled[loc/32] |= (1<<(loc%32)); - va.construct( &aValues[nPos], v ); - ka.construct( &aKeys[nPos], k ); - aHashCodes[nPos] = hash; + va.construct( &aValues[loc], v ); + ka.construct( &aKeys[loc], k ); + aHashCodes[loc] = hash; nFilled++; } -- cgit v1.2.3