updates.
[silc.git] / lib / silcutil / silchashtable.h
1 /*
2
3   silchashtable.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 2001 Pekka Riikonen
8
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.
13   
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.
18
19 */
20
21 #ifndef SILCHASHTABLE_H
22 #define SILCHASHTABLE_H
23
24 /* Forward declarations */
25 typedef struct SilcHashTableStruct *SilcHashTable;
26
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);
30
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);
35
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);
40
41 /* Prototypes */
42 SilcHashTable silc_hash_table_alloc(uint32 table_size, 
43                                     SilcHashFunction hash,
44                                     SilcHashCompare compare,
45                                     SilcHashDestructor destructor);
46 void silc_hash_table_free(SilcHashTable ht);
47 uint32 silc_hash_table_size(SilcHashTable ht);
48 uint32 silc_hash_table_count(SilcHashTable ht);
49 void silc_hash_table_add(SilcHashTable ht, void *key, void *context);
50 void silc_hash_table_replace(SilcHashTable ht, void *key, void *context);
51 bool silc_hash_table_del(SilcHashTable ht, void *key);
52 bool silc_hash_table_find(SilcHashTable ht, void *key,
53                           void **ret_key, void **ret_context);
54 void silc_hash_table_rehash(SilcHashTable ht, uint32 new_size);
55
56 #endif