Tinyhash
This is a library containing multiple C implementations of hashmap.
Loading...
Searching...
No Matches
tinyhash.h
Go to the documentation of this file.
1#ifndef __TINYHASH_H__
2#define __TINYHASH_H__
3
4#include <stdbool.h>
5#include <stdio.h>
6
7#include "./common/iterator.h"
8#include "./common/types.h"
9
18
24
30
36
42
48
49typedef th_iterator_t *(*th_begin_iterator_func_t)(th_generic_table_t, bool);
51
66
76
85
93
103th_any_t th_get(th_t *th, th_any_t data, size_t data_size);
104
116bool th_put(th_t *th, th_any_t data, size_t data_size, th_any_t value);
117
128bool th_delete(th_t *th, th_any_t data, size_t data_size);
129
135void th_clear(th_t *th);
136
142void th_free(th_t *th);
143
151
159
166int th_len(th_t *th);
167
168#endif
Centralizing every function associated with an unique implementation method.
Definition tinyhash.h:57
th_begin_iterator_func_t begin_iterator
Definition tinyhash.h:63
th_free_func_t _free
Definition tinyhash.h:62
th_get_func_t get
Definition tinyhash.h:59
th_len_func_t len
Definition tinyhash.h:64
th_create_func_t create
Definition tinyhash.h:58
th_delete_func_t _delete
Definition tinyhash.h:61
th_put_func_t put
Definition tinyhash.h:60
Represents an iterator that allow to iterate over a generic table.
Definition iterator.h:11
Represent a hashmap controller.
Definition tinyhash.h:71
th_funcs_t funcs
Definition tinyhash.h:73
th_generic_table_t table
Definition tinyhash.h:74
th_method_t method
Definition tinyhash.h:72
th_generic_table_t(* th_create_func_t)(void)
Pointer on generic function that create a table.
Definition tinyhash.h:23
th_t th_create(th_method_t method)
Allocate then initialize a hashmap controller. based on the given method.
Definition tinyhash.c:39
void(* th_free_func_t)(th_generic_table_t)
Pointer on generic function that free a table.
Definition tinyhash.h:47
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 tinyhash.h:41
th_iterator_t * th_empty_iterator(th_t *th)
Return an empty iterator.
Definition tinyhash.c:77
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.
Definition tinyhash.c:53
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 tinyhash.h:29
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.
Definition tinyhash.c:61
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 tinyhash.h:35
void th_clear(th_t *th)
Clear a hashmap.
Definition tinyhash.c:65
th_method_t
Implementation methods.
Definition tinyhash.h:14
@ TH_SEPARATE_CHAINING
Definition tinyhash.h:15
@ TH_OPEN_ADRESSING
Definition tinyhash.h:16
th_t th_create_default()
Allocate then initialize a hashmap controller with its default values.
Definition tinyhash.c:37
int(* th_len_func_t)(th_generic_table_t)
Definition tinyhash.h:50
int th_len(th_t *th)
Get the hashmap length (total amount of key value pairs).
Definition tinyhash.c:81
void th_free(th_t *th)
Free a hashmap.
Definition tinyhash.c:67
th_iterator_t *(* th_begin_iterator_func_t)(th_generic_table_t, bool)
Definition tinyhash.h:49
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.
Definition tinyhash.c:57
th_iterator_t * th_begin_iterator(th_t *th)
Return a pointer on an iterator with the first element.
Definition tinyhash.c:73
void * th_generic_table_t
Represents any table.
Definition types.h:14
void * th_any_t
Represent any type of data.
Definition types.h:8