5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 #ifndef SILCHASHTABLE_H
22 #define SILCHASHTABLE_H
24 /* Forward declarations */
25 typedef struct SilcHashTableStruct *SilcHashTable;
27 /* A type for the hash function. This function is used to hash the
28 provided key value `key' and return the index for the hash table. */
29 typedef uint32 (*SilcHashFunction)(void *key, void *user_context);
31 /* A comparison funtion that is called to compare the two keys `key1' and
32 `key2'. If they are equal this must return TRUE or FALSE otherwise.
33 The application provides this function when allocating a new hash table. */
34 typedef bool (*SilcHashCompare)(void *key1, void *key2, void *user_context);
36 /* A destructor callback that the library will call to destroy the
37 `key' and `context'. The appliation provides the function when
38 allocating a new hash table. */
39 typedef void (*SilcHashDestructor)(void *key, void *context,
42 /* Foreach function. This is called when traversing the entrys in the
43 hash table using silc_hash_table_foreach. */
44 typedef void (*SilcHashForeach)(void *key, void *context, void *user_context);
47 SilcHashTable silc_hash_table_alloc(uint32 table_size,
48 SilcHashFunction hash,
49 void *hash_user_context,
50 SilcHashCompare compare,
51 void *compare_user_context,
52 SilcHashDestructor destructor,
53 void *destructor_user_context);
54 void silc_hash_table_free(SilcHashTable ht);
55 uint32 silc_hash_table_size(SilcHashTable ht);
56 uint32 silc_hash_table_count(SilcHashTable ht);
57 void silc_hash_table_add(SilcHashTable ht, void *key, void *context);
58 void silc_hash_table_add_ext(SilcHashTable ht, void *key, void *context,
59 SilcHashFunction hash, void *hash_user_context);
60 void silc_hash_table_replace(SilcHashTable ht, void *key, void *context);
61 bool silc_hash_table_del(SilcHashTable ht, void *key);
62 bool silc_hash_table_del_by_context(SilcHashTable ht, void *key,
64 bool silc_hash_table_find(SilcHashTable ht, void *key,
65 void **ret_key, void **ret_context);
66 bool silc_hash_table_find_all(SilcHashTable ht, void *key,
67 void ***ret_keys, void ***ret_contexts,
68 unsigned int *ret_count);
69 bool silc_hash_table_find_ext(SilcHashTable ht, void *key,
70 void **ret_key, void **ret_context,
71 SilcHashFunction hash,
72 void *hash_user_context,
73 SilcHashCompare compare,
74 void *compare_user_context);
75 bool silc_hash_table_find_all_ext(SilcHashTable ht, void *key,
76 void ***ret_keys, void ***ret_contexts,
77 unsigned int *ret_count,
78 SilcHashFunction hash,
79 void *hash_user_context,
80 SilcHashCompare compare,
81 void *compare_user_context);
82 void silc_hash_table_foreach(SilcHashTable ht, SilcHashForeach foreach,
84 void silc_hash_table_rehash(SilcHashTable ht, uint32 new_size);