7b2e00c321d645920e815f57f6b933b70bb91ecd
[mono.git] / mono / utils / mono-value-hash.h
1 /*
2  * mono-value-hash.h: A hash table which only stores values in the hash nodes.
3  *
4  * Author:
5  *   Mark Probst (mark.probst@gmail.com)
6  *   Zoltan Varga (vargaz@gmail.com)
7  *
8  * (C) 2008 Novell, Inc.
9  *
10  */
11 #ifndef __MONO_UTILS_MONO_VALUE_HASH__
12 #define __MONO_UTILS_MONO_VALUE_HASH__
13
14 #include <glib.h>
15 #include "mono-compiler.h"
16
17 G_BEGIN_DECLS
18
19 /*
20  * This is a hash table with the following features/restrictions:
21  * - Keys are not stored in the table, instead a function must be supplied which 
22  *   computes them from the value.
23  * - Values are assumed to be normal pointers, i.e. their lowest 2-3 bits should be
24  *   zero.
25  * - NULL values are not allowed.
26  * - It uses internal probing instead of chaining.
27  * - The above restrictions mean that this hash table will be somewhat slower than
28  *   hash tables which store the key (or even the key hash) in the hash nodes. But
29  *   it also means that each hash node has a size of one machine word, instead of
30  * 4 in GHashTable.
31  * - Removal of entries is not supported, as it is not needed by the runtime right 
32  *   now.
33  */
34
35 typedef struct _MonoValueHashTable MonoValueHashTable;
36
37 typedef gpointer (*MonoValueHashKeyExtractFunc) (gpointer value);
38
39 MonoValueHashTable* mono_value_hash_table_new (GHashFunc hash_func,
40                                                                                            GEqualFunc key_equal_func,
41                                                                                            MonoValueHashKeyExtractFunc key_extract);
42
43 void
44 mono_value_hash_table_destroy (MonoValueHashTable *table);
45
46 gpointer
47 mono_value_hash_table_lookup (MonoValueHashTable *table, gconstpointer key);
48
49 /* The key pointer is actually only passed here to check a debugging
50    assertion and to make the API look more familiar. */
51 void
52 mono_value_hash_table_insert (MonoValueHashTable *table,
53                                  gpointer key, gpointer value);
54
55 G_END_DECLS
56
57 #endif