📄 ght_hash_table.h.in
字号:
* * @param p_ht the hash table to set rehashing for. * @param b_rehash TRUE if rehashing should be used or FALSE if it * should not be used. */void ght_set_rehash(ght_hash_table_t *p_ht, int b_rehash);/** * Get the size (the number of items) of the hash table. * * @param p_ht the hash table to get the size for. * * @return the number of items in the hash table. */unsigned int ght_size(ght_hash_table_t *p_ht);/** * Get the table size (the number of buckets) of the hash table. * * @param p_ht the hash table to get the table size for. * * @return the number of buckets in the hash table. */unsigned int ght_table_size(ght_hash_table_t *p_ht);/** * Insert an entry into the hash table. Prior to inserting anything, * make sure that the table is created with ght_create(). If an * element with the same key as this one already exists in the table, * the insertion will fail and -1 is returned. * * A typical example is shown below, where the string "blabla" is used * as a key for the integer 15. * * <PRE> * ght_hash_table_t *p_table; * char *p_key_data; * int *p_data; * int ret; * * [Create p_table etc...] * p_data = malloc(sizeof(int)); * p_key_data = "blabla"; * *p_data = 15; * * ret = ght_insert(p_table, * p_data, * sizeof(char)*strlen(p_key_data), p_key_data); * </PRE> * * @param p_ht the hash table to insert into. * @param p_entry_data the data to insert. * @param i_key_size the size of the key to associate the data with (in bytes). * @param p_key_data the key to use. The value will be copied, and it * is therefore OK to use a stack-allocated entry here. * * @return 0 if the element could be inserted, -1 otherwise. */int ght_insert(ght_hash_table_t *p_ht, void *p_entry_data, unsigned int i_key_size, void *p_key_data);/** * Replace an entry in the hash table. This function will return an * error if the entry to be replaced does not exist, i.e. it cannot be * used to insert new entries. * * @param p_ht the hash table to search in. * @param p_entry_data the new data for the key. * @param i_key_size the size of the key to search with (in bytes). * @param p_key_data the key to search for. * * @return a pointer to the <I>old</I> value or NULL if the operation failed. */void *ght_replace(ght_hash_table_t *p_ht, void *p_entry_data, unsigned int i_key_size, void *p_key_data);/** * Lookup an entry in the hash table. The entry is <I>not</I> removed from * the table. * * @param p_ht the hash table to search in. * @param i_key_size the size of the key to search with (in bytes). * @param p_key_data the key to search for. * * @return a pointer to the found entry or NULL if no entry could be found. */void *ght_get(ght_hash_table_t *p_ht, unsigned int i_key_size, void *p_key_data);/** * Remove an entry from the hash table. The entry is removed from the * table, but not freed (that is, the data stored is not freed). * * @param p_ht the hash table to use. * @param i_key_size the size of the key to search with (in bytes). * @param p_key_data the key to search for. * * @return a pointer to the removed entry or NULL if the entry could be found. */void *ght_remove(ght_hash_table_t *p_ht, unsigned int i_key_size, void *p_key_data);/** * Return the first entry in the hash table. This function should be * used for iteration and is used together with ght_next(). Note that * you cannot assume anything about the order in which the entries are * accessed. If an entry is inserted during an iteration, the entry * might or might not occur in the iteration. * * The use of the ght_iterator_t allows for several concurrent * iterations, where you would use one ght_iterator_t for each * iteration. In threaded environments, you should still lock access * to the hash table for insertion and removal. * * A typical example might look as follows: * <PRE> * ght_hash_table_t *p_table; * ght_iterator_t iterator; * void *p_key; * void *p_e; * * [Create table etc...] * for(p_e = ght_first(p_table, &iterator, &p_key); p_e; p_e = ght_next(p_table, &iterator, &p_key)) * { * [Do something with the current entry p_e and it's key p_key] * } * </PRE> * * @param p_ht the hash table to iterate through. * * @param p_iterator the iterator to use. The value of the structure * is filled in by this function and may be stack allocated. * * @param pp_key a pointer to the pointer of the key (NULL if none). * * @return a pointer to the first entry in the table or NULL if there * are no entries. * * * @see ght_next() */void *ght_first(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, void **pp_key);/** * Return the next entry in the hash table. This function should be * used for iteration, and must be called after ght_first(). * * @warning calling this without first having called ght_first will * give undefined results (probably a crash), since p_iterator isn't * filled correctly. * * @param p_ht the hash table to iterate through. * * @param p_iterator the iterator to use. * * @param pp_key a pointer to the pointer of the key (NULL if none). * * @return a pointer to the next entry in the table or NULL if there * are no more entries in the table. * * @see ght_first() */void *ght_next(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, void **pp_key);/** * Rehash the hash table. * * Rehashing will change the size of the hash table, retaining all * elements. This is very costly and should be avoided unless really * needed. If <TT>GHT_AUTOMATIC_REHASH</TT> is specified in the flag * parameter when ght_create() is called, the hash table is * automatically rehashed when the number of stored elements exceeds * two times the number of buckets in the table (making calls to this * function unessessary). * * @param p_ht the hash table to rehash. * @param i_size the new size of the table. * * @see ght_create() */void ght_rehash(ght_hash_table_t *p_ht, unsigned int i_size);/** * Free the hash table. ght_finalize() should typically be called * at the end of the program. Note that only the metadata and the keys * of the table is freed, not the entries. If you want to free the * entries when removing the table, the entries will have to be * manually freed before ght_finalize() is called like: * * <PRE> * ght_iterator_t iterator; * void *p_key; * void *p_e; * * for(p_e = ght_first(p_table, &iterator, &p_key); p_e; p_e = ght_next(p_table, &iterator, &p_key)) * { * free(p_e); * } * * ght_finalize(p_table); * </PRE> * * @param p_ht the table to remove. */void ght_finalize(ght_hash_table_t *p_ht);/* exported hash functions *//** * One-at-a-time-hash. One-at-a-time-hash is a good hash function, and * is the default when ght_create() is called with NULL as the * fn_hash parameter. This was found in a DrDobbs article, see * http://burtleburtle.net/bob/hash/doobs.html * * @warning Don't call this function directly, it is only meant to be * used as a callback for the hash table. * * @see ght_fn_hash_t * @see ght_rotating_hash(), ght_crc_hash() */ght_uint32_t ght_one_at_a_time_hash(ght_hash_key_t *p_key);/** * Rotating hash. Not so good hash function. This was found in a * DrDobbs article, see http://burtleburtle.net/bob/hash/doobs.html * * @warning Don't call this function directly, it is only meant to be * used as a callback for the hash table. * * @see ght_fn_hash_t * @see ght_one_at_a_time_hash(), ght_crc_hash() */ght_uint32_t ght_rotating_hash(ght_hash_key_t *p_key);/** * CRC32 hash. CRC32 hash is a good hash function. This came from Dru * Lemley <spambait@lemley.net>. * * @warning Don't call this function directly, it is only meant to be * used as a callback for the hash table. * * @see ght_fn_hash_t * @see ght_one_at_a_time_hash(), ght_rotating_hash() */ght_uint32_t ght_crc_hash(ght_hash_key_t *p_key);#ifdef USE_PROFILING/** * Print some statistics about the table. Only available if the * library was compiled with <TT>USE_PROFILING</TT> defined. */void ght_print(ght_hash_table_t *p_ht);#endif#ifdef __cplusplus}#endif#endif /* GHT_HASH_TABLE_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -