3 * Hash table for (object, property) pairs
6 * Zoltan Varga (vargaz@gmail.com)
11 #include "mono-property-hash.h"
13 struct _MonoPropertyHash
{
14 /* We use one hash table per property */
19 mono_property_hash_new (void)
21 MonoPropertyHash
*hash
= g_new0 (MonoPropertyHash
, 1);
23 hash
->hashes
= g_hash_table_new (NULL
, NULL
);
29 free_hash (gpointer key
, gpointer value
, gpointer user_data
)
31 GHashTable
*hash
= (GHashTable
*)value
;
33 g_hash_table_destroy (hash
);
37 mono_property_hash_destroy (MonoPropertyHash
*hash
)
39 g_hash_table_foreach (hash
->hashes
, free_hash
, NULL
);
40 g_hash_table_destroy (hash
->hashes
);
46 mono_property_hash_insert (MonoPropertyHash
*hash
, gpointer object
, guint32 property
,
49 GHashTable
*prop_hash
;
51 prop_hash
= (GHashTable
*) g_hash_table_lookup (hash
->hashes
, GUINT_TO_POINTER (property
));
53 // FIXME: Maybe use aligned_hash
54 prop_hash
= g_hash_table_new (NULL
, NULL
);
55 g_hash_table_insert (hash
->hashes
, GUINT_TO_POINTER (property
), prop_hash
);
58 g_hash_table_insert (prop_hash
, object
, value
);
62 remove_object (gpointer key
, gpointer value
, gpointer user_data
)
64 GHashTable
*prop_hash
= (GHashTable
*)value
;
66 g_hash_table_remove (prop_hash
, user_data
);
70 mono_property_hash_remove_object (MonoPropertyHash
*hash
, gpointer object
)
72 g_hash_table_foreach (hash
->hashes
, remove_object
, object
);
76 mono_property_hash_lookup (MonoPropertyHash
*hash
, gpointer object
, guint32 property
)
78 GHashTable
*prop_hash
;
80 prop_hash
= (GHashTable
*) g_hash_table_lookup (hash
->hashes
, GUINT_TO_POINTER (property
));
83 return g_hash_table_lookup (prop_hash
, object
);