17ca7de612afcfe95af8efbf00d5a875c560d9f8
[platform/upstream/glib.git] / glib / ghash.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __G_HASH_H__
28 #define __G_HASH_H__
29
30 #include <glib/gtypes.h>
31 #include <glib/glist.h>
32
33 G_BEGIN_DECLS
34
35 typedef struct _GHashTable  GHashTable;
36
37 typedef gboolean  (*GHRFunc)  (gpointer  key,
38                                gpointer  value,
39                                gpointer  user_data);
40
41 typedef struct _GHashTableIter GHashTableIter;
42
43 struct _GHashTableIter
44 {
45   /*< private >*/
46   gpointer      dummy1;
47   gpointer      dummy2;
48   gpointer      dummy3;
49   int           dummy4;
50   gboolean      dummy5;
51   gpointer      dummy6;
52 };
53
54 /* Hash tables
55  */
56 GHashTable* g_hash_table_new               (GHashFunc       hash_func,
57                                             GEqualFunc      key_equal_func);
58 GHashTable* g_hash_table_new_full          (GHashFunc       hash_func,
59                                             GEqualFunc      key_equal_func,
60                                             GDestroyNotify  key_destroy_func,
61                                             GDestroyNotify  value_destroy_func);
62 void        g_hash_table_destroy           (GHashTable     *hash_table);
63 void        g_hash_table_insert            (GHashTable     *hash_table,
64                                             gpointer        key,
65                                             gpointer        value);
66 void        g_hash_table_replace           (GHashTable     *hash_table,
67                                             gpointer        key,
68                                             gpointer        value);
69 gboolean    g_hash_table_remove            (GHashTable     *hash_table,
70                                             gconstpointer   key);
71 void        g_hash_table_remove_all        (GHashTable     *hash_table);
72 gboolean    g_hash_table_steal             (GHashTable     *hash_table,
73                                             gconstpointer   key);
74 void        g_hash_table_steal_all         (GHashTable     *hash_table);
75 gpointer    g_hash_table_lookup            (GHashTable     *hash_table,
76                                             gconstpointer   key);
77 gboolean    g_hash_table_lookup_extended   (GHashTable     *hash_table,
78                                             gconstpointer   lookup_key,
79                                             gpointer       *orig_key,
80                                             gpointer       *value);
81 void        g_hash_table_foreach           (GHashTable     *hash_table,
82                                             GHFunc          func,
83                                             gpointer        user_data);
84 gpointer    g_hash_table_find              (GHashTable     *hash_table,
85                                             GHRFunc         predicate,
86                                             gpointer        user_data);
87 guint       g_hash_table_foreach_remove    (GHashTable     *hash_table,
88                                             GHRFunc         func,
89                                             gpointer        user_data);
90 guint       g_hash_table_foreach_steal     (GHashTable     *hash_table,
91                                             GHRFunc         func,
92                                             gpointer        user_data);
93 guint       g_hash_table_size              (GHashTable     *hash_table);
94 GList *     g_hash_table_get_keys          (GHashTable     *hash_table);
95 GList *     g_hash_table_get_values        (GHashTable     *hash_table);
96
97 void        g_hash_table_iter_init         (GHashTableIter *iter,
98                                             GHashTable     *hash_table);
99 gboolean    g_hash_table_iter_next         (GHashTableIter *iter,
100                                             gpointer       *key,
101                                             gpointer       *value);
102 GHashTable* g_hash_table_iter_get_hash_table (GHashTableIter *iter);
103 void        g_hash_table_iter_remove       (GHashTableIter *iter);
104 void        g_hash_table_iter_steal        (GHashTableIter *iter);
105
106 /* keeping hash tables alive */
107 GHashTable* g_hash_table_ref               (GHashTable     *hash_table);
108 void        g_hash_table_unref             (GHashTable     *hash_table);
109
110 #ifndef G_DISABLE_DEPRECATED
111
112 /* The following two functions are deprecated and will be removed in
113  * the next major release. They do no good. */
114 #define g_hash_table_freeze(hash_table) ((void)0)
115 #define g_hash_table_thaw(hash_table) ((void)0)
116
117 #endif /* G_DISABLE_DEPRECATED */
118
119 /* Hash Functions
120  */
121 gboolean g_str_equal (gconstpointer  v1,
122                       gconstpointer  v2);
123 guint    g_str_hash  (gconstpointer  v);
124
125 gboolean g_int_equal (gconstpointer  v1,
126                       gconstpointer  v2);
127 guint    g_int_hash  (gconstpointer  v);
128
129 /* This "hash" function will just return the key's address as an
130  * unsigned integer. Useful for hashing on plain addresses or
131  * simple integer values.
132  * Passing NULL into g_hash_table_new() as GHashFunc has the
133  * same effect as passing g_direct_hash().
134  */
135 guint    g_direct_hash  (gconstpointer  v) G_GNUC_CONST;
136 gboolean g_direct_equal (gconstpointer  v1,
137                          gconstpointer  v2) G_GNUC_CONST;
138
139 G_END_DECLS
140
141 #endif /* __G_HASH_H__ */
142