Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2001 - 2003 Pekka Riikonen
+ Copyright (C) 2001 - 2006 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
* 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
*
* SYNOPSIS
*
- * typedef bool (*SilcHashCompare)(void *key1, void *key2,
- * void *user_context);
+ * typedef SilcBool (*SilcHashCompare)(void *key1, void *key2,
+ * void *user_context);
*
* DESCRIPTION
*
* 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
*
* void *compare_user_context,
* SilcHashDestructor destructor,
* void *destructor_user_context,
- * bool auto_rehash);
+ * SilcBool auto_rehash);
*
* DESCRIPTION
*
void *compare_user_context,
SilcHashDestructor destructor,
void *destructor_user_context,
- bool auto_rehash);
+ SilcBool auto_rehash);
/****f* silcutil/SilcHashTableAPI/silc_hash_table_free
*
*
* SYNOPSIS
*
- * void silc_hash_table_add(SilcHashTable ht, void *key, void *context);
+ * SilcBool silc_hash_table_add(SilcHashTable ht, void *key, void *context);
*
* DESCRIPTION
*
* 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
*
* 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
*
* 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
*
* 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
*
* 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
*
* 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
*
- * bool silc_hash_table_get(SilcHashTableList *htl, void **key,
- * void **context);
+ * SilcBool silc_hash_table_get(SilcHashTableList *htl, void **key,
+ * void **context);
*
* DESCRIPTION
*
* Returns always the next entry in the hash table into the `key' and
- * `context' and TRUE. If this returns FALSE then there are no anymore
- * any entrys.
+ * `context' and TRUE. If this returns FALSE then there are no more
+ * entries.
+ *
+ * EXAMPLE
+ *
+ * SilcHashTableList htl;
+ * silc_hash_table_list(hash_table, &htl);
+ * while (silc_hash_table_get(&htl, (void *)&key, (void *)&context))
+ * ...
+ * silc_hash_table_list_reset(&htl);
*
***/
-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
*
* 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
*
* 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
*
* 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
*
* 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
*
* 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
*
* 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
*
- * bool 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);
+ * 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
*
* comparing function. If not provided the hash table's default is used.
*
***/
-bool 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);
+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
*