64 #ifdef NO_STD_CHEADERS 148 register unsigned int power = 0, i = 31;
150 if (initialSlots < 8) initialSlots = 8;
154 if (initialSlots & (1 << i))
156 if (i < 20) power = (1 << (i + 2)) - 1;
157 else power = (1 << i) - 1;
187 cerr <<
"\tHashTable::HashTable" <<
"\n" 188 <<
"\t\tnumSlots: " << numSlots <<
"\n" 189 <<
"\t\tnextSlot: " <<
nextSlot <<
"\n" 190 <<
"\t\tentrySize: " <<
entrySize <<
"\n" 191 <<
"\t\tentries: " <<
entries <<
"\n" 192 <<
"\t\tindexSetSize: " << indexSetSize <<
"\n" 193 <<
"\t\tindexSet: " <<
indexSet <<
"\n" 209 char* cEntries = (
char*)
entries;
210 for (
unsigned int entryIndex = 0; entryIndex <
nextSlot; entryIndex++)
237 DIAG_Die(
"Should not call HashTable::operator=()!");
245 return (
id == rhsTab.
id);
256 char* cEntries = (
char*)
entries;
261 cerr <<
"HashTable::AddEntry: using index " << index
273 if (AddEntryCallback !=
NULL)
275 va_start (argList, AddEntryCallback);
302 char* cEntries = (
char*)
entries;
307 cerr <<
"\tHashTable::DeleteEntry: entry not found." 314 cerr <<
"\tHashTable::DeleteEntry: deleting entry for index " << index
321 cerr <<
"\tHashTable::DeleteEntry: moving last entry to empty slot." 330 int tempIndexSetValue = 0;
335 &cEntries[entrySize *
indexSet[toIndex]],
337 memcpy (&cEntries[entrySize *
indexSet[toIndex]],
338 &cEntries[entrySize *
indexSet[fromIndex]],
340 memcpy (&cEntries[entrySize *
indexSet[fromIndex]],
344 tempIndexSetValue =
indexSet[toIndex];
346 indexSet[fromIndex] = tempIndexSetValue;
354 if (DeleteEntryCallback !=
NULL)
356 va_start (argList, DeleteEntryCallback);
357 DeleteEntryCallback ((
void*)&cEntries[last *
entrySize], argList);
372 if (DeleteEntryCallback !=
NULL)
374 va_start (argList, DeleteEntryCallback);
375 DeleteEntryCallback ((
void*)&cEntries[0], argList);
401 char* cEntries = (
char*)
entries;
404 cerr <<
"\tHashTable::QueryEntry (" << entry <<
")." 477 cout <<
"HashTable: " <<
this <<
" (id: " <<
id <<
")" << endl;
482 for (i =0; stp.
Current(); stp++, i++) {
484 <<
" : ptr " << stp.
Current() << endl;
487 cout <<
" NOT CREATED" << endl;
499 register unsigned int power = 0, i = 31;
501 if (initialSlots < 8) initialSlots = 8;
505 if (initialSlots & (1 << i))
507 if (i < 20) power = (1 << (i + 2)) - 1;
508 else power = (1 << i) - 1;
526 cerr <<
"\tHashTable::HashTable\n" 527 <<
"\t\tnumSlots: " << numSlots <<
"\n" 528 <<
"\t\tnextSlot: " <<
nextSlot <<
"\n" 529 <<
"\t\tentrySize: " <<
entrySize <<
"\n" 530 <<
"\t\tentries: " <<
entries <<
"\n" 531 <<
"\t\tindexSetSize: " << indexSetSize <<
"\n" 532 <<
"\t\tindexSet: " <<
indexSet <<
"\n" 576 int initialIndex, currentIndex;
579 char* cEntries = (
char*)
entries;
585 cerr <<
"\tHashTable::QueryIndexSet(" << entry <<
", " << addingEntry <<
")." 596 return firstDeletedIndex;
606 if (firstDeletedIndex == currentIndex)
613 firstDeletedIndex = currentIndex;
627 cerr <<
"\tRehashing the Index" 639 (currentIndex == initialIndex))
645 else if (currentIndex == initialIndex)
697 register unsigned int i, initialIndex, finalIndex, size;
698 char* cEntries = (
char*)
entries;
711 cerr <<
"\tHashTable::OverflowIndexSet: old size: " <<
indexSetSize 712 <<
", new size: " << size
731 cerr <<
"\tRehashing for OverflowIndexSet()" 735 finalIndex =
RehashFunct (finalIndex, indexSetSize);
736 DIAG_Assert(finalIndex != initialIndex,
"shouldn't wrap table w/o allocating an index");
749 int newSlots, newSize, oldSize;
754 else newSlots = (int) (1.33 *
numSlots);
759 ptr =
new char [newSize];
760 memset (ptr, 0, newSize);
761 memcpy (ptr,
entries, oldSize);
767 cerr <<
"\tHashTable::OverflowEntries: old slots: " <<
numSlots 768 <<
", new slots: " << newSlots
781 DIAG_Die(
"Failure to call Create() before using the HashTable");
788 DIAG_Die(
"Failure to call Destroy() before deleting the HashTable");
797 return (
uint)((int)value % size);
805 return (
uint)((oldHashValue + 16) % size);
812 return (
int)((int)value1 != (
int)value2);
820 char* cEntry = (
char*) entry;
825 c = (
unsigned char) *cEntry++;
826 result += (c & 0x3f);
827 result = (result << 5) + (result >> 27);
830 return (result % size);
838 return (
uint)((oldHashValue + 16) % size);
845 char* cEntry1 = (
char*)entry1;
846 char* cEntry2 = (
char*)entry2;
848 return strcmp (cEntry1, cEntry2);
858 DIAG_Die(
"Failure to specify HashFunct function.");
869 newHashValue = (oldHashValue + 16) % size;
872 cerr <<
"\tHashTable::DefaultRehashFunct\t" << oldHashValue
873 <<
" ---> " << newHashValue
885 DIAG_Die(
"Failure to specify EntryCompare function.");
894 cerr <<
"\tHashTable::DefaultEntryCleanup\t" << (int)entry
925 currentEntryNumber--;
937 if (currentEntryNumber >= 0 &&
942 return (
void*)&cEntries[currentEntryNumber * ((
HashTable*)hashTable)->entrySize];
954 currentEntryNumber = ((
HashTable*)hashTable)->nextSlot - 1;
void FailureToDestroyError() const
EntryCleanupFunctPtr EntryCleanupCallback
int IntegerEntryCompare(const int value1, const int value2)
int(* EntryCompareFunctPtr)(const void *, const void *)
virtual uint RehashFunct(const uint oldHashValue, const uint size)
HashTable & operator=(const HashTable &rhs)
static void DefaultEntryCleanup(void *entry)
static const int INVALID_INDEX
void Create(const uint entrySize, uint initialSize, HashFunctFunctPtr const HashFunctCallback, RehashFunctFunctPtr const RehashFunctCallback, EntryCompareFunctPtr const EntryCompareCallback, EntryCleanupFunctPtr const EntryCleanupCallback)
EntryCompareFunctPtr EntryCompareCallback
static uint DefaultRehashFunct(const uint oldHashValue, const uint size)
void(* DeleteEntryFunctPtr)(void *, va_list)
uint StringHashFunct(const void *entry, const uint size)
uint(* HashFunctFunctPtr)(const void *, const uint)
virtual void EntryCleanup(void *entry)
uint IntegerHashFunct(const int value, const uint size)
uint(* RehashFunctFunctPtr)(const uint, const uint)
static int DefaultEntryCompare(const void *entry1, const void *entry2)
RehashFunctFunctPtr RehashFunctCallback
bool operator==(HashTable &rhsTab)
static uint DefaultHashFunct(const void *entry, const uint size)
uint IntegerRehashHashFunct(const uint oldHashValue, const uint size)
static const int ENTRY_DEPTH_FOR_HASHING
int QueryIndexSet(const void *entry, const bool expand) const
virtual uint HashFunct(const void *entry, const uint size)
void(* AddEntryFunctPtr)(void *, void *, va_list)
virtual ~HashTableIterator()
void DeleteEntry(void *entry, DeleteEntryFunctPtr const DeleteEntryCallback=0,...)
int GetEntryIndex(const void *entry) const
void AddEntry(void *entry, AddEntryFunctPtr const AddEntryCallback=0,...)
int StringEntryCompare(const void *entry1, const void *entry2)
static const int LOOKING_FOR_AN_INDEX
void FailureToCreateError() const
uint NumberOfEntries() const
HashFunctFunctPtr HashFunctCallback
void(* EntryCleanupFunctPtr)(void *)
static const int FIRST_SLOT
uint StringRehashFunct(const uint oldHashValue, const uint size)
void * QueryEntry(const void *entry) const
virtual int EntryCompare(const void *entry1, const void *entry2)
void * GetEntryByIndex(const uint index) const
HashTableIterator(const HashTable *theHashTable)