A bunch of typofixes
[ghc.git] / rts / Hash.h
1 /*-----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1999
4 *
5 * Prototypes for Hash.c
6 *
7 * -------------------------------------------------------------------------- */
8
9 #pragma once
10
11 #include "BeginPrivate.h"
12
13 typedef struct hashtable HashTable; /* abstract */
14
15 /* Hash table access where the keys are StgWords.
16 * Values are passed into the hash table and stored as `const void *` values,
17 * but when the value is looked up or removed, the value is returned without the
18 * `const` so that calling function can mutate what the pointer points to if it
19 * needs to.
20 */
21 HashTable * allocHashTable ( void );
22 void insertHashTable ( HashTable *table, StgWord key, const void *data );
23 void * lookupHashTable ( const HashTable *table, StgWord key );
24 void * removeHashTable ( HashTable *table, StgWord key, const void *data );
25
26 int keyCountHashTable (HashTable *table);
27
28 // Puts up to szKeys keys of the hash table into the given array. Returns the
29 // actual amount of keys that have been retrieved.
30 //
31 // If the table is modified concurrently, the function behavior is undefined.
32 //
33 int keysHashTable(HashTable *table, StgWord keys[], int szKeys);
34
35 typedef void (*MapHashFn)(void *data, StgWord key, const void *value);
36
37 void mapHashTable(HashTable *table, void *data, MapHashFn fn);
38
39 /* Hash table access where the keys are C strings (the strings are
40 * assumed to be allocated by the caller, and mustn't be deallocated
41 * until the corresponding hash table entry has been removed).
42 */
43 HashTable * allocStrHashTable ( void );
44
45 #define lookupStrHashTable(table, key) \
46 (lookupHashTable(table, (StgWord)key))
47
48 #define insertStrHashTable(table, key, data) \
49 (insertHashTable(table, (StgWord)key, data))
50
51 #define removeStrHashTable(table, key, data) \
52 (removeHashTable(table, (StgWord)key, data))
53
54 /* Hash tables for arbitrary keys */
55 typedef int HashFunction(const HashTable *table, StgWord key);
56 typedef int CompareFunction(StgWord key1, StgWord key2);
57 HashTable * allocHashTable_(HashFunction *hash, CompareFunction *compare);
58 int hashWord(const HashTable *table, StgWord key);
59 int hashStr(const HashTable *table, char *key);
60
61 /* Freeing hash tables
62 */
63 void freeHashTable ( HashTable *table, void (*freeDataFun)(void *) );
64
65 void exitHashTable ( void );
66
67 #include "EndPrivate.h"