diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-07-20 17:30:48 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-07-20 17:30:48 +0000 |
commit | 86f24cc82a3d0297e80f7c24ad624d43ba097000 (patch) | |
tree | 47deb396dcf6b4bf765e106aff2ee406a0699fae /src/hashtable.cpp | |
parent | 1ebe2d47412625d2be6ffe05cf761761becf0088 (diff) | |
download | libbu++-86f24cc82a3d0297e80f7c24ad624d43ba097000.tar.gz libbu++-86f24cc82a3d0297e80f7c24ad624d43ba097000.tar.bz2 libbu++-86f24cc82a3d0297e80f7c24ad624d43ba097000.tar.xz libbu++-86f24cc82a3d0297e80f7c24ad624d43ba097000.zip |
Added the "getKey" function to the HashTable, allowing you to get at the
internal persistant IDs using a temporary id.
Diffstat (limited to 'src/hashtable.cpp')
-rw-r--r-- | src/hashtable.cpp | 45 |
1 files changed, 45 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 | ||
244 | const 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 | |||
244 | void *HashTable::getFirstItemPos() | 289 | void *HashTable::getFirstItemPos() |
245 | { | 290 | { |
246 | HashPos *pos = new HashPos; | 291 | HashPos *pos = new HashPos; |