typedef struct hashlist HashList;
-typedef int HashFunction(HashTable *table, StgWord key);
-typedef int CompareFunction(StgWord key1, StgWord key2);
-
struct hashtable {
int split; /* Next bucket to split when expanding */
int max; /* Max bucket of smaller table */
* next bucket to be split, re-hash using the larger table.
* -------------------------------------------------------------------------- */
-static int
+int
hashWord(HashTable *table, StgWord key)
{
int bucket;
return bucket;
}
-static int
+int
hashStr(HashTable *table, char *key)
{
int h, bucket;
static HashList *freeList = NULL;
+static struct chunkList {
+ void *chunk;
+ struct chunkList *next;
+} *chunks;
+
static HashList *
allocHashList(void)
{
HashList *hl, *p;
+ struct chunkList *cl;
if ((hl = freeList) != NULL) {
freeList = hl->next;
} else {
hl = stgMallocBytes(HCHUNK * sizeof(HashList), "allocHashList");
+ cl = stgMallocBytes(sizeof (*cl), "allocHashList: chunkList");
+ cl->chunk = hl;
+ cl->next = chunks;
+ chunks = cl;
freeList = hl + 1;
for (p = freeList; p < hl + HCHUNK - 1; p++)
* initializing all of the first segment's hash buckets to NULL.
* -------------------------------------------------------------------------- */
-static HashTable *
+HashTable *
allocHashTable_(HashFunction *hash, CompareFunction *compare)
{
HashTable *table;
return allocHashTable_((HashFunction *)hashStr,
(CompareFunction *)compareStr);
}
+
+void
+exitHashTable(void)
+{
+ struct chunkList *cl;
+
+ while ((cl = chunks) != NULL) {
+ chunks = cl->next;
+ stgFree(cl->chunk);
+ stgFree(cl);
+ }
+}