Tinyhash
This is a library containing multiple C implementations of hashmap.
|
#include "../common/table.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "entry.h"
#include "table.h"
Go to the source code of this file.
Functions | |
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. | |
void | th_oa_table_init (th_oa_table_t *table) |
Initialize open adressing table values. | |
static th_oa_table_t * | _th_oa_table_create () |
Allocate then initialize an open addressing table. It can return NULL. | |
th_generic_table_t | th_oa_table_create () |
Return an allocated open addressing table struct. | |
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_table_increase (th_oa_table_t *table) |
Increase the size of a table. | |
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. | |
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. | |
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. | |
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. | |
void | th_oa_table_free (th_generic_table_t generic_table) |
Free an open addressing table. | |
static bool | th_oa_iterator_next (th_iterator_t **ptr) |
Get the next key value pair if it exists. | |
th_iterator_t * | th_oa_iterator_begin (th_generic_table_t generic_table, bool is_begin) |
Return a new iterator. | |
int | th_oa_table_len (th_generic_table_t generic_table) |
Returns the table length. | |
|
static |
Allocate then initialize an open addressing table. It can return NULL.
Definition at line 26 of file table.c.
References th_oa_table_init().
Referenced by th_oa_table_create().
th_iterator_t * th_oa_iterator_begin | ( | th_generic_table_t | generic_table, |
bool | is_begin ) |
Return a new iterator.
If is_begin
is true, it will initialize the iterator with the first element. Otherwise, it will be empty.
generic_table | |
is_begin |
Definition at line 272 of file table.c.
References th_iterator_s::index, th_iterator_create(), and th_oa_iterator_next().
|
static |
Get the next key value pair if it exists.
ptr |
Definition at line 246 of file table.c.
References th_oa_table_t::capacity, th_iterator_s::current, th_oa_table_t::entries, th_iterator_s::generic_table, th_iterator_s::index, th_iterator_s::key, th_oa_entry_s::key, th_iterator_s::value, and th_oa_entry_s::value.
Referenced by th_oa_iterator_begin().
|
static |
Copy and rehash every value from a table to another. Return true on success.
dest | |
src |
Definition at line 51 of file table.c.
References th_oa_table_t::capacity, th_oa_table_t::entries, th_oa_entry_s::key, th_oa_table_put_with_key(), and th_oa_entry_s::value.
Referenced by th_oa_table_increase().
th_generic_table_t th_oa_table_create | ( | ) |
Return an allocated open addressing table struct.
Definition at line 38 of file table.c.
References _th_oa_table_create().
bool th_oa_table_delete | ( | th_generic_table_t | table, |
th_any_t | data, | ||
size_t | data_size ) |
Delete a key value pair in an open addressing table. Return true on success.
table | |
data | |
data_size |
Definition at line 197 of file table.c.
References th_oa_table_t::capacity, th_oa_entry_s::is_tombstone, th_oa_entry_s::key, th_key_create(), and th_oa_table_find().
|
static |
Returns a bucket (entry) depending on a key. It can return a tomstone or an empty bucket.
table | |
key |
Definition at line 115 of file table.c.
References th_oa_table_t::capacity, th_oa_table_t::entries, th_key_t::hash, th_oa_entry_s::is_tombstone, th_oa_entry_s::key, and th_key_is_equal().
Referenced by th_oa_table_delete(), th_oa_table_get(), and th_oa_table_put_with_key().
void th_oa_table_free | ( | th_generic_table_t | table | ) |
Free an open addressing table.
table |
Definition at line 219 of file table.c.
References th_oa_table_t::capacity, th_oa_table_t::entries, th_oa_entry_s::key, and th_oa_table_init().
Referenced by th_oa_table_increase().
th_any_t th_oa_table_get | ( | th_generic_table_t | table, |
th_any_t | data, | ||
size_t | data_size ) |
Get a value from an open addressing table. Return NULL if it does exist.
table | |
data | |
data_size |
Definition at line 138 of file table.c.
References th_oa_table_t::capacity, th_oa_entry_s::key, th_key_create(), th_oa_table_find(), and th_oa_entry_s::value.
|
static |
Increase the size of a table.
table |
Definition at line 78 of file table.c.
References th_oa_table_t::capacity, th_oa_table_t::entries, th_oa_table_copy(), th_oa_table_free(), th_oa_table_init(), and TH_TABLE_NEXT_CAPACITY.
Referenced by th_oa_table_put_with_key().
void th_oa_table_init | ( | th_oa_table_t * | table | ) |
Initialize open adressing table values.
table |
Definition at line 14 of file table.c.
References th_oa_table_t::capacity, th_oa_table_t::count, and th_oa_table_t::entries.
Referenced by _th_oa_table_create(), th_oa_table_free(), and th_oa_table_increase().
int th_oa_table_len | ( | th_generic_table_t | generic_table | ) |
bool th_oa_table_put | ( | th_generic_table_t | 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.
table | |
data | |
data_size | |
value |
Definition at line 189 of file table.c.
References th_key_create(), and th_oa_table_put_with_key().
|
static |
Insert a value within the table with an already existing key.
table | |
key | |
value |
Definition at line 163 of file table.c.
References th_oa_table_t::capacity, th_oa_table_t::count, th_oa_entry_s::is_tombstone, th_oa_entry_s::key, TH_OA_LOAD_FACTOR, th_oa_table_find(), th_oa_table_increase(), and th_oa_entry_s::value.
Referenced by th_oa_table_copy(), and th_oa_table_put().