2 * mono-property-hash.c: Hash table for (object, property) pairs
5 * Zoltan Varga (vargaz@gmail.com)
10 #include "mono-property-hash.h"
12 struct _MonoPropertyHash
{
13 /* We use one hash table per property */
18 mono_property_hash_new (void)
20 MonoPropertyHash
*hash
= g_new0 (MonoPropertyHash
, 1);
22 hash
->hashes
= g_hash_table_new (NULL
, NULL
);
28 free_hash (gpointer key
, gpointer value
, gpointer user_data
)
30 GHashTable
*hash
= (GHashTable
*)value
;
32 g_hash_table_destroy (hash
);
36 mono_property_hash_destroy (MonoPropertyHash
*hash
)
38 g_hash_table_foreach (hash
->hashes
, free_hash
, NULL
);
39 g_hash_table_destroy (hash
->hashes
);
45 mono_property_hash_insert (MonoPropertyHash
*hash
, gpointer object
, guint32 property
,
48 GHashTable
*prop_hash
;
50 prop_hash
= (GHashTable
*) g_hash_table_lookup (hash
->hashes
, GUINT_TO_POINTER (property
));
52 // FIXME: Maybe use aligned_hash
53 prop_hash
= g_hash_table_new (NULL
, NULL
);
54 g_hash_table_insert (hash
->hashes
, GUINT_TO_POINTER (property
), prop_hash
);
57 g_hash_table_insert (prop_hash
, object
, value
);
61 remove_object (gpointer key
, gpointer value
, gpointer user_data
)
63 GHashTable
*prop_hash
= (GHashTable
*)value
;
65 g_hash_table_remove (prop_hash
, user_data
);
69 mono_property_hash_remove_object (MonoPropertyHash
*hash
, gpointer object
)
71 g_hash_table_foreach (hash
->hashes
, remove_object
, object
);
75 mono_property_hash_lookup (MonoPropertyHash
*hash
, gpointer object
, guint32 property
)
77 GHashTable
*prop_hash
;
79 prop_hash
= (GHashTable
*) g_hash_table_lookup (hash
->hashes
, GUINT_TO_POINTER (property
));
82 return g_hash_table_lookup (prop_hash
, object
);