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 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/hashtable.cpp') 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; -- cgit v1.2.3