Tinyhash
This is a library containing multiple C implementations of hashmap.
Loading...
Searching...
No Matches
Functions | Variables
tinyhash.c File Reference
#include "tinyhash.h"
#include "./open_addressing/table.h"
#include "./separate_chaining/table.h"
Include dependency graph for tinyhash.c:

Go to the source code of this file.

Functions

th_t th_create_default ()
 Allocate then initialize a hashmap controller with its default values.
 
th_t th_create (th_method_t method)
 Allocate then initialize a hashmap controller. based on the given method.
 
th_any_t th_get (th_t *th, th_any_t data, size_t data_size)
 Returns a value from a hashmap. Return NULL if it doest not exist.
 
bool th_put (th_t *th, th_any_t data, size_t data_size, th_any_t value)
 Insert element within the hashmap. Return true on success.
 
bool th_delete (th_t *th, th_any_t data, size_t data_size)
 Delete a key value pair from a hashmap. Return true on success.
 
void th_clear (th_t *th)
 Clear a hashmap.
 
void th_free (th_t *th)
 Free a hashmap.
 
th_iterator_tth_begin_iterator (th_t *th)
 Return a pointer on an iterator with the first element.
 
th_iterator_tth_empty_iterator (th_t *th)
 Return an empty iterator.
 
int th_len (th_t *th)
 Get the hashmap length (total amount of key value pairs).
 

Variables

static th_funcs_t th_funcs []
 Static array containing functions that accomplish hashmap operation associated with an implementation method.
 
static size_t th_funcs_length = sizeof(th_funcs) / sizeof(th_funcs[0])
 

Function Documentation

◆ th_begin_iterator()

th_iterator_t * th_begin_iterator ( th_t * th)

Return a pointer on an iterator with the first element.

Parameters
th
Returns
th_iterator_t*

Definition at line 73 of file tinyhash.c.

References th_funcs_t::begin_iterator, th_t::funcs, and th_t::table.

◆ th_clear()

void th_clear ( th_t * th)

Clear a hashmap.

Parameters
th

Definition at line 65 of file tinyhash.c.

References th_funcs_t::_free, th_t::funcs, and th_t::table.

◆ th_create()

th_t th_create ( th_method_t method)

Allocate then initialize a hashmap controller. based on the given method.

Parameters
method
Returns
th_t

Definition at line 39 of file tinyhash.c.

References th_funcs_t::create, th_create_default(), th_funcs, and th_funcs_length.

Referenced by th_create_default().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ th_create_default()

th_t th_create_default ( )

Allocate then initialize a hashmap controller with its default values.

Returns
th_t

Definition at line 37 of file tinyhash.c.

References th_create(), and TH_SEPARATE_CHAINING.

Referenced by th_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ th_delete()

bool th_delete ( th_t * th,
th_any_t data,
size_t data_size )

Delete a key value pair from a hashmap. Return true on success.

Parameters
th
data
data_size
Returns
true
false

Definition at line 61 of file tinyhash.c.

References th_funcs_t::_delete, th_t::funcs, and th_t::table.

◆ th_empty_iterator()

th_iterator_t * th_empty_iterator ( th_t * th)

Return an empty iterator.

Parameters
th
Returns
th_iterator_t*

Definition at line 77 of file tinyhash.c.

References th_funcs_t::begin_iterator, th_t::funcs, and th_t::table.

◆ th_free()

void th_free ( th_t * th)

Free a hashmap.

Parameters
th

Definition at line 67 of file tinyhash.c.

References th_funcs_t::_free, th_t::funcs, and th_t::table.

◆ th_get()

th_any_t th_get ( th_t * th,
th_any_t data,
size_t data_size )

Returns a value from a hashmap. Return NULL if it doest not exist.

Parameters
th
data
data_size
Returns
th_any_t

Definition at line 53 of file tinyhash.c.

References th_t::funcs, th_funcs_t::get, and th_t::table.

◆ th_len()

int th_len ( th_t * th)

Get the hashmap length (total amount of key value pairs).

Parameters
th
Returns
int

Definition at line 81 of file tinyhash.c.

References th_t::funcs, th_funcs_t::len, and th_t::table.

◆ th_put()

bool th_put ( th_t * th,
th_any_t data,
size_t data_size,
th_any_t value )

Insert element within the hashmap. Return true on success.

Parameters
th
data
data_size
value
Returns
true
false

Definition at line 57 of file tinyhash.c.

References th_t::funcs, th_funcs_t::put, and th_t::table.

Variable Documentation

◆ th_funcs

th_funcs_t th_funcs[]
static
Initial value:
= {
{
.create = th_sc_table_create,
._delete = th_sc_table_delete,
._free = th_sc_table_free,
.begin_iterator = th_sc_iterator_begin,
},
{
.create = th_oa_table_create,
._delete = th_oa_table_delete,
._free = th_oa_table_free,
.begin_iterator = th_oa_iterator_begin,
},
}
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.
Definition table.c:197
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.
Definition table.c:189
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.
Definition table.c:138
void th_oa_table_free(th_generic_table_t generic_table)
Free an open addressing table.
Definition table.c:219
th_iterator_t * th_oa_iterator_begin(th_generic_table_t generic_table, bool is_begin)
Return a new iterator.
Definition table.c:272
int th_oa_table_len(th_generic_table_t generic_table)
Returns the table length.
Definition table.c:289
th_generic_table_t th_oa_table_create()
Return an allocated open addressing table struct.
Definition table.c:38
th_iterator_t * th_sc_iterator_begin(th_generic_table_t generic_table, bool is_begin)
Return a new iterator.
Definition table.c:287
void th_sc_table_free(th_generic_table_t generic_table)
Free an separate chaining table.
Definition table.c:222
int th_sc_table_len(th_generic_table_t generic_table)
Returns the table length.
Definition table.c:304
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.
Definition table.c:133
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.
Definition table.c:183
th_generic_table_t th_sc_table_create()
Return an allocated separate chaining table.
Definition table.c:36
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.
Definition table.c:191
@ TH_SEPARATE_CHAINING
Definition tinyhash.h:15
@ TH_OPEN_ADRESSING
Definition tinyhash.h:16

Static array containing functions that accomplish hashmap operation associated with an implementation method.

Definition at line 11 of file tinyhash.c.

Referenced by th_create().

◆ th_funcs_length

size_t th_funcs_length = sizeof(th_funcs) / sizeof(th_funcs[0])
static

Definition at line 35 of file tinyhash.c.

Referenced by th_create().