26 #ifndef CDCONTAINERS_INCLUDE_CDCONTAINERS_HASH_TABLE_H 27 #define CDCONTAINERS_INCLUDE_CDCONTAINERS_HASH_TABLE_H 151 float load_factor, ...);
164 float load_factor, va_list args);
506 #ifdef CDC_USE_SHORT_NAMES 509 typedef struct cdc_pair_hash_table_iter pair_hash_table_iter_t;
510 typedef struct cdc_pair_hash_table_iter_bool pair_hash_table_iter_bool_t;
513 #define hash_table_ctor(...) cdc_hash_table_ctor(__VA_ARGS__) 514 #define hash_table_ctorl(...) cdc_hash_table_ctorl(__VA_ARGS__) 515 #define hash_table_ctorv(...) cdc_hash_table_ctorv(__VA_ARGS__) 516 #define hash_table_ctor1(...) cdc_hash_table_ctor1(__VA_ARGS__) 517 #define hash_table_ctorl1(...) cdc_hash_table_ctorl1(__VA_ARGS__) 518 #define hash_table_ctorv1(...) cdc_hash_table_ctorv1(__VA_ARGS__) 519 #define hash_table_dtor(...) cdc_hash_table_dtor(__VA_ARGS__) 522 #define hash_table_get(...) cdc_hash_table_get(__VA_ARGS__) 523 #define hash_table_count(...) cdc_hash_table_count(__VA_ARGS__) 524 #define hash_table_find(...) cdc_hash_table_find(__VA_ARGS__) 527 #define hash_table_size(...) cdc_hash_table_size(__VA_ARGS__) 528 #define hash_table_empty(...) cdc_hash_table_empty(__VA_ARGS__) 531 #define hash_table_clear(...) cdc_hash_table_clear(__VA_ARGS__) 532 #define hash_table_insert(...) cdc_hash_table_insert(__VA_ARGS__) 533 #define hash_table_insert_or_assign(...) \ 534 cdc_hash_table_insert_or_assign(__VA_ARGS__) 535 #define hash_table_erase(...) cdc_hash_table_erase(__VA_ARGS__) 536 #define hash_table_swap(...) cdc_hash_table_swap(__VA_ARGS__) 539 #define hash_table_begin(...) cdc_hash_table_begin(__VA_ARGS__) 540 #define hash_table_end(...) cdc_hash_table_end(__VA_ARGS__) 543 #define hash_table_load_factor(...) cdc_hash_table_load_factor(__VA_ARGS__) 544 #define hash_table_max_load_factor(...) \ 545 cdc_hash_table_max_load_factor(__VA_ARGS__) 546 #define hash_table_set_max_load_factor(...) \ 547 cdc_hash_table_set_max_load_factor(__VA_ARGS__) 548 #define hash_table_rehash(...) cdc_hash_table_rehash(__VA_ARGS__) 549 #define hash_table_reserve(...) cdc_hash_table_reserve(__VA_ARGS__) 552 #define hash_table_bucket_count(...) cdc_hash_table_bucket_count(__VA_ARGS__) 555 #define hash_table_iter_next(...) cdc_hash_table_iter_next(__VA_ARGS__) 556 #define hash_table_iter_has_next(...) cdc_hash_table_iter_has_next(__VA_ARGS__) 557 #define hash_table_iter_key(...) cdc_hash_table_iter_key(__VA_ARGS__) 558 #define hash_table_iter_value(...) cdc_hash_table_iter_value(__VA_ARGS__) 559 #define hash_table_iter_key_value(...) \ 560 cdc_hash_table_iter_key_value(__VA_ARGS__) 561 #define hash_table_iter_is_eq(...) cdc_hash_table_iter_is_eq(__VA_ARGS__) 564 #endif // CDCONTAINERS_INCLUDE_CDCONTAINERS_HASH_TABLE_H enum cdc_stat cdc_hash_table_reserve(struct cdc_hash_table *t, size_t count)
Reserves space for at least the specified number of elements. This regenerates the hash table...
struct cdc_hash_table_entry * tail
Definition: hash-table.h:61
static void cdc_hash_table_set_max_load_factor(struct cdc_hash_table *t, float load_factor)
Sets the maximum load factor.
Definition: hash-table.h:371
size_t bcount
Definition: hash-table.h:63
struct cdc_hash_table_entry ** buckets
Definition: hash-table.h:62
struct cdc_hash_table_entry * current
Definition: hash-table.h:76
size_t cdc_hash_table_erase(struct cdc_hash_table *t, void *key)
Removes the element (if one exists) with the key equivalent to key.
static size_t cdc_hash_table_bucket_count(struct cdc_hash_table *t)
Returns the number of buckets.
Definition: hash-table.h:410
void cdc_hash_table_find(struct cdc_hash_table *t, void *key, struct cdc_hash_table_iter *it)
Finds an element with key equivalent to key.
enum cdc_stat cdc_hash_table_ctorl1(struct cdc_hash_table **t, struct cdc_data_info *info, float load_factor,...)
Constructs a hash table, initialized by an variable number of pointers on cdc_pair's(first - key...
This file contains different utilities for hashing. The ideas of algorithms were borrowed from the bo...
static void * cdc_hash_table_iter_key(struct cdc_hash_table_iter *it)
Returns an item's key.
Definition: hash-table.h:454
enum cdc_stat cdc_hash_table_ctorl(struct cdc_hash_table **t, struct cdc_data_info *info,...)
Constructs a hash table, initialized by an variable number of pointers on cdc_pair's(first - key...
void * value
Definition: hash-table.h:51
size_t hash
Definition: hash-table.h:52
struct cdc_hash_table_entry * next
Definition: hash-table.h:49
static struct cdc_pair cdc_hash_table_iter_key_value(struct cdc_hash_table_iter *it)
Returns a pair, where first - key, second - value.
Definition: hash-table.h:478
enum cdc_stat cdc_hash_table_insert(struct cdc_hash_table *t, void *key, void *value, struct cdc_hash_table_iter *it, bool *inserted)
Inserts an element into the container, if the container doesn't already contain an element with an eq...
static size_t cdc_hash_table_size(struct cdc_hash_table *t)
Returns the number of items in the hash_table.
Definition: hash-table.h:221
static bool cdc_hash_table_iter_has_next(struct cdc_hash_table_iter *it)
Returns true if there is at least one element ahead of the iterator, i.e. the iterator is not at the ...
Definition: hash-table.h:442
struct cdc_hash_table * container
Definition: hash-table.h:75
static float cdc_hash_table_max_load_factor(struct cdc_hash_table *t)
Returns current maximum load factor.
Definition: hash-table.h:359
void cdc_hash_table_clear(struct cdc_hash_table *t)
Removes all the elements from the hash_table.
The cdc_hash_table_iter is service struct.
Definition: hash-table.h:74
enum cdc_stat cdc_hash_table_rehash(struct cdc_hash_table *t, size_t count)
Reserves at least the specified number of buckets. This regenerates the hash table.
enum cdc_stat cdc_hash_table_ctorv1(struct cdc_hash_table **t, struct cdc_data_info *info, float load_factor, va_list args)
Constructs a hash table, initialized by args. The last item must be CDC_END.
cdc_stat
Definition: status.h:24
static void cdc_hash_table_begin(struct cdc_hash_table *t, struct cdc_hash_table_iter *it)
Initializes the iterator to the beginning.
Definition: hash-table.h:311
static bool cdc_hash_table_iter_is_eq(struct cdc_hash_table_iter *it1, struct cdc_hash_table_iter *it2)
Returns false if the iterator |it1| equal to the iterator |it2|, otherwise returns false...
Definition: hash-table.h:495
enum cdc_stat cdc_hash_table_ctor(struct cdc_hash_table **t, struct cdc_data_info *info)
Constructs an empty hash table.
size_t size
Definition: hash-table.h:65
void cdc_hash_table_swap(struct cdc_hash_table *a, struct cdc_hash_table *b)
Swaps hash_tables a and b. This operation is very fast and never fails.
enum cdc_stat cdc_hash_table_get(struct cdc_hash_table *t, void *key, void **value)
Returns a value that is mapped to a key. If the key does not exist, then NULL will return...
void cdc_hash_table_dtor(struct cdc_hash_table *t)
Destroys the hash table.
static void cdc_hash_table_end(struct cdc_hash_table *t, struct cdc_hash_table_iter *it)
Initializes the iterator to the end.
Definition: hash-table.h:326
enum cdc_stat cdc_hash_table_ctorv(struct cdc_hash_table **t, struct cdc_data_info *info, va_list args)
Constructs a hash table, initialized by args. The last item must be CDC_END.
static void cdc_hash_table_iter_next(struct cdc_hash_table_iter *it)
Advances the iterator to the next element in the hash table.
Definition: hash-table.h:428
enum cdc_stat cdc_hash_table_insert_or_assign(struct cdc_hash_table *t, void *key, void *value, struct cdc_hash_table_iter *it, bool *inserted)
Inserts an element or assigns to the current element if the key already exists.
static float cdc_hash_table_load_factor(struct cdc_hash_table *t)
Returns average number of elements per bucket.
Definition: hash-table.h:347
static void * cdc_hash_table_iter_value(struct cdc_hash_table_iter *it)
Returns an item's value.
Definition: hash-table.h:466
size_t cdc_hash_table_count(struct cdc_hash_table *t, void *key)
Returns the number of elements with key that compares equal to the specified argument key...
The cdc_hash_table is service struct.
Definition: hash-table.h:60
The cdc_data_info struct used to initialize contaners.
Definition: common.h:71
static bool cdc_hash_table_empty(struct cdc_hash_table *t)
Checks if the hash table has no elements.
Definition: hash-table.h:233
void * key
Definition: hash-table.h:50
The cdc_hash_table_entry struct.
Definition: hash-table.h:48
struct cdc_data_info * dinfo
Definition: hash-table.h:66
float load_factor
Definition: hash-table.h:64
enum cdc_stat cdc_hash_table_ctor1(struct cdc_hash_table **t, struct cdc_data_info *info, float load_factor)
Constructs an empty hash table.