X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilchashtable.h;h=687170f9a4585a7efb9a9b99a9d8754dc5900da7;hb=40f8443d8d3a6577336ee66d18e04d9ac4d956bb;hp=478ea184a6a23128f8d710c899bb26a4de2a151b;hpb=413da0f8686910f5e627393157566ae729ca99c4;p=silc.git diff --git a/lib/silcutil/silchashtable.h b/lib/silcutil/silchashtable.h index 478ea184..687170f9 100644 --- a/lib/silcutil/silchashtable.h +++ b/lib/silcutil/silchashtable.h @@ -1,10 +1,10 @@ /* - silchashtable.h + silchashtable.h Author: Pekka Riikonen - Copyright (C) 2001 - 2002 Pekka Riikonen + Copyright (C) 2001 - 2005 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,6 +39,9 @@ * SilcHashTableList structure and traverse the hash table inside while() * using the list structure. Both are equally fast. * + * The hash table is not thread safe. If same hash table context is used in + * multi thread environment concurrency control must be employed. + * ***/ #ifndef SILCHASHTABLE_H @@ -47,7 +50,7 @@ /****s* silcutil/SilcHashTableAPI/SilcHashTable * * NAME - * + * * typedef struct SilcHashTableStruct *SilcHashTable; * * DESCRIPTION @@ -63,13 +66,13 @@ typedef struct SilcHashTableStruct *SilcHashTable; /****s* silcutil/SilcHashTableAPI/SilcHashTableList * * NAME - * + * * typedef struct SilcHashTableListStruct SilcHashTableList; * * DESCRIPTION * * This structure is used to tarverse the hash table. This structure - * is given as argument to the silc_hash_table_list function to + * is given as argument to the silc_hash_table_list function to * initialize it and then used to traverse the hash table with the * silc_hash_table_get function. It needs not be allocated or freed. * @@ -114,8 +117,8 @@ typedef SilcUInt32 (*SilcHashFunction)(void *key, void *user_context); * * SYNOPSIS * - * typedef bool (*SilcHashCompare)(void *key1, void *key2, - * void *user_context); + * typedef SilcBool (*SilcHashCompare)(void *key1, void *key2, + * void *user_context); * * DESCRIPTION * @@ -126,31 +129,32 @@ typedef SilcUInt32 (*SilcHashFunction)(void *key, void *user_context); * to the callback. * ***/ -typedef bool (*SilcHashCompare)(void *key1, void *key2, void *user_context); +typedef SilcBool (*SilcHashCompare)(void *key1, void *key2, + void *user_context); /****f* silcutil/SilcHashTableAPI/SilcHashDestructor * * SYNOPSIS * - * typedef void (*SilcHashDestructor)(void *key, void *context, + * typedef void (*SilcHashDestructor)(void *key, void *context, * void *user_context); * * DESCRIPTION * - * A destructor callback that the library will call to destroy the + * A destructor callback that the library will call to destroy the * `key' and `context'. The application provides the function when * allocating a new hash table. The `user_context' is application * specific context and is delivered to the callback. * ***/ -typedef void (*SilcHashDestructor)(void *key, void *context, +typedef void (*SilcHashDestructor)(void *key, void *context, void *user_context); /****f* silcutil/SilcHashTableAPI/SilcHashForeach * * SYNOPSIS * - * typedef void (*SilcHashForeach)(void *key, void *context, + * typedef void (*SilcHashForeach)(void *key, void *context, * void *user_context); * * DESCRIPTION @@ -168,14 +172,14 @@ typedef void (*SilcHashForeach)(void *key, void *context, void *user_context); * * SYNOPSIS * - * SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, + * SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, * SilcHashFunction hash, * void *hash_user_context, * SilcHashCompare compare, * void *compare_user_context, * SilcHashDestructor destructor, * void *destructor_user_context, - * bool auto_rehash); + * SilcBool auto_rehash); * * DESCRIPTION * @@ -188,14 +192,14 @@ typedef void (*SilcHashForeach)(void *key, void *context, void *user_context); * are optional. * ***/ -SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, +SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, SilcHashFunction hash, void *hash_user_context, SilcHashCompare compare, void *compare_user_context, SilcHashDestructor destructor, void *destructor_user_context, - bool auto_rehash); + SilcBool auto_rehash); /****f* silcutil/SilcHashTableAPI/silc_hash_table_free * @@ -244,7 +248,7 @@ SilcUInt32 silc_hash_table_count(SilcHashTable ht); * * SYNOPSIS * - * void silc_hash_table_add(SilcHashTable ht, void *key, void *context); + * SilcBool silc_hash_table_add(SilcHashTable ht, void *key, void *context); * * DESCRIPTION * @@ -254,13 +258,14 @@ SilcUInt32 silc_hash_table_count(SilcHashTable ht); * to the hash table reliably (it is collision resistant). * ***/ -void silc_hash_table_add(SilcHashTable ht, void *key, void *context); +SilcBool silc_hash_table_add(SilcHashTable ht, void *key, void *context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_replace * * SYNOPSIS * - * void silc_hash_table_replace(SilcHashTable ht, void *key, void *context); + * SilcBool silc_hash_table_replace(SilcHashTable ht, void *key, + * void *context); * * DESCRIPTION * @@ -270,13 +275,13 @@ void silc_hash_table_add(SilcHashTable ht, void *key, void *context); * replaced key and context. * ***/ -void silc_hash_table_replace(SilcHashTable ht, void *key, void *context); +SilcBool silc_hash_table_replace(SilcHashTable ht, void *key, void *context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_del * * SYNOPSIS * - * bool silc_hash_table_del(SilcHashTable ht, void *key); + * SilcBool silc_hash_table_del(SilcHashTable ht, void *key); * * DESCRIPTION * @@ -285,14 +290,14 @@ void silc_hash_table_replace(SilcHashTable ht, void *key, void *context); * entry was removed successfully and FALSE otherwise. * ***/ -bool silc_hash_table_del(SilcHashTable ht, void *key); +SilcBool silc_hash_table_del(SilcHashTable ht, void *key); /****f* silcutil/SilcHashTableAPI/silc_hash_table_del_by_context * * SYNOPSIS * - * bool silc_hash_table_del_by_context(SilcHashTable ht, void *key, - * void *context); + * SilcBool silc_hash_table_del_by_context(SilcHashTable ht, void *key, + * void *context); * * DESCRIPTION * @@ -302,34 +307,34 @@ bool silc_hash_table_del(SilcHashTable ht, void *key); * be used to check whether the correct entry is being deleted. * ***/ -bool silc_hash_table_del_by_context(SilcHashTable ht, void *key, - void *context); +SilcBool silc_hash_table_del_by_context(SilcHashTable ht, void *key, + void *context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_find * * SYNOPSIS * - * bool silc_hash_table_find(SilcHashTable ht, void *key, - * void **ret_key, void **ret_context); + * SilcBool silc_hash_table_find(SilcHashTable ht, void *key, + * void **ret_key, void **ret_context); * * DESCRIPTION * * Finds the entry in the hash table by the provided `key' as fast as - * possible. Return TRUE if the entry was found and FALSE otherwise. + * possible. Return TRUE if the entry was found and FALSE otherwise. * The found entry is returned to the `ret_key' and `ret_context', * respectively. If the `ret_key and `ret_context' are NULL then this * maybe used only to check whether given key exists in the table. * ***/ -bool silc_hash_table_find(SilcHashTable ht, void *key, - void **ret_key, void **ret_context); +SilcBool silc_hash_table_find(SilcHashTable ht, void *key, + void **ret_key, void **ret_context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_find_by_context * * SYNOPSIS * - * bool silc_hash_table_find_by_context(SilcHashTable ht, void *key, - * void *context, void **ret_key); + * SilcBool silc_hash_table_find_by_context(SilcHashTable ht, void *key, + * void *context, void **ret_key); * * DESCRIPTION * @@ -342,15 +347,15 @@ bool silc_hash_table_find(SilcHashTable ht, void *key, * the caller already knows the context. * ***/ -bool silc_hash_table_find_by_context(SilcHashTable ht, void *key, - void *context, void **ret_key); +SilcBool silc_hash_table_find_by_context(SilcHashTable ht, void *key, + void *context, void **ret_key); /****f* silcutil/SilcHashTableAPI/silc_hash_table_find_foreach * * SYNOPSIS * * void silc_hash_table_find_foreach(SilcHashTable ht, void *key, - * SilcHashForeach foreach, + * SilcHashForeach foreach, * void *user_context); * * DESCRIPTION @@ -450,8 +455,8 @@ void silc_hash_table_list_reset(SilcHashTableList *htl); * * SYNOPSIS * - * bool silc_hash_table_get(SilcHashTableList *htl, void **key, - * void **context); + * SilcBool silc_hash_table_get(SilcHashTableList *htl, void **key, + * void **context); * * DESCRIPTION * @@ -460,7 +465,8 @@ void silc_hash_table_list_reset(SilcHashTableList *htl); * any entrys. * ***/ -bool silc_hash_table_get(SilcHashTableList *htl, void **key, void **context); +SilcBool silc_hash_table_get(SilcHashTableList *htl, + void **key, void **context); /* Extended hash table interface (same as above but with specific @@ -470,9 +476,10 @@ bool silc_hash_table_get(SilcHashTableList *htl, void **key, void **context); * * SYNOPSIS * - * void silc_hash_table_add_ext(SilcHashTable ht, void *key, void *context, - * SilcHashFunction hash, - * void *hash_user_context); + * SilcBool silc_hash_table_add_ext(SilcHashTable ht, void *key, + * void *context, + * SilcHashFunction hash, + * void *hash_user_context); * * DESCRIPTION * @@ -485,17 +492,19 @@ bool silc_hash_table_get(SilcHashTableList *htl, void **key, void **context); * function. If not provided the hash table's default is used. * ***/ -void silc_hash_table_add_ext(SilcHashTable ht, void *key, void *context, - SilcHashFunction hash, void *hash_user_context); +SilcBool silc_hash_table_add_ext(SilcHashTable ht, + void *key, void *context, + SilcHashFunction hash, + void *hash_user_context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_replace_ext * * SYNOPSIS * - * void silc_hash_table_replace_ext(SilcHashTable ht, void *key, - * void *context, - * SilcHashFunction hash, - * void *hash_user_context); + * SilcBool silc_hash_table_replace_ext(SilcHashTable ht, void *key, + * void *context, + * SilcHashFunction hash, + * void *hash_user_context); * * DESCRIPTION * @@ -508,21 +517,22 @@ void silc_hash_table_add_ext(SilcHashTable ht, void *key, void *context, * function. If not provided the hash table's default is used. * ***/ -void silc_hash_table_replace_ext(SilcHashTable ht, void *key, void *context, - SilcHashFunction hash, - void *hash_user_context); +SilcBool silc_hash_table_replace_ext(SilcHashTable ht, + void *key, void *context, + SilcHashFunction hash, + void *hash_user_context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_del_ext * * SYNOPSIS * - * bool silc_hash_table_del_ext(SilcHashTable ht, void *key, - * SilcHashFunction hash, - * void *hash_user_context, - * SilcHashCompare compare, - * void *compare_user_context, - * SilcHashDestructor destructor, - * void *destructor_user_context); + * SilcBool silc_hash_table_del_ext(SilcHashTable ht, void *key, + * SilcHashFunction hash, + * void *hash_user_context, + * SilcHashCompare compare, + * void *compare_user_context, + * SilcHashDestructor destructor, + * void *destructor_user_context); * * DESCRIPTION * @@ -538,26 +548,27 @@ void silc_hash_table_replace_ext(SilcHashTable ht, void *key, void *context, * specific destructor function. * ***/ -bool silc_hash_table_del_ext(SilcHashTable ht, void *key, - SilcHashFunction hash, - void *hash_user_context, - SilcHashCompare compare, - void *compare_user_context, - SilcHashDestructor destructor, - void *destructor_user_context); +SilcBool silc_hash_table_del_ext(SilcHashTable ht, void *key, + SilcHashFunction hash, + void *hash_user_context, + SilcHashCompare compare, + void *compare_user_context, + SilcHashDestructor destructor, + void *destructor_user_context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_del_by_context_ext * * SYNOPSIS * - * bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key, - * void *context, - * SilcHashFunction hash, - * void *hash_user_context, - * SilcHashCompare compare, - * void *compare_user_context, - * SilcHashDestructor destructor, - * void *destructor_user_context); + * SilcBool + * silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key, + * void *context, + * SilcHashFunction hash, + * void *hash_user_context, + * SilcHashCompare compare, + * void *compare_user_context, + * SilcHashDestructor destructor, + * void *destructor_user_context); * * DESCRIPTION * @@ -574,30 +585,30 @@ bool silc_hash_table_del_ext(SilcHashTable ht, void *key, * specific destructor function. * ***/ -bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key, - void *context, - SilcHashFunction hash, - void *hash_user_context, - SilcHashCompare compare, - void *compare_user_context, - SilcHashDestructor destructor, - void *destructor_user_context); +SilcBool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key, + void *context, + SilcHashFunction hash, + void *hash_user_context, + SilcHashCompare compare, + void *compare_user_context, + SilcHashDestructor destructor, + void *destructor_user_context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_find_ext * * SYNOPSIS * - * bool silc_hash_table_find_ext(SilcHashTable ht, void *key, - * void **ret_key, void **ret_context, - * SilcHashFunction hash, - * void *hash_user_context, - * SilcHashCompare compare, - * void *compare_user_context); + * SilcBool silc_hash_table_find_ext(SilcHashTable ht, void *key, + * void **ret_key, void **ret_context, + * SilcHashFunction hash, + * void *hash_user_context, + * SilcHashCompare compare, + * void *compare_user_context); * * DESCRIPTION * * Finds the entry in the hash table by the provided `key' as fast as - * possible. Return TRUE if the entry was found and FALSE otherwise. + * possible. Return TRUE if the entry was found and FALSE otherwise. * The found entry is returned to the `ret_key' and `ret_context', * respectively. If the `ret_key and `ret_context' are NULL then this * maybe used only to check whether given key exists in the table. @@ -608,23 +619,58 @@ bool silc_hash_table_del_by_context_ext(SilcHashTable ht, void *key, * comparing function. If not provided the hash table's default is used. * ***/ -bool silc_hash_table_find_ext(SilcHashTable ht, void *key, - void **ret_key, void **ret_context, - SilcHashFunction hash, - void *hash_user_context, - SilcHashCompare compare, - void *compare_user_context); +SilcBool silc_hash_table_find_ext(SilcHashTable ht, void *key, + void **ret_key, void **ret_context, + SilcHashFunction hash, + void *hash_user_context, + SilcHashCompare compare, + void *compare_user_context); + +/****f* silcutil/SilcHashTableAPI/silc_hash_table_find_by_context_ext + * + * SYNOPSIS + * + * SilcBool + * silc_hash_table_find_by_context_ext(SilcHashTable ht, void *key, + * void *context, void **ret_key, + * SilcHashFunction hash, + * void *hash_user_context, + * SilcHashCompare compare, + * void *compare_user_context); + * + * DESCRIPTION + * + * Finds the entry in the hash table by the provided `key' and + * `context' as fast as possible. This is handy function when there + * can be multiple same keys in the hash table. By using this function + * the specific key with specific context can be found. Return + * TRUE if the entry with the key and context was found and FALSE + * otherwise. The function returns only the key to `ret_key' since + * the caller already knows the context. + * + * The `hash' and `hash_user_context' are application specified hash + * function. If not provided the hash table's default is used. + * The `compare' and `compare_user_context' are application specified + * comparing function. If not provided the hash table's default is used. + * + ***/ +SilcBool silc_hash_table_find_by_context_ext(SilcHashTable ht, void *key, + void *context, void **ret_key, + SilcHashFunction hash, + void *hash_user_context, + SilcHashCompare compare, + void *compare_user_context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_find_foreach_ext * * SYNOPSIS * * void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key, - * SilcHashFunction hash, + * SilcHashFunction hash, * void *hash_user_context, - * SilcHashCompare compare, + * SilcHashCompare compare, * void *compare_user_context, - * SilcHashForeach foreach, + * SilcHashForeach foreach, * void *foreach_user_context); * * DESCRIPTION @@ -649,11 +695,11 @@ bool silc_hash_table_find_ext(SilcHashTable ht, void *key, * ***/ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key, - SilcHashFunction hash, + SilcHashFunction hash, void *hash_user_context, - SilcHashCompare compare, + SilcHashCompare compare, void *compare_user_context, - SilcHashForeach foreach, + SilcHashForeach foreach, void *foreach_user_context); /****f* silcutil/SilcHashTableAPI/silc_hash_table_rehash_ext @@ -661,7 +707,7 @@ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key, * SYNOPSIS * * void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size, - * SilcHashFunction hash, + * SilcHashFunction hash, * void *hash_user_context); * * DESCRIPTION @@ -676,7 +722,7 @@ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key, * ***/ void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size, - SilcHashFunction hash, + SilcHashFunction hash, void *hash_user_context); #endif