1 /* EINA - EFL data type library
2 * Copyright (C) 2002-2008 Carsten Haitzler, Gustavo Sverzut Barbieri,
3 * Vincent Torri, Jorge Luis Zapata Muga, Cedric Bail
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library;
17 * if not, see <http://www.gnu.org/licenses/>.
23 #include "eina_types.h"
28 typedef struct _Eina_Hash Eina_Hash;
29 typedef unsigned int (*Eina_Key_Length)(const void *key);
30 #define EINA_KEY_LENGTH(Function) ((Eina_Key_Length)Function)
31 typedef int (*Eina_Key_Cmp)(const void *key1, int key1_length,
32 const void *key2, int key2_length);
33 #define EINA_KEY_CMP(Function) ((Eina_Key_Cmp)Function)
34 typedef int (*Eina_Key_Hash)(const void *key, int key_length);
35 #define EINA_KEY_HASH(Function) ((Eina_Key_Hash)Function)
37 EAPI int eina_hash_init(void);
38 EAPI int eina_hash_shutdown(void);
40 EAPI Eina_Hash * eina_hash_new(Eina_Key_Length key_length_cb,
41 Eina_Key_Cmp key_cmp_cb,
42 Eina_Key_Hash key_hash_cb);
43 EAPI Eina_Hash * eina_hash_string_djb2_new(void);
44 EAPI Eina_Hash * eina_hash_string_superfast_new(void);
46 EAPI Eina_Bool eina_hash_add(Eina_Hash *hash, const void *key, const void *data);
47 EAPI Eina_Bool eina_hash_direct_add(Eina_Hash *hash, const void *key, const void *data);
48 EAPI Eina_Bool eina_hash_del(Eina_Hash *hash, const void *key, const void *data);
49 EAPI void * eina_hash_find(const Eina_Hash *hash, const void *key);
50 EAPI void * eina_hash_modify(Eina_Hash *hash, const void *key, const void *data);
51 EAPI void eina_hash_free(Eina_Hash *hash);
52 EAPI int eina_hash_population(const Eina_Hash *hash);
54 EAPI Eina_Bool eina_hash_add_by_hash(Eina_Hash *hash,
55 const void *key, int key_length, int key_hash,
57 EAPI Eina_Bool eina_hash_direct_add_by_hash(Eina_Hash *hash,
58 const void *key, int key_length, int key_hash,
60 EAPI Eina_Bool eina_hash_del_by_hash(Eina_Hash *hash,
61 const void *key, int key_length, int key_hash,
63 EAPI void * eina_hash_find_by_hash(const Eina_Hash *hash,
64 const void *key, int key_length, int key_hash);
65 EAPI void * eina_hash_modify_by_hash(Eina_Hash *hash,
66 const void *key, int key_length, int key_hash,
69 /* FIXME: Should go with iterator support. */
70 typedef Eina_Bool (*Eina_Foreach)(const Eina_Hash *hash, const void *key, void *data, void *fdata);
71 EAPI void eina_hash_foreach(const Eina_Hash *hash,
75 /* Paul Hsieh (http://www.azillionmonkeys.com/qed/hash.html) hash function
76 used by WebCore (http://webkit.org/blog/8/hashtables-part-2/) */
77 EAPI int eina_hash_superfast(const char *key, int len);
79 /* Hash function first reported by dan bernstein many years ago in comp.lang.c */
80 static inline int eina_hash_djb2(const char *key, int len);
82 #include "eina_inline_hash.x"
84 #endif /*EINA_HASH_H_*/