2 /* EINA - EFL data type library
3 * Copyright (C) 2002-2008 Carsten Haitzler, Gustavo Sverzut Barbieri,
4 * Vincent Torri, Jorge Luis Zapata Muga, Cedric Bail
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library;
18 * if not, see <http://www.gnu.org/licenses/>.
24 #include "eina_types.h"
25 #include "eina_iterator.h"
28 * @addtogroup Eina_Data_Types_Group Data Types
34 * @addtogroup Eina_Containers_Group Containers
40 * @defgroup Eina_Hash_Group Hash Table
45 typedef struct _Eina_Hash Eina_Hash;
46 typedef struct _Eina_Hash_Tuple Eina_Hash_Tuple;
47 struct _Eina_Hash_Tuple
52 unsigned int key_length;
55 typedef unsigned int (*Eina_Key_Length)(const void *key);
56 #define EINA_KEY_LENGTH(Function) ((Eina_Key_Length)Function)
57 typedef int (*Eina_Key_Cmp)(const void *key1, int key1_length,
58 const void *key2, int key2_length);
59 #define EINA_KEY_CMP(Function) ((Eina_Key_Cmp)Function)
60 typedef int (*Eina_Key_Hash)(const void *key, int key_length);
61 #define EINA_KEY_HASH(Function) ((Eina_Key_Hash)Function)
64 eina_hash_new(Eina_Key_Length key_length_cb,
72 buckets_power_size) EINA_MALLOC EINA_WARN_UNUSED_RESULT
73 EINA_ARG_NONNULL(2, 3);
75 eina_hash_string_djb2_new(
76 Eina_Free_Cb data_free_cb);
78 eina_hash_string_superfast_new(
79 Eina_Free_Cb data_free_cb);
81 eina_hash_string_small_new(
82 Eina_Free_Cb data_free_cb);
85 Eina_Free_Cb data_free_cb);
88 Eina_Free_Cb data_free_cb);
90 eina_hash_pointer_new(
91 Eina_Free_Cb data_free_cb);
93 eina_hash_stringshared_new(
94 Eina_Free_Cb data_free_cb);
100 const void *data) EINA_ARG_NONNULL(1, 2, 3);
102 eina_hash_direct_add(
105 const void *data) EINA_ARG_NONNULL(1, 2, 3);
110 const void *data) EINA_ARG_NONNULL(1);
113 const Eina_Hash *hash,
114 const void *key) EINA_ARG_NONNULL(1, 2);
119 const void *data) EINA_ARG_NONNULL(1, 2, 3);
124 const void *data) EINA_ARG_NONNULL(1, 2, 3);
127 Eina_Hash *hash) EINA_ARG_NONNULL(1);
129 eina_hash_free_buckets(
130 Eina_Hash *hash) EINA_ARG_NONNULL(1);
132 eina_hash_population(
133 const Eina_Hash *hash) EINA_ARG_NONNULL(1);
136 eina_hash_add_by_hash(
143 void *data) EINA_ARG_NONNULL(1, 2, 5);
145 eina_hash_direct_add_by_hash(Eina_Hash *hash,
151 void *data) EINA_ARG_NONNULL(1, 2, 5);
154 eina_hash_del_by_key_hash(Eina_Hash *hash,
157 int key_hash) EINA_ARG_NONNULL(1, 2);
160 eina_hash_del_by_key(Eina_Hash *hash, const void *key) EINA_ARG_NONNULL(1, 2);
162 eina_hash_del_by_data(Eina_Hash *hash, const void *data) EINA_ARG_NONNULL(1, 2);
165 eina_hash_del_by_hash(Eina_Hash *hash,
171 void *data) EINA_ARG_NONNULL(1);
173 eina_hash_find_by_hash(const Eina_Hash *hash,
177 int key_hash) EINA_ARG_NONNULL(1, 2);
179 eina_hash_modify_by_hash(Eina_Hash *hash,
185 void *data) EINA_ARG_NONNULL(1, 2, 5);
188 eina_hash_iterator_key_new(
189 const Eina_Hash *hash) EINA_MALLOC EINA_ARG_NONNULL(1)
190 EINA_WARN_UNUSED_RESULT;
192 eina_hash_iterator_data_new(
193 const Eina_Hash *hash) EINA_MALLOC EINA_ARG_NONNULL(
194 1) EINA_WARN_UNUSED_RESULT;
196 eina_hash_iterator_tuple_new(
197 const Eina_Hash *hash) EINA_MALLOC EINA_ARG_NONNULL(
198 1) EINA_WARN_UNUSED_RESULT;
200 typedef Eina_Bool (*Eina_Hash_Foreach)(const Eina_Hash *hash, const void *key,
201 void *data, void *fdata);
203 eina_hash_foreach(const Eina_Hash *hash,
207 void *fdata) EINA_ARG_NONNULL(1, 2);
209 /* Paul Hsieh (http://www.azillionmonkeys.com/qed/hash.html) hash function
210 used by WebCore (http://webkit.org/blog/8/hashtables-part-2/) */
212 eina_hash_superfast(const char *key, int len) EINA_ARG_NONNULL(1);
214 /* Hash function first reported by dan bernstein many years ago in comp.lang.c */
216 eina_hash_djb2(const char *key, int len) EINA_ARG_NONNULL(1);
218 eina_hash_djb2_len(const char *key, int *plen) EINA_ARG_NONNULL(1, 2);
220 /* Hash function from http://www.concentric.net/~Ttwang/tech/inthash.htm */
222 eina_hash_int32(const unsigned int *pkey, int len) EINA_ARG_NONNULL(1);
224 eina_hash_int64(const unsigned long int *pkey, int len) EINA_ARG_NONNULL(1);
226 #include "eina_inline_hash.x"
240 #endif /*EINA_HASH_H_*/