少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
 * \file
 * Hash table for (object, property) pairs
 *
 * Author:
 *    Zoltan Varga (vargaz@gmail.com)
 *
 * (C) 2008 Novell, Inc
 */
 
#include "mono-property-hash.h"
 
struct _MonoPropertyHash {
    /* We use one hash table per property */
    GHashTable *hashes;
};
 
MonoPropertyHash*
mono_property_hash_new (void)
{
    MonoPropertyHash *hash = g_new0 (MonoPropertyHash, 1);
 
    hash->hashes = g_hash_table_new (NULL, NULL);
 
    return hash;
}
 
static void
free_hash (gpointer key, gpointer value, gpointer user_data)
{
    GHashTable *hash = (GHashTable*)value;
 
    g_hash_table_destroy (hash);
}
 
void
mono_property_hash_destroy (MonoPropertyHash *hash)
{
    g_hash_table_foreach (hash->hashes, free_hash, NULL);
    g_hash_table_destroy (hash->hashes);
 
    g_free (hash);
}
 
void
mono_property_hash_insert (MonoPropertyHash *hash, gpointer object, guint32 property,
                           gpointer value)
{
    GHashTable *prop_hash;
 
    prop_hash = (GHashTable *) g_hash_table_lookup (hash->hashes, GUINT_TO_POINTER (property));
    if (!prop_hash) {
        // FIXME: Maybe use aligned_hash
        prop_hash = g_hash_table_new (NULL, NULL);
        g_hash_table_insert (hash->hashes, GUINT_TO_POINTER (property), prop_hash);
    }
 
    g_hash_table_insert (prop_hash, object, value);
}    
 
static void
remove_object (gpointer key, gpointer value, gpointer user_data)
{
    GHashTable *prop_hash = (GHashTable*)value;
 
    g_hash_table_remove (prop_hash, user_data);
}
 
void
mono_property_hash_remove_object (MonoPropertyHash *hash, gpointer object)
{
    g_hash_table_foreach (hash->hashes, remove_object, object);
}
 
gpointer
mono_property_hash_lookup (MonoPropertyHash *hash, gpointer object, guint32 property)
{
    GHashTable *prop_hash;
 
    prop_hash = (GHashTable *) g_hash_table_lookup (hash->hashes, GUINT_TO_POINTER (property));
    if (!prop_hash)
        return NULL;
    return g_hash_table_lookup (prop_hash, object);
}