summaryrefslogtreecommitdiff
path: root/utils/HashTable.cc
diff options
context:
space:
mode:
authorsc2000-12-22 09:30:36 +0000
committersc2000-12-22 09:30:36 +0000
commitf559679714fbcb3774409122285ae785b351ade7 (patch)
tree0e687b725c72505f6cef7ec22f28e56b07957d43 /utils/HashTable.cc
parent97487c4585cbf2049c2b4a5ad86c8e15f829975d (diff)
downloadivy-league-f559679714fbcb3774409122285ae785b351ade7.zip
ivy-league-f559679714fbcb3774409122285ae785b351ade7.tar.gz
ivy-league-f559679714fbcb3774409122285ae785b351ade7.tar.bz2
ivy-league-f559679714fbcb3774409122285ae785b351ade7.tar.xz
Added method RemoveOne
Diffstat (limited to 'utils/HashTable.cc')
-rw-r--r--utils/HashTable.cc41
1 files changed, 35 insertions, 6 deletions
diff --git a/utils/HashTable.cc b/utils/HashTable.cc
index 59ac76d..4bedbfe 100644
--- a/utils/HashTable.cc
+++ b/utils/HashTable.cc
@@ -1,17 +1,17 @@
/*
- * CENA C++ Utilities
+ * Ivy League
*
- * by Stephane Chatty
+ * plain and generic hash tables and dictionnaries
+ * (Original C version by Michel Beaudouin-Lafon)
*
- * Copyright 1991-1996
+ * Copyright 1991-2000
* Laboratoire de Recherche en Informatique (LRI)
* Centre d'Etudes de la Navigation Aerienne (CENA)
*
- * plain and generic hash tables and dictionnaries
- * (Original C version by Michel Beaudouin-Lafon)
+ * by Stephane Chatty
*
* $Id$
- * $CurLog$
+ *
*/
#include <string.h>
@@ -193,6 +193,35 @@ IvlHashTable :: Clear ()
}
}
+/*?
+Remove one item from the hash table. The key is destroyed if a destruction function was provided.
+?*/
+IvlHashItem*
+IvlHashTable :: RemoveOne ()
+{
+ int s = Size;
+ IvlHashCell** entry = Table;
+
+ /* try each slot of the array in turn ... */
+ for ( ; s--; ++entry ) {
+ IvlHashCell* h = *entry;
+ /* ... until we find one with items, */
+ if (!h)
+ continue;
+ /* then pick the first one, delete it...*/
+ *entry = h->Next;
+ IvlHashItem* info = h->Info;
+ if (Delete)
+ (*Delete) (h->Key);
+ delete h;
+ /* ... and return the item it holds.*/
+ return info;
+ }
+
+ /* if all slots are empty, return 0 */
+ return 0;
+}
+
/*?hidden?*/
IvlHashCell**
IvlHashTable :: HashKey (const void* key) const