aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/hashtable.cpp45
-rw-r--r--src/hashtable.h2
2 files changed, 47 insertions, 0 deletions
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 )
241 return NULL; 241 return NULL;
242} 242}
243 243
244const void *HashTable::getKey( const void *id, unsigned long int nSkip )
245{
246 unsigned long int nPos = hFunc->hash( id )%nTableSize;
247
248 for( unsigned long int j=0; j < 32; nPos = (nPos+(1<<j))%nTableSize, j++ )
249 {
250 if( !isFilled( nPos ) ) return NULL;
251 if( hFunc->cmpIDs( id, aTable[nPos].id ) &&
252 aTable[nPos].bDeleted == false )
253 {
254 if( nSkip == 0 )
255 {
256 return aTable[nPos].id;
257 }
258 else
259 {
260 nSkip--;
261 }
262 }
263 }
264
265 if( bAllowDupes )
266 {
267 int nOldPos = nPos;
268 for( nPos++; nPos != nOldPos; nPos=(nPos+1)%nTableSize )
269 {
270 if( !isFilled( nPos ) ) return NULL;
271 if( hFunc->cmpIDs( id, aTable[nPos].id ) &&
272 aTable[nPos].bDeleted == false )
273 {
274 if( nSkip == 0 )
275 {
276 return aTable[nPos].id;
277 }
278 else
279 {
280 nSkip--;
281 }
282 }
283 }
284 }
285
286 return NULL;
287}
288
244void *HashTable::getFirstItemPos() 289void *HashTable::getFirstItemPos()
245{ 290{
246 HashPos *pos = new HashPos; 291 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:
90 *@returns A pointer to the data stored at the given id. 90 *@returns A pointer to the data stored at the given id.
91 */ 91 */
92 const void *get( const void *id, unsigned long int nSkip=0 ); 92 const void *get( const void *id, unsigned long int nSkip=0 );
93
94 const void *getKey( const void *id, unsigned long int nSkip=0 );
93 95
94 /** Gets the total capacity of the hashtable. This is actually the number 96 /** Gets the total capacity of the hashtable. This is actually the number
95 * of total positions available inside the hashtable at the moment. This 97 * of total positions available inside the hashtable at the moment. This