52 for (
int i = 0; i < src->
capacity; i++) {
55 while (entry != NULL) {
58 if (success ==
false) {
85 new_table.
entries = malloc(size);
87 if (new_table.
entries == NULL) {
91 memset(new_table.
entries, 0, size);
94 if (success ==
false) {
122 while (entry != NULL) {
169 if (*bucket == NULL) {
177 entry->
value = value;
207 }
else if (entry->
previous == NULL) {
208 *bucket = entry->
next;
210 }
else if (entry->
next == NULL) {
227 for (
int i = 0; i < table->
capacity; i++) {
230 while (entry != NULL) {
263 if (current != NULL && current->
next != NULL) {
297 if (is_begin ==
true) {
#define TH_TABLE_NEXT_CAPACITY(capacity)
Generate the next capacity value absed on a previous one.
bool th_sc_entry_add(th_sc_entry_t **root, th_key_t *key, th_any_t value)
Add an a separate chaining entry to the beginning of a linked list. Return true on success.
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.
th_iterator_t * th_sc_iterator_begin(th_generic_table_t generic_table, bool is_begin)
Return a new iterator.
void th_sc_table_free(th_generic_table_t generic_table)
Free an separate chaining table.
static bool th_sc_iterator_next(th_iterator_t **ptr)
Get the next key value pair if it exists.
int th_sc_table_len(th_generic_table_t generic_table)
Returns the table length.
static void th_sc_iterator_copy_entry(th_iterator_t *it, th_sc_entry_t *entry)
th_any_t th_sc_table_get(th_generic_table_t generic_table, th_any_t data, size_t data_size)
Get a value from an separate chaining table. Return NULL if it does exist.
static th_sc_entry_t * th_sc_table_find(th_sc_table_t *table, th_key_t *key)
Returns a bucket (entry) depending on a key. Return NULL if the entry does not exist.
bool th_sc_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 separate chaining table. Return true on success.
static bool th_sc_table_copy(th_sc_table_t *dest, th_sc_table_t *src)
Copy and rehash every value from a table to another. Return true on success.
static th_sc_table_t * _th_sc_table_create()
Allocate then return a new table.
void th_sc_table_init(th_sc_table_t *table)
Initialize a separate chaining table.
th_generic_table_t th_sc_table_create()
Return an allocated separate chaining table.
static bool th_sc_table_put_with_key(th_sc_table_t *table, th_key_t *key, th_any_t value)
Insert a value within the table with an already existing key.
bool th_sc_table_delete(th_generic_table_t generic_table, th_any_t data, size_t data_size)
Delete a key value pair in an separate chaining table. Return true on success.
static bool th_sc_table_increase(th_sc_table_t *table)
Increase the size of a table.
Represents an iterator that allow to iterate over a generic table.
th_generic_table_t generic_table
Represents a separate chaining entry.
struct th_sc_entry_s * previous
struct th_sc_entry_s * next
Represent a separate chaining table.
void * th_generic_table_t
Represents any table.
void * th_any_t
Represent any type of data.