Bug fix: after reallocating the hash table, we have to re-insert each value

instead of copying table entries!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7396 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Vikram S. Adve 2003-07-29 20:01:01 +00:00
parent e6124d3b7c
commit b3b0414c87

View File

@ -1,26 +1,24 @@
/*===-- tracelib.c - Runtime routines for tracing ---------------*- C++ -*-===*\
//
// Runtime routines for supporting tracing of execution for code generated by
// LLVM.
//
//===----------------------------------------------------------------------===*/
/*===-- tracelib.c - Runtime routines for tracing ---------------*- C++ -*-===*
*
* Runtime routines for supporting tracing of execution for code generated by
* LLVM.
*
*===----------------------------------------------------------------------===*/
#include "tracelib.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef sun
#include <stdint.h>
#endif
#include "Support/DataTypes.h"
/*===---------------------------------------------------------------------=====
* HASH FUNCTIONS
*===---------------------------------------------------------------------===*/
/* use #defines until we have inlining */
typedef uint32_t Index; /* type of index/size for hash table */
typedef uint32_t Generic; /* type of values stored in table */
typedef uintptr_t Index; /* type of keys, size for hash table */
typedef uint32_t Generic; /* type of values stored in table */
/* Index IntegerHashFunc(const Generic value, const Index size) */
#define IntegerHashFunc(value, size) \
@ -38,7 +36,6 @@ typedef uint32_t Generic; /* type of values stored in table */
#define PointerRehashFunc(value, size) \
IntegerRehashFunc((Index) value, size)
/*===---------------------------------------------------------------------=====
* POINTER-TO-GENERIC HASH TABLE.
* These should be moved to a separate location: HashTable.[ch]
@ -71,6 +68,10 @@ extern void Insert(PtrValueHashTable* ptrTable, void* ptr, Generic value);
extern void Delete(PtrValueHashTable* ptrTable, void* ptr);
/* Returns NULL if the item is not found. */
/* void* LookupPtr(PtrValueHashTable* ptrTable, void* ptr) */
#define LookupPtr(ptrTable, ptr) \
LookupOrInsertPtr(ptrTable, ptr, FIND)
void
InitializeTable(PtrValueHashTable* ptrTable, Index newSize)
@ -98,11 +99,9 @@ ReallocTable(PtrValueHashTable* ptrTable, Index newSize)
return;
#ifndef NDEBUG
printf("\n***\n*** WARNING: REALLOCATING SPACE FOR POINTER HASH TABLE.\n");
printf("*** oldSize = %d, oldCapacity = %d\n***\n\n",
ptrTable->size, ptrTable->capacity);
printf("*** NEW SEQUENCE NUMBER FOR A POINTER WILL PROBABLY NOT MATCH ");
printf(" THE OLD ONE!\n***\n\n");
printf("\n***\n*** REALLOCATING SPACE FOR POINTER HASH TABLE.\n");
printf("*** oldSize = %ld, oldCapacity = %ld\n***\n\n",
(long) ptrTable->size, (long) ptrTable->capacity);
#endif
unsigned int i;
@ -113,20 +112,18 @@ ReallocTable(PtrValueHashTable* ptrTable, Index newSize)
/* allocate the new storage and flags and re-insert the old entries */
InitializeTable(ptrTable, newSize);
memcpy(ptrTable->table, oldTable,
oldCapacity * sizeof(PtrValueHashEntry));
memcpy(ptrTable->fullEmptyFlags, oldFlags,
oldCapacity * sizeof(FULLEMPTY));
ptrTable->size = oldSize;
for (i=0; i < oldCapacity; ++i)
if (oldFlags[i] == FULL)
Insert(ptrTable, oldTable[i].key, oldTable[i].value);
assert(ptrTable->size == oldSize && "Incorrect number of entries copied?");
#ifndef NDEBUG
for (i=0; i < oldCapacity; ++i) {
assert(ptrTable->fullEmptyFlags[i] == oldFlags[i]);
assert(ptrTable->table[i].key == oldTable[i].key);
assert(ptrTable->table[i].value == oldTable[i].value);
}
for (i=0; i < oldCapacity; ++i)
if (! oldFlags[i])
assert(LookupPtr(ptrTable, oldTable[i].key) == oldTable[i].value);
#endif
free(oldTable);
free(oldFlags);
}
@ -216,11 +213,6 @@ LookupOrInsertPtr(PtrValueHashTable* ptrTable, void* ptr, ACTION action)
return (Generic) NULL;
}
/* Returns NULL if the item is not found. */
/* void* LookupPtr(PtrValueHashTable* ptrTable, void* ptr) */
#define LookupPtr(ptrTable, ptr) \
LookupOrInsertPtr(ptrTable, ptr, FIND)
void
Insert(PtrValueHashTable* ptrTable, void* ptr, Generic value)
{