[cert-sync]: Make the new store the default and add '--legacy' for the old one.
[mono-project.git] / mono / utils / mono-property-hash.c
blob0eaadf795758a2371b9f5eac026d75771ea7b3f3
1 /*
2 * mono-property-hash.c: Hash table for (object, property) pairs
4 * Author:
5 * Zoltan Varga (vargaz@gmail.com)
7 * (C) 2008 Novell, Inc
8 */
10 #include "mono-property-hash.h"
12 struct _MonoPropertyHash {
13 /* We use one hash table per property */
14 GHashTable *hashes;
17 MonoPropertyHash*
18 mono_property_hash_new (void)
20 MonoPropertyHash *hash = g_new0 (MonoPropertyHash, 1);
22 hash->hashes = g_hash_table_new (NULL, NULL);
24 return hash;
27 static void
28 free_hash (gpointer key, gpointer value, gpointer user_data)
30 GHashTable *hash = (GHashTable*)value;
32 g_hash_table_destroy (hash);
35 void
36 mono_property_hash_destroy (MonoPropertyHash *hash)
38 g_hash_table_foreach (hash->hashes, free_hash, NULL);
39 g_hash_table_destroy (hash->hashes);
41 g_free (hash);
44 void
45 mono_property_hash_insert (MonoPropertyHash *hash, gpointer object, guint32 property,
46 gpointer value)
48 GHashTable *prop_hash;
50 prop_hash = (GHashTable *) g_hash_table_lookup (hash->hashes, GUINT_TO_POINTER (property));
51 if (!prop_hash) {
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);
60 static void
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);
68 void
69 mono_property_hash_remove_object (MonoPropertyHash *hash, gpointer object)
71 g_hash_table_foreach (hash->hashes, remove_object, object);
74 gpointer
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));
80 if (!prop_hash)
81 return NULL;
82 return g_hash_table_lookup (prop_hash, object);