• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
28 #error "Only <glib.h> can be included directly."
29 #endif
30 
31 #ifndef __G_HASH_H__
32 #define __G_HASH_H__
33 
34 #include <glib/gtypes.h>
35 #include <glib/glist.h>
36 
37 G_BEGIN_DECLS
38 
39 typedef struct _GHashTable  GHashTable;
40 
41 typedef gboolean  (*GHRFunc)  (gpointer  key,
42                                gpointer  value,
43                                gpointer  user_data);
44 
45 typedef struct _GHashTableIter GHashTableIter;
46 
47 struct _GHashTableIter
48 {
49   /*< private >*/
50   gpointer	dummy1;
51   gpointer	dummy2;
52   gpointer	dummy3;
53   int		dummy4;
54   gboolean	dummy5;
55   gpointer	dummy6;
56 };
57 
58 /* Hash tables
59  */
60 GHashTable* g_hash_table_new		   (GHashFunc	    hash_func,
61 					    GEqualFunc	    key_equal_func);
62 GHashTable* g_hash_table_new_full      	   (GHashFunc	    hash_func,
63 					    GEqualFunc	    key_equal_func,
64 					    GDestroyNotify  key_destroy_func,
65 					    GDestroyNotify  value_destroy_func);
66 void	    g_hash_table_destroy	   (GHashTable	   *hash_table);
67 void	    g_hash_table_insert		   (GHashTable	   *hash_table,
68 					    gpointer	    key,
69 					    gpointer	    value);
70 void        g_hash_table_replace           (GHashTable     *hash_table,
71 					    gpointer	    key,
72 					    gpointer	    value);
73 gboolean    g_hash_table_remove		   (GHashTable	   *hash_table,
74 					    gconstpointer   key);
75 void        g_hash_table_remove_all        (GHashTable     *hash_table);
76 gboolean    g_hash_table_steal             (GHashTable     *hash_table,
77 					    gconstpointer   key);
78 void        g_hash_table_steal_all         (GHashTable     *hash_table);
79 gpointer    g_hash_table_lookup		   (GHashTable	   *hash_table,
80 					    gconstpointer   key);
81 gboolean    g_hash_table_lookup_extended   (GHashTable	   *hash_table,
82 					    gconstpointer   lookup_key,
83 					    gpointer	   *orig_key,
84 					    gpointer	   *value);
85 void	    g_hash_table_foreach	   (GHashTable	   *hash_table,
86 					    GHFunc	    func,
87 					    gpointer	    user_data);
88 gpointer    g_hash_table_find	           (GHashTable	   *hash_table,
89 					    GHRFunc	    predicate,
90 					    gpointer	    user_data);
91 guint	    g_hash_table_foreach_remove	   (GHashTable	   *hash_table,
92 					    GHRFunc	    func,
93 					    gpointer	    user_data);
94 guint	    g_hash_table_foreach_steal	   (GHashTable	   *hash_table,
95 					    GHRFunc	    func,
96 					    gpointer	    user_data);
97 guint	    g_hash_table_size		   (GHashTable	   *hash_table);
98 GList *     g_hash_table_get_keys          (GHashTable     *hash_table);
99 GList *     g_hash_table_get_values        (GHashTable     *hash_table);
100 
101 void        g_hash_table_iter_init         (GHashTableIter *iter,
102 					    GHashTable     *hash_table);
103 gboolean    g_hash_table_iter_next         (GHashTableIter *iter,
104 					    gpointer       *key,
105 					    gpointer       *value);
106 GHashTable* g_hash_table_iter_get_hash_table (GHashTableIter *iter);
107 void        g_hash_table_iter_remove       (GHashTableIter *iter);
108 void        g_hash_table_iter_steal        (GHashTableIter *iter);
109 
110 /* keeping hash tables alive */
111 GHashTable* g_hash_table_ref   		   (GHashTable 	   *hash_table);
112 void        g_hash_table_unref             (GHashTable     *hash_table);
113 
114 #ifndef G_DISABLE_DEPRECATED
115 
116 /* The following two functions are deprecated and will be removed in
117  * the next major release. They do no good. */
118 #define g_hash_table_freeze(hash_table) ((void)0)
119 #define g_hash_table_thaw(hash_table) ((void)0)
120 
121 #endif /* G_DISABLE_DEPRECATED */
122 
123 /* Hash Functions
124  */
125 gboolean g_str_equal (gconstpointer  v1,
126                       gconstpointer  v2);
127 guint    g_str_hash  (gconstpointer  v);
128 
129 gboolean g_int_equal (gconstpointer  v1,
130                       gconstpointer  v2);
131 guint    g_int_hash  (gconstpointer  v);
132 
133 /* This "hash" function will just return the key's address as an
134  * unsigned integer. Useful for hashing on plain addresses or
135  * simple integer values.
136  * Passing NULL into g_hash_table_new() as GHashFunc has the
137  * same effect as passing g_direct_hash().
138  */
139 guint    g_direct_hash  (gconstpointer  v) G_GNUC_CONST;
140 gboolean g_direct_equal (gconstpointer  v1,
141                          gconstpointer  v2) G_GNUC_CONST;
142 
143 G_END_DECLS
144 
145 #endif /* __G_HASH_H__ */
146