ghash.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 /*
00022  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00023  * file for a list of people on the GLib Team.  See the ChangeLog
00024  * files for a list of changes.  These files are distributed with
00025  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00026  */
00027 
00028 #ifndef __G_HASH_H__
00029 #define __G_HASH_H__
00030 
00031 #include <_ansi.h>
00032 #include <glib/gtypes.h>
00033 
00034 G_BEGIN_DECLS
00035 
00036 typedef struct _GHashTable  GHashTable;
00037 
00038 typedef gboolean  (*GHRFunc)  (gpointer  key,
00039                                gpointer  value,
00040                                gpointer  user_data);
00041 
00042 /* Hash tables
00043  */
00044 IMPORT_C GHashTable* g_hash_table_new              (GHashFunc       hash_func,
00045                                             GEqualFunc      key_equal_func);
00046 IMPORT_C GHashTable* g_hash_table_new_full                 (GHashFunc       hash_func,
00047                                             GEqualFunc      key_equal_func,
00048                                             GDestroyNotify  key_destroy_func,
00049                                             GDestroyNotify  value_destroy_func);
00050 IMPORT_C void       g_hash_table_destroy           (GHashTable     *hash_table);
00051 IMPORT_C void       g_hash_table_insert            (GHashTable     *hash_table,
00052                                             gpointer        key,
00053                                             gpointer        value);
00054 IMPORT_C void        g_hash_table_replace           (GHashTable     *hash_table,
00055                                             gpointer        key,
00056                                             gpointer        value);
00057 IMPORT_C gboolean    g_hash_table_remove                   (GHashTable     *hash_table,
00058                                             gconstpointer   key);
00059 IMPORT_C gboolean    g_hash_table_steal             (GHashTable     *hash_table,
00060                                             gconstpointer   key);
00061 IMPORT_C gpointer    g_hash_table_lookup                   (GHashTable     *hash_table,
00062                                             gconstpointer   key);
00063 IMPORT_C gboolean    g_hash_table_lookup_extended   (GHashTable    *hash_table,
00064                                             gconstpointer   lookup_key,
00065                                             gpointer       *orig_key,
00066                                             gpointer       *value);
00067 IMPORT_C void       g_hash_table_foreach           (GHashTable     *hash_table,
00068                                             GHFunc          func,
00069                                             gpointer        user_data);
00070 IMPORT_C gpointer    g_hash_table_find     (GHashTable     *hash_table,
00071                                             GHRFunc         predicate,
00072                                             gpointer        user_data);
00073 IMPORT_C guint      g_hash_table_foreach_remove    (GHashTable     *hash_table,
00074                                             GHRFunc         func,
00075                                             gpointer        user_data);
00076 IMPORT_C guint      g_hash_table_foreach_steal     (GHashTable     *hash_table,
00077                                             GHRFunc         func,
00078                                             gpointer        user_data);
00079 IMPORT_C guint      g_hash_table_size              (GHashTable     *hash_table);
00080 
00081 /* keeping hash tables alive */
00082 IMPORT_C GHashTable* g_hash_table_ref                      (GHashTable     *hash_table);
00083 IMPORT_C void        g_hash_table_unref             (GHashTable     *hash_table);
00084 
00085 #ifndef G_DISABLE_DEPRECATED
00086 
00087 /* The following two functions are deprecated and will be removed in
00088  * the next major release. They do no good. */
00089 #define g_hash_table_freeze(hash_table) ((void)0)
00090 #define g_hash_table_thaw(hash_table) ((void)0)
00091 
00092 #endif /* G_DISABLE_DEPRECATED */
00093 
00094 /* Hash Functions
00095  */
00096 IMPORT_C gboolean g_str_equal (gconstpointer  v1,
00097                       gconstpointer  v2);
00098 IMPORT_C guint    g_str_hash  (gconstpointer  v);
00099 
00100 IMPORT_C gboolean g_int_equal (gconstpointer  v1,
00101                       gconstpointer  v2);
00102 IMPORT_C guint    g_int_hash  (gconstpointer  v);
00103 
00104 /* This "hash" function will just return the key's address as an
00105  * unsigned integer. Useful for hashing on plain addresses or
00106  * simple integer values.
00107  * Passing NULL into g_hash_table_new() as GHashFunc has the
00108  * same effect as passing g_direct_hash().
00109  */
00110 IMPORT_C guint    g_direct_hash  (gconstpointer  v) G_GNUC_CONST;
00111 IMPORT_C gboolean g_direct_equal (gconstpointer  v1,
00112                          gconstpointer  v2) G_GNUC_CONST;
00113 
00114 G_END_DECLS
00115 
00116 #endif /* __G_HASH_H__ */
00117 

Copyright © Nokia Corporation 2001-2008
Back to top