X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=rts%2FHash.c;h=033ccb3e73a2c9701c59bf250b7adab508375bbd;hp=ada11a6a859ef59f941719f3dfb3e28fee869547;hb=8604da0136707cc14845d14a88c2272fe576b6d0;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1 diff --git a/rts/Hash.c b/rts/Hash.c index ada11a6..033ccb3 100644 --- a/rts/Hash.c +++ b/rts/Hash.c @@ -35,9 +35,6 @@ struct hashlist { 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 */ @@ -55,7 +52,7 @@ struct hashtable { * next bucket to be split, re-hash using the larger table. * -------------------------------------------------------------------------- */ -static int +int hashWord(HashTable *table, StgWord key) { int bucket; @@ -73,7 +70,7 @@ hashWord(HashTable *table, StgWord key) return bucket; } -static int +int hashStr(HashTable *table, char *key) { int h, bucket; @@ -212,15 +209,25 @@ lookupHashTable(HashTable *table, StgWord key) 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++) @@ -337,7 +344,7 @@ freeHashTable(HashTable *table, void (*freeDataFun)(void *) ) * initializing all of the first segment's hash buckets to NULL. * -------------------------------------------------------------------------- */ -static HashTable * +HashTable * allocHashTable_(HashFunction *hash, CompareFunction *compare) { HashTable *table; @@ -374,3 +381,15 @@ allocStrHashTable(void) return allocHashTable_((HashFunction *)hashStr, (CompareFunction *)compareStr); } + +void +exitHashTable(void) +{ + struct chunkList *cl; + + while ((cl = chunks) != NULL) { + chunks = cl->next; + stgFree(cl->chunk); + stgFree(cl); + } +}