Tinyhash
This is a library containing multiple C implementations of hashmap.
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions
tinyhash.h File Reference
#include <stdbool.h>
#include <stdio.h>
#include "./common/iterator.h"
#include "./common/types.h"
Include dependency graph for tinyhash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  th_funcs_t
 Centralizing every function associated with an unique implementation method. More...
 
struct  th_t
 Represent a hashmap controller. More...
 

Typedefs

typedef th_generic_table_t(* th_create_func_t) (void)
 Pointer on generic function that create a table.
 
typedef th_any_t(* th_get_func_t) (th_generic_table_t, th_any_t, size_t)
 Pointer on generic function that get a value from a table.
 
typedef bool(* th_put_func_t) (th_generic_table_t, th_any_t, size_t, th_any_t)
 Pointer on generic function that insert a value into a table.
 
typedef bool(* th_delete_func_t) (th_generic_table_t, th_any_t, size_t)
 Pointer on generic function that delete a value from a table.
 
typedef void(* th_free_func_t) (th_generic_table_t)
 Pointer on generic function that free a table.
 
typedef th_iterator_t *(* th_begin_iterator_func_t) (th_generic_table_t, bool)
 
typedef int(* th_len_func_t) (th_generic_table_t)
 

Enumerations

enum  th_method_t { TH_SEPARATE_CHAINING , TH_OPEN_ADRESSING }
 Implementation methods. More...
 

Functions

th_t th_create (th_method_t method)
 Allocate then initialize a hashmap controller. based on the given method.
 
th_t th_create_default ()
 Allocate then initialize a hashmap controller with its default values.
 
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).
 

Typedef Documentation

◆ th_begin_iterator_func_t

typedef th_iterator_t *(* th_begin_iterator_func_t) (th_generic_table_t, bool)

Definition at line 49 of file tinyhash.h.

◆ th_create_func_t

typedef th_generic_table_t(* th_create_func_t) (void)

Pointer on generic function that create a table.

Definition at line 23 of file tinyhash.h.

◆ th_delete_func_t

typedef bool(* th_delete_func_t) (th_generic_table_t, th_any_t, size_t)

Pointer on generic function that delete a value from a table.

Definition at line 41 of file tinyhash.h.

◆ th_free_func_t

typedef void(* th_free_func_t) (th_generic_table_t)

Pointer on generic function that free a table.

Definition at line 47 of file tinyhash.h.

◆ th_get_func_t

typedef th_any_t(* th_get_func_t) (th_generic_table_t, th_any_t, size_t)

Pointer on generic function that get a value from a table.

Definition at line 29 of file tinyhash.h.

◆ th_len_func_t

typedef int(* th_len_func_t) (th_generic_table_t)

Definition at line 50 of file tinyhash.h.

◆ th_put_func_t

typedef bool(* th_put_func_t) (th_generic_table_t, th_any_t, size_t, th_any_t)

Pointer on generic function that insert a value into a table.

Definition at line 35 of file tinyhash.h.

Enumeration Type Documentation

◆ th_method_t

Implementation methods.

Enumerator
TH_SEPARATE_CHAINING 
TH_OPEN_ADRESSING 

Definition at line 14 of file tinyhash.h.

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.