*/
-/****h* silcutil/SilcHashTableAPI
+/****h* silcutil/SILC Hash Table Interface
*
* DESCRIPTION
*
* an extended interface where caller can specify its own hash and comparison
* functions.
*
- * There are two ways tro traverse the entire hash table if this feature
+ * There are two ways to traverse the entire hash table if this feature
* is needed. There exists a foreach function that calls a foreach
* callback for each entry in the hash table. Other way is to use
* SilcHashTableList structure and traverse the hash table inside while()
struct SilcHashTableListStruct {
SilcHashTable ht;
void *entry;
- uint32 index;
- bool auto_rehash;
+ unsigned int index : 31;
+ unsigned int auto_rehash : 1;
};
/***/
*
* SYNOPSIS
*
- * typedef uint32 (*SilcHashFunction)(void *key, void *user_context);
+ * typedef SilcUInt32 (*SilcHashFunction)(void *key, void *user_context);
*
* DESCRIPTION
*
* to the callback.
*
***/
-typedef uint32 (*SilcHashFunction)(void *key, void *user_context);
+typedef SilcUInt32 (*SilcHashFunction)(void *key, void *user_context);
/****f* silcutil/SilcHashTableAPI/SilcHashCompare
*
* DESCRIPTION
*
* A destructor callback that the library will call to destroy the
- * `key' and `context'. The appliation provides the function when
+ * `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.
*
*
* 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,
* 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,
*
* SYNOPSIS
*
- * uint32 silc_hash_table_size(SilcHashTable ht);
+ * SilcUInt32 silc_hash_table_size(SilcHashTable ht);
*
* DESCRIPTION
*
* 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
*
* 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
*
bool 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);
+ *
+ * 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.
+ *
+ ***/
+bool silc_hash_table_find_by_context(SilcHashTable ht, void *key,
+ void *context, void **ret_key);
+
/****f* silcutil/SilcHashTableAPI/silc_hash_table_find_foreach
*
* SYNOPSIS
* 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.
+ * `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 list,
+ * 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.
*
*
* NOTES
*
- * The hash table will not be rehashed during the traversing of the list,
+ * 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.
*
*
* SYNOPSIS
*
- * void silc_hash_table_rehash(SilcHashTable ht, uint32 new_size);
+ * void silc_hash_table_rehash(SilcHashTable ht, SilcUInt32 new_size);
*
* DESCRIPTION
*
* 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
*
* 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.
+ * `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.
*
* NOTES
*
- * The hash table will not be rehashed during the traversing of the list,
+ * 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.
*
*
* 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);
*
* 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);