44 #ifndef __FAST_HASH_TABLE_H__ 45 #define __FAST_HASH_TABLE_H__ 58 #define FHT_TABLE_COLS 4 63 #define FHT_COL_FULL ((uint8_t) 0x000F) 143 uint32_t (*hash_function)(
const void *, int32_t);
175 fht_table_t *
fht_init(uint32_t table_rows, uint32_t key_size, uint32_t data_size, uint32_t stash_size);
200 int fht_insert(
fht_table_t *table,
const void *key,
const void *data,
void *key_lost,
void *data_lost);
275 static inline void *fht_get_data(
fht_table_t *table,
const void *key)
281 while (__sync_lock_test_and_set(&table->
lock_table[table_row], 1))
289 __sync_lock_release(&table->
lock_table[table_row]);
299 __sync_lock_release(&table->
lock_table[table_row]);
309 __sync_lock_release(&table->
lock_table[table_row]);
319 __sync_lock_release(&table->
lock_table[table_row]);
326 __sync_lock_release(&table->
lock_table[table_row]);
344 static inline void *fht_get_data_locked(
fht_table_t *table,
const void *key, int8_t **lock)
350 while (__sync_lock_test_and_set(&table->
lock_table[table_row], 1))
387 __sync_lock_release(&table->
lock_table[table_row]);
406 static inline void *fht_get_data_with_stash(
fht_table_t *table,
const void *key)
413 while (__sync_lock_test_and_set(&table->
lock_table[table_row], 1))
421 __sync_lock_release(&table->
lock_table[table_row]);
431 __sync_lock_release(&table->
lock_table[table_row]);
441 __sync_lock_release(&table->
lock_table[table_row]);
451 __sync_lock_release(&table->
lock_table[table_row]);
458 __sync_lock_release(&table->
lock_table[table_row]);
463 while (__sync_lock_test_and_set(&table->
lock_stash, 1))
494 static inline void *fht_get_data_with_stash_locked(
fht_table_t *table,
const void *key, int8_t **lock)
501 while (__sync_lock_test_and_set(&table->
lock_table[table_row], 1))
538 __sync_lock_release(&table->
lock_table[table_row]);
543 while (__sync_lock_test_and_set(&table->
lock_stash, 1))
650 static inline void fht_unlock_data(int8_t *lock)
652 __sync_lock_release(lock);
uint8_t lt_replacement_vector_remove[][4]
int fht_insert(fht_table_t *table, const void *key, const void *data, void *key_lost, void *data_lost)
Function for inserting the item into the table without using stash.
int fht_remove(fht_table_t *table, const void *key)
Function for removing item from the table without looking for in stash.
void fht_destroy(fht_table_t *table)
Function for destroying the table and freeing memory.
uint8_t lt_replacement_index[]
uint8_t lt_replacement_vector[][4]
uint8_t * stash_free_flag_field
int fht_insert_with_stash_wr(fht_table_t *table, const void *key, const void *data)
Function for inserting the item into the table using stash and without replacing items in stash...
void fht_reinit_iter(fht_iter_t *iter)
Function for reinitializing iterator for the table.
int fht_remove_with_stash(fht_table_t *table, const void *key)
Function for removing item from the table with looking for in stash.
fht_table_t * fht_init(uint32_t table_rows, uint32_t key_size, uint32_t data_size, uint32_t stash_size)
Function for initializing the hash table.
void fht_clear(fht_table_t *table)
Function for clearing the table.
uint8_t * replacement_vector_field
int fht_remove_iter(fht_iter_t *iter)
Function for removing actual item from the table when using iterator.
fht_iter_t * fht_init_iter(fht_table_t *table)
Function for initializing iterator for the table.
int fht_insert_wr(fht_table_t *table, const void *key, const void *data)
Function for inserting the item into the table without using stash and without replacing the oldest i...
int fht_remove_locked(fht_table_t *table, const void *key, int8_t *lock_ptr)
Function for removing item from the table without looking for in stash. Function does not locks lock...
uint32_t(* hash_function)(const void *, int32_t)
uint8_t * free_flag_field
void fht_destroy_iter(fht_iter_t *iter)
Function for destroying iterator and freeing memory.
uint8_t * stash_data_field
uint8_t * stash_key_field
int fht_insert_with_stash(fht_table_t *table, const void *key, const void *data, void *key_lost, void *data_lost)
Function for inserting the item into the table using stash.
int32_t fht_get_next_iter(fht_iter_t *iter)
Function for getting next item in the table.
int fht_remove_with_stash_locked(fht_table_t *table, const void *key, int8_t *lock_ptr)
Function for removing item from the table with looking for in stash. Function does not locks lock...