From 3f064aa71f19725fa652fcd20fcf3816664fbaf2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 2 Mar 2007 19:40:02 +0000 Subject: Removed debugging from the Hash --- src/hash.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ src/http.cpp | 12 +++++------ src/sptr.h | 4 +++- 3 files changed, 68 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/hash.h b/src/hash.h index 10db03a..7f1ac65 100644 --- a/src/hash.h +++ b/src/hash.h @@ -25,10 +25,12 @@ bool __cmpHashKeys( T a, T b ); struct __calcNextTSize_fast { - uint32_t operator()( uint32_t nCapacity, uint32_t nFill, uint32_t nDeleted ) const - { - return nCapacity*2+1; - } + uint32_t operator()( uint32_t nCapacity, uint32_t nFill, uint32_t nDeleted ) const + { + if( nDeleted >= nCapacity/2 ) + return nCapacity; + return nCapacity*2+1; + } }; template, typename valuealloc = std::allocator, typename challoc = std::allocator > @@ -295,6 +297,18 @@ public: } } + struct iterator; + virtual void erase( struct iterator &i ) + { + if( this != &i.hsh ) + throw HashException("This iterator didn't come from this Hash."); + if( isFilled( i.nPos ) && !isDeleted( i.nPos ) ) + { + _erase( i.nPos ); + onDelete(); + } + } + virtual void clear() { for( uint32_t j = 0; j < nCapacity; j++ ) @@ -399,10 +413,29 @@ public: return !(*this == oth ); } + iterator operator=( const iterator &oth ) + { + if( &hsh != &oth.hsh ) + throw HashException( + "Cannot mix iterators from different hash objects."); + nPos = oth.nPos; + bFinished = oth.bFinished; + } + std::pair operator *() { return hsh.getAtPos( nPos ); } + + key &getKey() + { + return hsh.getKeyAtPos( nPos ); + } + + value &getValue() + { + return hsh.getValueAtPos( nPos ); + } }; iterator begin() @@ -436,6 +469,8 @@ protected: ka.construct( &aKeys[loc], k ); aHashCodes[loc] = hash; nFilled++; + //printf("Filled: %d, Deleted: %d, Capacity: %d\n", + // nFilled, nDeleted, nCapacity ); } virtual void _erase( uint32_t loc ) @@ -443,12 +478,25 @@ protected: bDeleted[loc/32] |= (1<<(loc%32)); va.destroy( &aValues[loc] ); ka.destroy( &aKeys[loc] ); + nDeleted++; + //printf("Filled: %d, Deleted: %d, Capacity: %d\n", + // nFilled, nDeleted, nCapacity ); } virtual std::pair getAtPos( uint32_t nPos ) { return std::pair(aKeys[nPos],aValues[nPos]); } + + virtual key &getKeyAtPos( uint32_t nPos ) + { + return aKeys[nPos]; + } + + virtual value &getValueAtPos( uint32_t nPos ) + { + return aValues[nPos]; + } virtual uint32_t getFirstPos( bool &bFinished ) { @@ -521,6 +569,10 @@ protected: void reHash( uint32_t nNewSize ) { + //printf("---REHASH---"); + //printf("Filled: %d, Deleted: %d, Capacity: %d\n", + // nFilled, nDeleted, nCapacity ); + // Save all the old data uint32_t nOldCapacity = nCapacity; uint32_t *bOldFilled = bFilled; @@ -543,12 +595,13 @@ protected: aKeys = ka.allocate( nCapacity ); aValues = va.allocate( nCapacity ); - nFilled = 0; + nDeleted = nFilled = 0; // Re-insert all of the old data (except deleted items) for( uint32_t j = 0; j < nOldCapacity; j++ ) { - if( (bOldFilled[j/32]&(1<<(j%32)))!=0 ) + if( (bOldFilled[j/32]&(1<<(j%32)))!=0 && + (bOldDeleted[j/32]&(1<<(j%32)))==0 ) { insert( aOldKeys[j], aOldValues[j] ); } diff --git a/src/http.cpp b/src/http.cpp index 19122c3..92bd89c 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -58,7 +58,7 @@ bool Http::parseRequest() else { setResponseStatus( statusHTTPVersionNotSupported ); - printf("Verson not supported.\n"); + //printf("Verson not supported.\n"); return true; } @@ -93,7 +93,7 @@ bool Http::parseRequest() nLen = pCon->scanInputFor(':'); if( nLen == -1 ) { - printf("No colon? what are you trying to pull?\n"); + //printf("No colon? what are you trying to pull?\n"); } else { @@ -111,10 +111,10 @@ bool Http::parseRequest() pValue->c_str() ); - printf("::%s = \"%s\"\n", - pName->c_str(), - pValue->c_str() - ); + //printf("::%s = \"%s\"\n", + // pName->c_str(), + // pValue->c_str() + // ); } } } diff --git a/src/sptr.h b/src/sptr.h index e72644d..c95dad8 100644 --- a/src/sptr.h +++ b/src/sptr.h @@ -23,7 +23,8 @@ public: pRefCnt( src.pRefCnt ), pData( src.pData ) { - (*pRefCnt) += 1; + if( pRefCnt ) + (*pRefCnt) += 1; } SPtr( T *pSrc ) : @@ -80,6 +81,7 @@ private: if( pRefCnt ) { (*pRefCnt) -= 1; + printf("Decrementing ref-count to %d\n", *pRefCnt ); if( (*pRefCnt) == 0 ) { delete pRefCnt; -- cgit v1.2.3