Linker: some extra debugging / logging
[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 * Values are passed into the hash table and stored as `const void *` values,
18 * but when the value is looked up or removed, the value is returned without the
19 * `const` so that calling function can mutate what the pointer points to if it
20 * needs to.
21 */
22 HashTable * allocHashTable ( void );
23 void insertHashTable ( HashTable *table, StgWord key, const void *data );
24 void * lookupHashTable ( const HashTable *table, StgWord key );
25 void * removeHashTable ( HashTable *table, StgWord key, const void *data );
26
27 int keyCountHashTable (HashTable *table);
28
29 // Puts up to szKeys keys of the hash table into the given array. Returns the
30 // actual amount of keys that have been retrieved.
31 //
32 // If the table is modified concurrently, the function behavior is undefined.
33 //
34 int keysHashTable(HashTable *table, StgWord keys[], int szKeys);
35
36 /* Hash table access where the keys are C strings (the strings are
37 * assumed to be allocated by the caller, and mustn't be deallocated
38 * until the corresponding hash table entry has been removed).
39 */
40 HashTable * allocStrHashTable ( void );
41
42 #define lookupStrHashTable(table, key) \
43 (lookupHashTable(table, (StgWord)key))
44
45 #define insertStrHashTable(table, key, data) \
46 (insertHashTable(table, (StgWord)key, data))
47
48 #define removeStrHashTable(table, key, data) \
49 (removeHashTable(table, (StgWord)key, data))
50
51 /* Hash tables for arbitrary keys */
52 typedef int HashFunction(const HashTable *table, StgWord key);
53 typedef int CompareFunction(StgWord key1, StgWord key2);
54 HashTable * allocHashTable_(HashFunction *hash, CompareFunction *compare);
55 int hashWord(const HashTable *table, StgWord key);
56 int hashStr(const HashTable *table, char *key);
57
58 /* Freeing hash tables
59 */
60 void freeHashTable ( HashTable *table, void (*freeDataFun)(void *) );
61
62 void exitHashTable ( void );
63
64 #include "EndPrivate.h"
65
66 #endif /* HASH_H */