Detab TcUnify
[ghc-hetmet.git] / rts / Hash.c
index ada11a6..033ccb3 100644 (file)
@@ -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);
+  }
+}