projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add unique package identifiers (InstalledPackageId) in the package DB
[ghc-hetmet.git]
/
rts
/
Hash.c
diff --git
a/rts/Hash.c
b/rts/Hash.c
index
ada11a6
..
09d0a06
100644
(file)
--- a/
rts/Hash.c
+++ b/
rts/Hash.c
@@
-10,10
+10,10
@@
#include "PosixSource.h"
#include "Rts.h"
#include "PosixSource.h"
#include "Rts.h"
+
#include "Hash.h"
#include "RtsUtils.h"
#include "Hash.h"
#include "RtsUtils.h"
-#include <stdlib.h>
#include <string.h>
#define HSEGSIZE 1024 /* Size of a single hash table segment */
#include <string.h>
#define HSEGSIZE 1024 /* Size of a single hash table segment */
@@
-35,9
+35,6
@@
struct hashlist {
typedef struct hashlist 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 */
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.
* -------------------------------------------------------------------------- */
* next bucket to be split, re-hash using the larger table.
* -------------------------------------------------------------------------- */
-static int
+int
hashWord(HashTable *table, StgWord key)
{
int bucket;
hashWord(HashTable *table, StgWord key)
{
int bucket;
@@
-73,7
+70,7
@@
hashWord(HashTable *table, StgWord key)
return bucket;
}
return bucket;
}
-static int
+int
hashStr(HashTable *table, char *key)
{
int h, bucket;
hashStr(HashTable *table, char *key)
{
int h, bucket;
@@
-212,15
+209,25
@@
lookupHashTable(HashTable *table, StgWord key)
static HashList *freeList = NULL;
static HashList *freeList = NULL;
+static struct chunkList {
+ void *chunk;
+ struct chunkList *next;
+} *chunks;
+
static HashList *
allocHashList(void)
{
HashList *hl, *p;
static HashList *
allocHashList(void)
{
HashList *hl, *p;
+ struct chunkList *cl;
if ((hl = freeList) != NULL) {
freeList = hl->next;
} else {
hl = stgMallocBytes(HCHUNK * sizeof(HashList), "allocHashList");
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++)
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.
* -------------------------------------------------------------------------- */
* initializing all of the first segment's hash buckets to NULL.
* -------------------------------------------------------------------------- */
-static HashTable *
+HashTable *
allocHashTable_(HashFunction *hash, CompareFunction *compare)
{
HashTable *table;
allocHashTable_(HashFunction *hash, CompareFunction *compare)
{
HashTable *table;
@@
-374,3
+381,15
@@
allocStrHashTable(void)
return allocHashTable_((HashFunction *)hashStr,
(CompareFunction *)compareStr);
}
return allocHashTable_((HashFunction *)hashStr,
(CompareFunction *)compareStr);
}
+
+void
+exitHashTable(void)
+{
+ struct chunkList *cl;
+
+ while ((cl = chunks) != NULL) {
+ chunks = cl->next;
+ stgFree(cl->chunk);
+ stgFree(cl);
+ }
+}