1 #ifndef G_HASHTABLE_H
2 #define G_HASHTABLE_H 1
3 #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 14)
4 
5 #include "../lasso/utils.h"
6 
7 typedef struct _GHashNode  GHashNode;
8 
9 struct _GHashNode
10 {
11   gpointer   key;
12   gpointer   value;
13   GHashNode *next;
14   guint      key_hash;
15 };
16 
17 struct _GHashTable
18 {
19   gint             size;
20   gint             nnodes;
21   GHashNode      **nodes;
22   GHashFunc        hash_func;
23   GEqualFunc       key_equal_func;
24   volatile gint    ref_count;
25   GDestroyNotify   key_destroy_func;
26   GDestroyNotify   value_destroy_func;
27 };
28 
29 /* Helper functions to access JNI interface functions */
30 #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 12)
return_true(G_GNUC_UNUSED gpointer a,G_GNUC_UNUSED gpointer b,G_GNUC_UNUSED gpointer c)31 static gboolean return_true(G_GNUC_UNUSED gpointer a, G_GNUC_UNUSED gpointer b,
32 		G_GNUC_UNUSED gpointer c)
33 {
34 	return TRUE;
35 }
36 
37 G_GNUC_UNUSED static void
g_hash_table_remove_all(GHashTable * hash_table)38 g_hash_table_remove_all (GHashTable *hash_table)
39 {
40     lasso_return_if_fail(hash_table != NULL);
41 
42     g_hash_table_foreach_remove (hash_table, (GHRFunc)return_true, NULL);
43 }
44 #endif
45   /* copy of private struct and g_hash_table_get_keys from GLib internals
46    * (as this function is useful but new in 2.14) */
47 
48 
49 G_GNUC_UNUSED static GList *
g_hash_table_get_keys(GHashTable * hash_table)50 g_hash_table_get_keys (GHashTable *hash_table)
51 {
52   GHashNode *node;
53   gint i;
54   GList *retval;
55 
56   lasso_return_val_if_fail(hash_table != NULL, NULL);
57 
58   retval = NULL;
59   for (i = 0; i < hash_table->size; i++)
60     for (node = hash_table->nodes[i]; node; node = node->next)
61       retval = g_list_prepend (retval, node->key);
62 
63   return retval;
64 }
65 
66 G_GNUC_UNUSED static GList *
g_hash_table_get_values(GHashTable * hash_table)67 g_hash_table_get_values (GHashTable *hash_table)
68 {
69     GHashNode *node;
70     gint i;
71     GList *retval;
72 
73     lasso_return_val_if_fail(hash_table != NULL, NULL);
74 
75     retval = NULL;
76     for (i = 0; i < hash_table->size; i++)
77         for (node = hash_table->nodes[i]; node; node = node->next)
78             retval = g_list_prepend (retval, node->value);
79 
80     return retval;
81 }
82 #endif
83 #endif /* G_HASHTABLE_H */
84