From f559679714fbcb3774409122285ae785b351ade7 Mon Sep 17 00:00:00 2001 From: sc Date: Fri, 22 Dec 2000 09:30:36 +0000 Subject: Added method RemoveOne --- utils/HashTable.cc | 41 +++++++++++++++++++++++++++++++++++------ utils/HashTable.h | 16 ++++++++++------ 2 files changed, 45 insertions(+), 12 deletions(-) (limited to 'utils') 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 @@ -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 diff --git a/utils/HashTable.h b/utils/HashTable.h index 6586efe..7fb2e84 100644 --- a/utils/HashTable.h +++ b/utils/HashTable.h @@ -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-1997 + * 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$ + * */ #ifndef HashTable_H_ @@ -91,6 +91,7 @@ static unsigned int HashPtr (const void*, int); IvlHashCell* Add (const void*, int* = 0); IvlHashCell* Get (const void*); IvlHashItem* Remove (const void*, int* = 0); + IvlHashItem* RemoveOne (); void Clear (); void Resize (int); inline int GetSize () const { return Size; } @@ -178,6 +179,7 @@ inline ~IvlHashTableOf () {} inline IvlHashCellOf* Add (const void* key, int* found = 0) { return (IvlHashCellOf*) IvlHashTable::Add (key, found); } inline IvlHashCellOf* Get (const void* key) { return (IvlHashCellOf*) IvlHashTable::Get (key); } inline ITEM* Remove (const void* key, int* found = 0) { return (ITEM*) IvlHashTable::Remove (key, found); } +inline ITEM* RemoveOne () { return (ITEM*) IvlHashTable::RemoveOne (); } inline IvlHashCellRefOf operator [] (const void* key) const { return IvlHashCellRefOf (*this, key); } }; @@ -188,6 +190,7 @@ inline ~IvlDictionnaryOf () {} inline IvlHashCellOf* Add (const void* key, int* found = 0) { return (IvlHashCellOf*) IvlDictionnary::Add (key, found); } inline IvlHashCellOf* Get (const void* key) { return (IvlHashCellOf*) IvlDictionnary::Get (key); } inline ITEM* Remove (const void* key, int* found = 0) { return (ITEM*) IvlDictionnary::Remove (key, found); } +inline ITEM* RemoveOne () { return (ITEM*) IvlDictionnary::RemoveOne (); } inline operator const IvlHashTableOf& () const { return *(const IvlHashTableOf*) this; } inline IvlHashCellRefOf operator [] (const char* key) const { return IvlHashCellRefOf (*(const IvlHashTableOf*)this, key); } }; @@ -199,6 +202,7 @@ inline ~IvlHashedArrayOf () {} inline IvlHashCellOf* Add (int key, int* found = 0) { return (IvlHashCellOf*) IvlHashTable::Add ((void*)key, found); } inline IvlHashCellOf* Get (int key) { return (IvlHashCellOf*) IvlHashTable::Get ((void*)key); } inline ITEM* Remove (int key, int* found = 0) { return (ITEM*) IvlHashTable::Remove ((void*) key, found); } +inline ITEM* RemoveOne () { return (ITEM*) IvlHashTable::RemoveOne (); } inline operator const IvlHashTableOf& () const { return *(const IvlHashTableOf*) this; } inline IvlHashCellRefOf operator [] (int key) const { return IvlHashCellRefOf (*(const IvlHashTableOf*)this, (void*)key); } }; -- cgit v1.1