X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilchashtable.h;h=2b186c957301757bb095b634dfc95d7aa0b58c1d;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=bdee0e10c69ffdf6c70c8e360612b611993f7b33;hpb=ab530adb8aab5b1aa48f66f3cd0dd6be509dd6de;p=silc.git diff --git a/lib/silcutil/silchashtable.h b/lib/silcutil/silchashtable.h index bdee0e10..2b186c95 100644 --- a/lib/silcutil/silchashtable.h +++ b/lib/silcutil/silchashtable.h @@ -1,16 +1,15 @@ /* - silchashtable.h - + silchashtable.h + Author: Pekka Riikonen - - Copyright (C) 2001 Pekka Riikonen - + + Copyright (C) 2001 - 2002 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -80,6 +79,7 @@ typedef struct SilcHashTableStruct *SilcHashTable; * silc_hash_table_list(hash_table, &htl); * while (silc_hash_table_get(&htl, (void *)&key, (void *)&context)) * ... + * silc_hash_table_list_reset(&htl); * * SOURCE */ @@ -89,7 +89,8 @@ typedef struct SilcHashTableListStruct SilcHashTableList; struct SilcHashTableListStruct { SilcHashTable ht; void *entry; - uint32 index; + SilcUInt32 index; + bool auto_rehash; }; /***/ @@ -97,7 +98,7 @@ struct SilcHashTableListStruct { * * SYNOPSIS * - * typedef uint32 (*SilcHashFunction)(void *key, void *user_context); + * typedef SilcUInt32 (*SilcHashFunction)(void *key, void *user_context); * * DESCRIPTION * @@ -107,7 +108,7 @@ struct SilcHashTableListStruct { * to the callback. * ***/ -typedef uint32 (*SilcHashFunction)(void *key, void *user_context); +typedef SilcUInt32 (*SilcHashFunction)(void *key, void *user_context); /****f* silcutil/SilcHashTableAPI/SilcHashCompare * @@ -167,7 +168,7 @@ typedef void (*SilcHashForeach)(void *key, void *context, void *user_context); * * SYNOPSIS * - * SilcHashTable silc_hash_table_alloc(uint32 table_size, + * SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, * SilcHashFunction hash, * void *hash_user_context, * SilcHashCompare compare, @@ -187,7 +188,7 @@ typedef void (*SilcHashForeach)(void *key, void *context, void *user_context); * are optional. * ***/ -SilcHashTable silc_hash_table_alloc(uint32 table_size, +SilcHashTable silc_hash_table_alloc(SilcUInt32 table_size, SilcHashFunction hash, void *hash_user_context, SilcHashCompare compare, @@ -214,7 +215,7 @@ void silc_hash_table_free(SilcHashTable ht); * * SYNOPSIS * - * uint32 silc_hash_table_size(SilcHashTable ht); + * SilcUInt32 silc_hash_table_size(SilcHashTable ht); * * DESCRIPTION * @@ -222,13 +223,13 @@ void silc_hash_table_free(SilcHashTable ht); * hash table. * ***/ -uint32 silc_hash_table_size(SilcHashTable ht); +SilcUInt32 silc_hash_table_size(SilcHashTable ht); /****f* silcutil/SilcHashTableAPI/silc_hash_table_count * * SYNOPSIS * - * uint32 silc_hash_table_count(SilcHashTable ht); + * SilcUInt32 silc_hash_table_count(SilcHashTable ht); * * DESCRIPTION * @@ -237,7 +238,7 @@ uint32 silc_hash_table_size(SilcHashTable ht); * silc_hash_table_rehash is recommended. * ***/ -uint32 silc_hash_table_count(SilcHashTable ht); +SilcUInt32 silc_hash_table_count(SilcHashTable ht); /****f* silcutil/SilcHashTableAPI/silc_hash_table_add * @@ -338,6 +339,12 @@ bool silc_hash_table_find(SilcHashTable ht, void *key, * and contexts from the hash table that are found using the `key'. The * `foreach' is called for every found key. * + * NOTES + * + * The hash table will not be rehashed during the traversing of the table, + * even if the table was marked as auto rehashable. The caller also must + * not call silc_hash_table_rehash while traversing the table. + * ***/ void silc_hash_table_find_foreach(SilcHashTable ht, void *key, SilcHashForeach foreach, void *user_context); @@ -354,6 +361,12 @@ void silc_hash_table_find_foreach(SilcHashTable ht, void *key, * Traverse all entrys in the hash table and call the `foreach' for * every entry with the `user_context' context. * + * NOTES + * + * The hash table will not be rehashed during the traversing of the table, + * even if the table was marked as auto rehashable. The caller also must + * not call silc_hash_table_rehash while traversing the table. + * ***/ void silc_hash_table_foreach(SilcHashTable ht, SilcHashForeach foreach, void *user_context); @@ -362,7 +375,7 @@ void silc_hash_table_foreach(SilcHashTable ht, SilcHashForeach foreach, * * SYNOPSIS * - * void silc_hash_table_rehash(SilcHashTable ht, uint32 new_size); + * void silc_hash_table_rehash(SilcHashTable ht, SilcUInt32 new_size); * * DESCRIPTION * @@ -372,7 +385,7 @@ void silc_hash_table_foreach(SilcHashTable ht, SilcHashForeach foreach, * very slow. * ***/ -void silc_hash_table_rehash(SilcHashTable ht, uint32 new_size); +void silc_hash_table_rehash(SilcHashTable ht, SilcUInt32 new_size); /****f* silcutil/SilcHashTableAPI/silc_hash_table_list * @@ -383,11 +396,33 @@ void silc_hash_table_rehash(SilcHashTable ht, uint32 new_size); * DESCRIPTION * * Prepares the `htl' SilcHashTableList sent as argument to be used in the - * hash table traversing with the silc_hash_table_get. + * hash table traversing with the silc_hash_table_get. After the hash + * table traversing is completed the silc_hash_table_list_reset must be + * called. + * + * NOTES + * + * The hash table will not be rehashed during the traversing of the list, + * even if the table was marked as auto rehashable. The caller also must + * not call silc_hash_table_rehash while traversing the list. * ***/ void silc_hash_table_list(SilcHashTable ht, SilcHashTableList *htl); +/****f* silcutil/SilcHashTableAPI/silc_hash_table_list_reset + * + * SYNOPSIS + * + * void silc_hash_table_list_reset(SilcHashTableList *htl); + * + * DESCRIPTION + * + * Resets the `htl' SilcHashTableList. This must be called after the + * hash table traversing is completed. + * + ***/ +void silc_hash_table_list_reset(SilcHashTableList *htl); + /****f* silcutil/SilcHashTableAPI/silc_hash_table_get * * SYNOPSIS @@ -581,6 +616,12 @@ bool silc_hash_table_find_ext(SilcHashTable ht, void *key, * The `compare' and `compare_user_context' are application specified * comparing function. If not provided the hash table's default is used. * + * NOTES + * + * The hash table will not be rehashed during the traversing of the table, + * even if the table was marked as auto rehashable. The caller also must + * not call silc_hash_table_rehash while traversing the table. + * ***/ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key, SilcHashFunction hash, @@ -594,7 +635,7 @@ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key, * * SYNOPSIS * - * void silc_hash_table_rehash_ext(SilcHashTable ht, uint32 new_size, + * void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size, * SilcHashFunction hash, * void *hash_user_context); * @@ -609,7 +650,7 @@ void silc_hash_table_find_foreach_ext(SilcHashTable ht, void *key, * function. If not provided the hash table's default is used. * ***/ -void silc_hash_table_rehash_ext(SilcHashTable ht, uint32 new_size, +void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size, SilcHashFunction hash, void *hash_user_context);