+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_size
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_table_size(SilcHashTable ht);
+ *
+ * DESCRIPTION
+ *
+ * Returns the size of the hash table. This is the true size of the
+ * hash table.
+ *
+ ***/
+SilcUInt32 silc_hash_table_size(SilcHashTable ht);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_count
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_table_count(SilcHashTable ht);
+ *
+ * DESCRIPTION
+ *
+ * Returns the number of the entires in the hash table. If there is more
+ * entries in the table thatn the size of the hash table calling the
+ * silc_hash_table_rehash is recommended.
+ *
+ ***/
+SilcUInt32 silc_hash_table_count(SilcHashTable ht);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_add
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_table_add(SilcHashTable ht, void *key, void *context);
+ *
+ * DESCRIPTION
+ *
+ * Adds new entry to the hash table. The `key' is hashed using the
+ * hash function and the both `key' and `context' will be saved to the
+ * hash table. This function quarantees that the entry is always added
+ * to the hash table reliably (it is collision resistant).
+ *
+ ***/
+SilcBool silc_hash_table_add(SilcHashTable ht, void *key, void *context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_set
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_table_set(SilcHashTable ht, void *key,
+ * void *context);
+ *
+ * DESCRIPTION
+ *
+ * Same as silc_hash_table_add but if the `key' already exists in the
+ * hash table the old key and the old context will be replaced with the
+ * `key' and the `context. The destructor function will be called for the
+ * replaced key and context.
+ *
+ ***/
+SilcBool silc_hash_table_set(SilcHashTable ht, void *key, void *context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_del
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_table_del(SilcHashTable ht, void *key);
+ *
+ * DESCRIPTION
+ *
+ * Removes the entry from the hash table by the provided `key'. This will
+ * call the destructor funtion for the found entry. Return TRUE if the
+ * entry was removed successfully and FALSE otherwise.
+ *
+ ***/
+SilcBool silc_hash_table_del(SilcHashTable ht, void *key);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_del_by_context
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_table_del_by_context(SilcHashTable ht, void *key,
+ * void *context);
+ *
+ * DESCRIPTION
+ *
+ * Same as silc_hash_table_del but verifies that the context associated
+ * with the `key' matches the `context'. This is handy to use with hash
+ * tables that may have duplicate keys. In that case the `context' may
+ * be used to check whether the correct entry is being deleted.
+ *
+ ***/
+SilcBool silc_hash_table_del_by_context(SilcHashTable ht, void *key,
+ void *context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_find
+ *
+ * SYNOPSIS
+ *
+ * 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.
+ * 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.
+ *
+ ***/
+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
+ *
+ * SilcBool silc_hash_table_find_by_context(SilcHashTable ht, void *key,
+ * void *context, void **ret_key);
+ *
+ * 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.
+ *
+ ***/
+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,
+ * void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * As the hash table is collision resistant it is possible to save duplicate
+ * keys to the hash table. This function can be used to find all keys
+ * and contexts from the hash table that are found using the `key'. The
+ * `foreach' is called for every found key. If no entries can be found
+ * the `foreach' will be called once with the context set NULL and
+ * `key' and `user_context' sent to the function.
+ *
+ * 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);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_foreach
+ *
+ * SYNOPSIS
+ *
+ * void silc_hash_table_foreach(SilcHashTable ht, SilcHashForeach foreach,
+ * void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * 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);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_rehash
+ *
+ * SYNOPSIS
+ *
+ * void silc_hash_table_rehash(SilcHashTable ht, SilcUInt32 new_size);
+ *
+ * DESCRIPTION
+ *
+ * Rehashs the hash table. The size of the new hash table is provided
+ * as `new_size'. If the `new_size' is zero then this routine will make
+ * the new table of a suitable size. Note that this operation may be
+ * very slow.
+ *
+ ***/
+void silc_hash_table_rehash(SilcHashTable ht, SilcUInt32 new_size);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_list
+ *
+ * SYNOPSIS
+ *
+ * void silc_hash_table_list(SilcHashTable ht, SilcHashTableList *htl);
+ *
+ * DESCRIPTION
+ *
+ * Prepares the `htl' SilcHashTableList sent as argument to be used in the
+ * 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
+ *
+ * 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 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);
+ *
+ ***/
+SilcBool silc_hash_table_get(SilcHashTableList *htl,
+ void **key, void **context);
+
+
+/* Extended hash table interface (same as above but with specific
+ hash and comparison functions). */
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_add_ext
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_table_add_ext(SilcHashTable ht, void *key,
+ * void *context,
+ * SilcHashFunction hash,
+ * void *hash_user_context);
+ *
+ * DESCRIPTION
+ *
+ * Adds new entry to the hash table. The `key' is hashed using the
+ * hash function and the both `key' and `context' will be saved to the
+ * hash table. This function quarantees that the entry is always added
+ * to the hash table reliably (it is collision resistant).
+ *
+ * The `hash' and `hash_user_context' are application specified hash
+ * function. If not provided the hash table's default is used.
+ *
+ ***/
+SilcBool silc_hash_table_add_ext(SilcHashTable ht,
+ void *key, void *context,
+ SilcHashFunction hash,
+ void *hash_user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_set_ext
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_table_set_ext(SilcHashTable ht, void *key,
+ * void *context,
+ * SilcHashFunction hash,
+ * void *hash_user_context);
+ *
+ * DESCRIPTION
+ *
+ * Same as silc_hash_table_add_ext but if the `key' already exists in the
+ * hash table the old key and the old context will be replaced with the
+ * `key' and the `context. The destructor function will be called for the
+ * replaced key and context.
+ *
+ * The `hash' and `hash_user_context' are application specified hash
+ * function. If not provided the hash table's default is used.
+ *
+ ***/
+SilcBool silc_hash_table_set_ext(SilcHashTable ht,
+ void *key, void *context,
+ SilcHashFunction hash,
+ void *hash_user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_del_ext
+ *
+ * SYNOPSIS
+ *
+ * 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
+ *
+ * Removes the entry from the hash table by the provided `key'. This will
+ * call the destructor funtion for the found entry. Return TRUE if the
+ * entry was removed successfully and FALSE otherwise.
+ *
+ * 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.
+ * The `destructor' and `destructor_user_context' are application
+ * specific destructor function.
+ *
+ ***/
+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
+ *
+ * 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
+ *
+ * Same as silc_hash_table_del but verifies that the context associated
+ * with the `key' matches the `context'. This is handy to use with hash
+ * tables that may have duplicate keys. In that case the `context' may
+ * be used to check whether the correct entry is being deleted.
+ *
+ * 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.
+ * The `destructor' and `destructor_user_context' are application
+ * specific destructor function.
+ *
+ ***/
+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
+ *
+ * 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.
+ * 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.
+ *
+ * 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_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,
+ * void *hash_user_context,
+ * SilcHashCompare compare,
+ * void *compare_user_context,
+ * SilcHashForeach foreach,
+ * void *foreach_user_context);
+ *
+ * DESCRIPTION
+ *
+ * As the hash table is collision resistant it is possible to save duplicate
+ * keys to the hash table. This function can be used to find all keys
+ * and contexts from the hash table that are found using the `key'. The
+ * `foreach' is called for every found key. If no entries can be found
+ * the `foreach' will be called once with the context set NULL and
+ * `key' and `user_context' sent to the function.
+ *
+ * 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.
+ *
+ * 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,
+ void *hash_user_context,
+ SilcHashCompare compare,
+ void *compare_user_context,
+ SilcHashForeach foreach,
+ void *foreach_user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_table_rehash_ext
+ *
+ * SYNOPSIS
+ *
+ * void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size,
+ * SilcHashFunction hash,
+ * void *hash_user_context);
+ *
+ * DESCRIPTION
+ *
+ * Rehashs the hash table. The size of the new hash table is provided
+ * as `new_size'. If the `new_size' is zero then this routine will make
+ * the new table of a suitable size. Note that this operation may be
+ * very slow.
+ *
+ * The `hash' and `hash_user_context' are application specified hash
+ * function. If not provided the hash table's default is used.
+ *
+ ***/
+void silc_hash_table_rehash_ext(SilcHashTable ht, SilcUInt32 new_size,
+ SilcHashFunction hash,
+ void *hash_user_context);
+
+/* Hash functions */
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_string
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_string(void *key, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Basic hash function to hash strings. May be used with the SilcHashTable.
+ * This uses Bob Jenkin's one-at-a-time (described in Wikipedia) hash
+ * function.
+ *
+ ***/
+SilcUInt32 silc_hash_string(void *key, void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_string_case
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_string_case(void *key, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Basic hash function to hash strings. May be used with the SilcHashTable.
+ * This ignores the string's case, ie. 'Foo' and 'foo' will hash to same
+ * value. This uses Bob Jenkin's one-at-a-time (described in Wikipedia)
+ * hash function.
+ *
+ ***/
+SilcUInt32 silc_hash_string_case(void *key, void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_utf8_string
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Basic has function to hash UTF-8 strings. May be used with the
+ * SilcHashTable. Used with identifier strings. The key is
+ * expected to be casefolded.
+ *
+ ***/
+SilcUInt32 silc_hash_utf8_string(void *key, void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_uint
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_uint(void *key, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Basic hash function to hash integers. May be used with the SilcHashTable.
+ * Comparison function is not needed, the SilcHashTable will automatically
+ * compare integer values.
+ *
+ ***/
+SilcUInt32 silc_hash_uint(void *key, void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_ptr
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_ptr(void *key, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Basic hash funtion to hash pointers. May be used with the SilcHashTable.
+ * Comparison function is not needed, the SilcHashTable will automatically
+ * compare pointer values.
+ *
+ ***/
+SilcUInt32 silc_hash_ptr(void *key, void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_data
+ *
+ * SYNOPSIS
+ *
+ * SilcUInt32 silc_hash_data(void *key, void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Hash binary data. The `user_context' is the data length. This uses Bob
+ * Jenkin's one-at-a-time (described in Wikipedia) hash function.
+ *
+ ***/
+SilcUInt32 silc_hash_data(void *key, void *user_context);
+
+/* Comparison functions */
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_string_compare
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_string_compare(void *key1, void *key2,
+ * void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Compares two strings. It may be used as SilcHashTable comparison
+ * function.
+ *
+ ***/
+SilcBool silc_hash_string_compare(void *key1, void *key2, void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_string_case_compare
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_string_case_compare(void *key1, void *key2,
+ * void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Compares two strings. This ignores the case while comparing. It may
+ * be used as SilcHashTable comparison function.
+ *
+ ***/
+SilcBool silc_hash_string_case_compare(void *key1, void *key2,
+ void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_utf8_compare
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_utf8_compare(void *key1, void *key2,
+ * void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Compares UTF-8 strings. Casefolded and NULL terminated strings are
+ * expected. May be used as SilcHashTable comparison function.
+ *
+ ***/
+SilcBool silc_hash_utf8_compare(void *key1, void *key2, void *user_context);
+
+/****f* silcutil/SilcHashTableAPI/silc_hash_data_compare
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_hash_data_compare(void *key1, void *key2,
+ * void *user_context);
+ *
+ * DESCRIPTION
+ *
+ * Compares binary data. May be used as SilcHashTable comparison function.
+ *
+ ***/
+SilcBool silc_hash_data_compare(void *key1, void *key2, void *user_context);