3 * A hash table which uses the values themselves as nodes.
6 * Mark Probst (mark.probst@gmail.com)
8 * (C) 2007 Novell, Inc.
11 #ifndef __MONO_UTILS_MONO_INTERNAL_HASH__
12 #define __MONO_UTILS_MONO_INTERNAL_HASH__
14 /* A MonoInternalHashTable is a hash table that does not allocate hash
15 nodes. It can be used if the following conditions are fulfilled:
17 * The key is contained (directly or indirectly) in the value.
19 * Each value is in at most one internal hash table at the same
22 The value data structure must then be extended to contain a
23 pointer, used by the internal hash table to chain values in the
26 Apart from the hash function, two other functions must be provided,
27 namely for extracting the key out of a value, and for getting the
28 next value pointer. The latter must actually return a pointer to
29 the next value pointer, because the internal hash table must be
32 See the class_cache internal hash table in MonoImage for an
36 typedef struct _MonoInternalHashTable MonoInternalHashTable;
38 typedef gpointer (*MonoInternalHashKeyExtractFunc) (gpointer value);
39 typedef gpointer* (*MonoInternalHashNextValueFunc) (gpointer value);
41 struct _MonoInternalHashTable
44 MonoInternalHashKeyExtractFunc key_extract;
45 MonoInternalHashNextValueFunc next_value;
52 mono_internal_hash_table_init (MonoInternalHashTable *table,
54 MonoInternalHashKeyExtractFunc key_extract,
55 MonoInternalHashNextValueFunc next_value);
58 mono_internal_hash_table_destroy (MonoInternalHashTable *table);
61 mono_internal_hash_table_lookup (MonoInternalHashTable *table, gpointer key);
63 /* mono_internal_hash_table_insert requires that there is no entry for
64 key in the hash table. If you want to change the value for a key
65 already in the hash table, remove it first and then insert the new
68 The key pointer is actually only passed here to check a debugging
69 assertion and to make the API look more familiar. */
71 mono_internal_hash_table_insert (MonoInternalHashTable *table,
72 gpointer key, gpointer value);
75 mono_internal_hash_table_remove (MonoInternalHashTable *table, gpointer key);