1 #ifndef __MONO_SGENHASHTABLE_H__
2 #define __MONO_SGENHASHTABLE_H__
12 typedef struct _SgenHashTableEntry SgenHashTableEntry
;
13 struct _SgenHashTableEntry
{
14 SgenHashTableEntry
*next
;
16 char data
[MONO_ZERO_LEN_ARRAY
]; /* data is pointer-aligned */
24 GEqualFunc equal_func
;
25 SgenHashTableEntry
**table
;
30 #define SGEN_HASH_TABLE_INIT(table_type,entry_type,data_size,hash_func,equal_func) { (table_type), (entry_type), (data_size), (hash_func), (equal_func), NULL, 0, 0 }
31 #define SGEN_HASH_TABLE_ENTRY_SIZE(data_size) ((data_size) + sizeof (SgenHashTableEntry*) + sizeof (gpointer))
33 gpointer
sgen_hash_table_lookup (SgenHashTable
*table
, gpointer key
);
34 gboolean
sgen_hash_table_replace (SgenHashTable
*table
, gpointer key
, gpointer new_value
, gpointer old_value
);
35 gboolean
sgen_hash_table_set_value (SgenHashTable
*table
, gpointer key
, gpointer new_value
, gpointer old_value
);
36 gboolean
sgen_hash_table_set_key (SgenHashTable
*hash_table
, gpointer old_key
, gpointer new_key
);
37 gboolean
sgen_hash_table_remove (SgenHashTable
*table
, gpointer key
, gpointer data_return
);
39 void sgen_hash_table_clean (SgenHashTable
*table
);
41 void sgen_init_hash_table (void);
43 #define sgen_hash_table_num_entries(h) ((h)->num_entries)
45 #define sgen_hash_table_key_for_value_pointer(v) ((GCObject *)(((SgenHashTableEntry*)((char*)(v) - G_STRUCT_OFFSET (SgenHashTableEntry, data)))->key))
47 #define SGEN_HASH_TABLE_FOREACH(h,tk,k,tv,v) do { \
48 SgenHashTable *__hash_table = (h); \
49 SgenHashTableEntry **__table = __hash_table->table; \
51 for (__i = 0; __i < (h)->size; ++__i) { \
52 SgenHashTableEntry **__iter, **__next; \
53 for (__iter = &__table [__i]; *__iter; __iter = __next) { \
54 SgenHashTableEntry *__entry = *__iter; \
55 __next = &__entry->next; \
56 (k) = (tk)__entry->key; \
57 (v) = (tv)__entry->data;
59 /* The loop must be continue'd after using this! */
60 #define SGEN_HASH_TABLE_FOREACH_REMOVE(free) do { \
63 --__hash_table->num_entries; \
65 sgen_free_internal (__entry, __hash_table->entry_mem_type); \
68 #define SGEN_HASH_TABLE_FOREACH_SET_KEY(k) ((__entry)->key = (k))
70 #define SGEN_HASH_TABLE_FOREACH_END \