727c04298c8c05e75d259527c72620a5d59c9713
[ghc.git] / rts / Hash.h
1 /*-----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1999
4 *
5 * Prototypes for Hash.c
6 *
7 * -------------------------------------------------------------------------- */
8
9 #ifndef HASH_H
10 #define HASH_H
11
12 #include "BeginPrivate.h"
13
14 typedef struct hashtable HashTable; /* abstract */
15
16 /* Hash table access where the keys are StgWords */
17 HashTable * allocHashTable ( void );
18 void * lookupHashTable ( HashTable *table, StgWord key );
19 void insertHashTable ( HashTable *table, StgWord key, void *data );
20 void * removeHashTable ( HashTable *table, StgWord key, void *data );
21
22 /* Hash table access where the keys are C strings (the strings are
23 * assumed to be allocated by the caller, and mustn't be deallocated
24 * until the corresponding hash table entry has been removed).
25 */
26 HashTable * allocStrHashTable ( void );
27
28 #define lookupStrHashTable(table, key) \
29 (lookupHashTable(table, (StgWord)key))
30
31 #define insertStrHashTable(table, key, data) \
32 (insertHashTable(table, (StgWord)key, data))
33
34 #define removeStrHashTable(table, key, data) \
35 (removeHashTable(table, (StgWord)key, data))
36
37 /* Hash tables for arbitrary keys */
38 typedef int HashFunction(HashTable *table, StgWord key);
39 typedef int CompareFunction(StgWord key1, StgWord key2);
40 HashTable * allocHashTable_(HashFunction *hash, CompareFunction *compare);
41 int hashWord(HashTable *table, StgWord key);
42 int hashStr(HashTable *table, char *key);
43
44 /* Freeing hash tables
45 */
46 void freeHashTable ( HashTable *table, void (*freeDataFun)(void *) );
47
48 void exitHashTable ( void );
49
50 #include "EndPrivate.h"
51
52 #endif /* HASH_H */
53