From bea5b488189383ddcaafbdc427555226003d2b00 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 21 Nov 2006 14:46:50 +0000 Subject: Many good updates, but I'm gonna' switch computers, it'll build again in a sec. --- src/hash.h | 63 ++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 24 deletions(-) (limited to 'src/hash.h') diff --git a/src/hash.h b/src/hash.h index b8ced99..2dac257 100644 --- a/src/hash.h +++ b/src/hash.h @@ -31,45 +31,60 @@ struct HashProxy { friend class Hash; private: - HashProxy( Hash &h, key k, value v ) : + HashProxy( Hash &h, key *k, value *v, uint32_t hash ) : hsh( h ), - tKey( k ), - tValue( v ), - bFilled( true ) + pKey( k ), + pValue( v ), + hash( hash ), + bFilled( false ) { } - HashProxy( Hash &h, key k ) : + HashProxy( Hash &h, value *pValue ) : hsh( h ), - tKey( k ), - bFilled( false ) + pValue( pValue ), + bFilled( true ) { } Hash &hsh; - key tKey; - value tValue; + key *pKey; + value *pValue; bool bFilled; + uint32_t hash; public: operator value() { if( bFilled == false ) throw "Nope, no data there"; - return tValue; + return *pValue; + } + + bool isFilled() + { + return bFilled; } value operator=( value nval ) { - hsh.insert( tKey, nval ); + if( bFilled ) + { + hsh.va.destroy( KEEP GOING HERE + hsh.insert( tKey, nval ); + } + else + { + } + return nval; } - }; template class Hash { + friend HashProxy; public: Hash() : nCapacity( 11 ), @@ -143,11 +158,11 @@ public: if( bFill ) { - return HashProxy( *this, aKeys[nPos], aValues[nPos] ); + return HashProxy( *this, &aValues[nPos] ); } else { - return HashProxy( *this, k ); + return HashProxy( *this, &k, nPos, hash ); } } @@ -164,11 +179,7 @@ public: } else { - va.construct( &aValues[nPos], v ); - ka.construct( &aKeys[nPos], k ); - fill( nPos ); - aHashCodes[nPos] = hash; - nFilled++; + fill( nPos, k, v, hash ); } } @@ -276,11 +287,6 @@ public: ca.deallocate( aOldHashCodes, nOldCapacity ); } - void fill( uint32_t loc ) - { - bFilled[loc/32] |= (1<<(loc%32)); - } - bool isFilled( uint32_t loc ) { return (bFilled[loc/32]&(1<<(loc%32)))!=0; @@ -370,6 +376,15 @@ public: } 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; + nFilled++; + } + std::pair getAtPos( uint32_t nPos ) { return std::pair(aKeys[nPos],aValues[nPos]); -- cgit v1.2.3