2003-04-24 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-hash.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-hash.h Generic hash table utility (internal to D-BUS implementation)
3  * 
4  * Copyright (C) 2002  Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef DBUS_HASH_H
25 #define DBUS_HASH_H
26
27 #include <dbus/dbus-memory.h>
28 #include <dbus/dbus-types.h>
29
30 DBUS_BEGIN_DECLS;
31
32 /* The iterator is on the stack, but its real fields are
33  * hidden privately.
34  */
35 struct DBusHashIter
36 {
37   void *dummy1;
38   void *dummy2;
39   void *dummy3;
40   void *dummy4;
41   int   dummy5;
42   int   dummy6;
43 };
44
45 typedef struct DBusHashTable DBusHashTable;
46 typedef struct DBusHashIter  DBusHashIter;
47
48 /* Allowing an arbitrary function as with GLib
49  * would be nicer for a public API, but for
50  * an internal API this saves typing, we can add
51  * more whenever we feel like it.
52  */
53 typedef enum
54 {
55   DBUS_HASH_STRING,  /**< Hash keys are strings. */
56   DBUS_HASH_INT,     /**< Hash keys are integers. */
57   DBUS_HASH_POINTER, /**< Hash keys are pointers. */
58   DBUS_HASH_ULONG    /**< Hash keys are unsigned long. */
59 } DBusHashType;
60
61 DBusHashTable* _dbus_hash_table_new            (DBusHashType      type,
62                                                 DBusFreeFunction  key_free_function,
63                                                 DBusFreeFunction  value_free_function);
64 void           _dbus_hash_table_ref            (DBusHashTable    *table);
65 void           _dbus_hash_table_unref          (DBusHashTable    *table);
66 void           _dbus_hash_iter_init            (DBusHashTable    *table,
67                                                 DBusHashIter     *iter);
68 dbus_bool_t    _dbus_hash_iter_next            (DBusHashIter     *iter);
69 void           _dbus_hash_iter_remove_entry    (DBusHashIter     *iter);
70 void*          _dbus_hash_iter_get_value       (DBusHashIter     *iter);
71 void           _dbus_hash_iter_set_value       (DBusHashIter     *iter,
72                                                 void             *value);
73 int            _dbus_hash_iter_get_int_key     (DBusHashIter     *iter);
74 const char*    _dbus_hash_iter_get_string_key  (DBusHashIter     *iter);
75 unsigned long  _dbus_hash_iter_get_ulong_key   (DBusHashIter     *iter);
76 dbus_bool_t    _dbus_hash_iter_lookup          (DBusHashTable    *table,
77                                                 void             *key,
78                                                 dbus_bool_t       create_if_not_found,
79                                                 DBusHashIter     *iter);
80 void*          _dbus_hash_table_lookup_string  (DBusHashTable    *table,
81                                                 const char       *key);
82 void*          _dbus_hash_table_lookup_int     (DBusHashTable    *table,
83                                                 int               key);
84 void*          _dbus_hash_table_lookup_pointer (DBusHashTable    *table,
85                                                 void             *key);
86 void*          _dbus_hash_table_lookup_ulong   (DBusHashTable    *table,
87                                                 unsigned long     key);
88 dbus_bool_t    _dbus_hash_table_remove_string  (DBusHashTable    *table,
89                                                 const char       *key);
90 dbus_bool_t    _dbus_hash_table_remove_int     (DBusHashTable    *table,
91                                                 int               key);
92 dbus_bool_t    _dbus_hash_table_remove_pointer (DBusHashTable    *table,
93                                                 void             *key);
94 dbus_bool_t    _dbus_hash_table_remove_ulong   (DBusHashTable    *table,
95                                                 unsigned long     key);
96 dbus_bool_t    _dbus_hash_table_insert_string  (DBusHashTable    *table,
97                                                 char             *key,
98                                                 void             *value);
99 dbus_bool_t    _dbus_hash_table_insert_int     (DBusHashTable    *table,
100                                                 int               key,
101                                                 void             *value);
102 dbus_bool_t    _dbus_hash_table_insert_pointer (DBusHashTable    *table,
103                                                 void             *key,
104                                                 void             *value);
105 dbus_bool_t    _dbus_hash_table_insert_ulong   (DBusHashTable    *table,
106                                                 unsigned long     key,
107                                                 void             *value);
108 int            _dbus_hash_table_get_n_entries  (DBusHashTable    *table);
109
110
111 /* Preallocation */
112 typedef struct DBusPreallocatedHash DBusPreallocatedHash;
113
114 DBusPreallocatedHash *_dbus_hash_table_preallocate_entry          (DBusHashTable        *table);
115 void                  _dbus_hash_table_free_preallocated_entry    (DBusHashTable        *table,
116                                                                    DBusPreallocatedHash *preallocated);
117 void                  _dbus_hash_table_insert_string_preallocated (DBusHashTable        *table,
118                                                                    DBusPreallocatedHash *preallocated,
119                                                                    char                 *key,
120                                                                    void                 *value);
121
122
123 DBUS_END_DECLS;
124
125 #endif /* DBUS_HASH_H */