summaryrefslogtreecommitdiffstats
path: root/bindings/ghashtable.h
blob: ef9133f19fbfef2c6d950c2145a2fde50a563a59 (plain)
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
#ifndef G_HASHTABLE_H
#define G_HASHTABLE_H 1
#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 14)

#include "../lasso/utils.h"

typedef struct _GHashNode  GHashNode;

struct _GHashNode
{
  gpointer   key;
  gpointer   value;
  GHashNode *next;
  guint      key_hash;
};

struct _GHashTable
{
  gint             size;
  gint             nnodes;
  GHashNode      **nodes;
  GHashFunc        hash_func;
  GEqualFunc       key_equal_func;
  volatile gint    ref_count;
  GDestroyNotify   key_destroy_func;
  GDestroyNotify   value_destroy_func;
};

/* Helper functions to access JNI interface functions */
#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 12)
static gboolean return_true(G_GNUC_UNUSED gpointer a, G_GNUC_UNUSED gpointer b,
		G_GNUC_UNUSED gpointer c)
{
	return TRUE;
}

static void
g_hash_table_remove_all (GHashTable *hash_table)
{
    lasso_return_if_fail(hash_table != NULL);

    g_hash_table_foreach_remove (hash_table, (GHRFunc)return_true, NULL);
}
#endif
  /* copy of private struct and g_hash_table_get_keys from GLib internals
   * (as this function is useful but new in 2.14) */


static GList *
g_hash_table_get_keys (GHashTable *hash_table)
{
  GHashNode *node;
  gint i;
  GList *retval;

  lasso_return_val_if_fail(hash_table != NULL, NULL);

  retval = NULL;
  for (i = 0; i < hash_table->size; i++)
    for (node = hash_table->nodes[i]; node; node = node->next)
      retval = g_list_prepend (retval, node->key);

  return retval;
}

static GList *
g_hash_table_get_values (GHashTable *hash_table)
{
    GHashNode *node;
    gint i;
    GList *retval;

    lasso_return_val_if_fail(hash_table != NULL, NULL);

    retval = NULL;
    for (i = 0; i < hash_table->size; i++)
        for (node = hash_table->nodes[i]; node; node = node->next)
            retval = g_list_prepend (retval, node->value);

    return retval;
}
#endif
#endif /* G_HASHTABLE_H */