From 86f24cc82a3d0297e80f7c24ad624d43ba097000 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 20 Jul 2006 17:30:48 +0000 Subject: Added the "getKey" function to the HashTable, allowing you to get at the internal persistant IDs using a temporary id. --- src/hashtable.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/hashtable.h | 2 ++ 2 files changed, 47 insertions(+) (limited to 'src') diff --git a/src/hashtable.cpp b/src/hashtable.cpp index 8a31f57..ea13236 100644 --- a/src/hashtable.cpp +++ b/src/hashtable.cpp @@ -241,6 +241,51 @@ const void *HashTable::get( const void *id, unsigned long int nSkip ) return NULL; } +const void *HashTable::getKey( const void *id, unsigned long int nSkip ) +{ + unsigned long int nPos = hFunc->hash( id )%nTableSize; + + for( unsigned long int j=0; j < 32; nPos = (nPos+(1<cmpIDs( id, aTable[nPos].id ) && + aTable[nPos].bDeleted == false ) + { + if( nSkip == 0 ) + { + return aTable[nPos].id; + } + else + { + nSkip--; + } + } + } + + if( bAllowDupes ) + { + int nOldPos = nPos; + for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize ) + { + if( !isFilled( nPos ) ) return NULL; + if( hFunc->cmpIDs( id, aTable[nPos].id ) && + aTable[nPos].bDeleted == false ) + { + if( nSkip == 0 ) + { + return aTable[nPos].id; + } + else + { + nSkip--; + } + } + } + } + + return NULL; +} + void *HashTable::getFirstItemPos() { HashPos *pos = new HashPos; diff --git a/src/hashtable.h b/src/hashtable.h index 170793f..f319cb0 100644 --- a/src/hashtable.h +++ b/src/hashtable.h @@ -90,6 +90,8 @@ public: *@returns A pointer to the data stored at the given id. */ const void *get( const void *id, unsigned long int nSkip=0 ); + + const void *getKey( const void *id, unsigned long int nSkip=0 ); /** Gets the total capacity of the hashtable. This is actually the number * of total positions available inside the hashtable at the moment. This -- cgit v1.2.3