54 for (
int i = 0; i < src->
capacity; i++) {
57 if (entry->
key == NULL) {
63 if (success ==
false) {
88 new_table.
entries = malloc(size);
89 if (new_table.
entries == NULL) {
93 memset(new_table.
entries, 0, size);
96 if (success ==
false) {
122 if (entry->
key == NULL) {
124 return tombstone != NULL ? tombstone : entry;
126 if (tombstone == NULL) {
134 index = (index + 1) % table->
capacity;
147 if (entry->
key == NULL) {
173 if (entry->
key == NULL) {
183 entry->
value = value;
207 if (entry->
key == NULL) {
222 for (
int i = 0; i < table->
capacity; i++) {
225 if (entry->
key == NULL) {
256 if (entry->
key == NULL) {
282 if (is_begin ==
true) {
#define TH_TABLE_NEXT_CAPACITY(capacity)
Generate the next capacity value absed on a previous one.
th_iterator_t * th_iterator_create(th_generic_table_t generic_table, th_iterator_next_func_t next)
Allocate then init a new iterator.
th_key_t th_key_create(th_any_t data, size_t size)
Create a key struct from data and size, it will automatically compute its hash.
bool th_key_is_equal(th_key_t *first, th_key_t *second)
Key comparator function.
struct th_oa_entry_s th_oa_entry_t
Represent an entry within a bucket.
static bool th_oa_table_copy(th_oa_table_t *dest, th_oa_table_t *src)
Copy and rehash every value from a table to another. Return true on success.
static bool th_oa_iterator_next(th_iterator_t **ptr)
Get the next key value pair if it exists.
static bool th_oa_table_increase(th_oa_table_t *table)
Increase the size of a table.
bool th_oa_table_delete(th_generic_table_t generic_table, th_any_t data, size_t data_size)
Delete a key value pair in an open addressing table. Return true on success.
bool th_oa_table_put(th_generic_table_t generic_table, th_any_t data, size_t data_size, th_any_t value)
Insert a value within an open addressing table. Return true on success.
void th_oa_table_init(th_oa_table_t *table)
Initialize open adressing table values.
th_any_t th_oa_table_get(th_generic_table_t generic_table, th_any_t data, size_t data_size)
Get a value from an open addressing table. Return NULL if it does exist.
void th_oa_table_free(th_generic_table_t generic_table)
Free an open addressing table.
th_iterator_t * th_oa_iterator_begin(th_generic_table_t generic_table, bool is_begin)
Return a new iterator.
static th_oa_table_t * _th_oa_table_create()
Allocate then initialize an open addressing table. It can return NULL.
static th_oa_entry_t * th_oa_table_find(th_oa_table_t *table, th_key_t *key)
Returns a bucket (entry) depending on a key. It can return a tomstone or an empty bucket.
int th_oa_table_len(th_generic_table_t generic_table)
Returns the table length.
static bool th_oa_table_put_with_key(th_oa_table_t *table, th_key_t *key, th_any_t value)
Insert a value within the table with an already existing key.
th_generic_table_t th_oa_table_create()
Return an allocated open addressing table struct.
#define TH_OA_LOAD_FACTOR
Load factor.
Represents an iterator that allow to iterate over a generic table.
th_generic_table_t generic_table
Represent an entry within a bucket.
void * th_generic_table_t
Represents any table.
void * th_any_t
Represent any type of data.