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

Go to the source code of this file.

Classes

struct  th_oa_table_t
 

Macros

#define TH_OA_LOAD_FACTOR   0.75
 Load factor.
 

Functions

void th_oa_table_init (th_oa_table_t *table)
 Initialize open adressing table values.
 
th_generic_table_t th_oa_table_create ()
 Return an allocated open addressing table struct.
 
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.
 
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.
 
void th_oa_table_free (th_generic_table_t table)
 Free an open addressing table.
 
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.
 
th_iterator_tth_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.
 

Macro Definition Documentation

◆ TH_OA_LOAD_FACTOR

#define TH_OA_LOAD_FACTOR   0.75

Load factor.

Definition at line 16 of file table.h.

Referenced by th_oa_table_put_with_key().

Function Documentation

◆ th_oa_iterator_begin()

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.

Parameters
generic_table
is_begin
Returns
th_iterator_t*

Definition at line 272 of file table.c.

References th_iterator_s::index, th_iterator_create(), and th_oa_iterator_next().

Here is the call graph for this function:

◆ th_oa_table_create()

th_generic_table_t th_oa_table_create ( )

Return an allocated open addressing table struct.

Returns
th_generic_table_t

Definition at line 38 of file table.c.

References _th_oa_table_create().

Here is the call graph for this function:

◆ th_oa_table_delete()

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.

Parameters
table
data
data_size
Returns
true
false

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().

Here is the call graph for this function:

◆ th_oa_table_free()

void th_oa_table_free ( th_generic_table_t table)

Free an open addressing table.

Parameters
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().

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

◆ th_oa_table_get()

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.

Parameters
table
data
data_size
Returns
th_any_t

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.

Here is the call graph for this function:

◆ th_oa_table_init()

void th_oa_table_init ( th_oa_table_t * table)

Initialize open adressing table values.

Parameters
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().

Here is the caller graph for this function:

◆ th_oa_table_len()

int th_oa_table_len ( th_generic_table_t generic_table)

Returns the table length.

Parameters
generic_table
Returns
int

Definition at line 289 of file table.c.

◆ th_oa_table_put()

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.

Parameters
table
data
data_size
value
Returns
true
false

Definition at line 189 of file table.c.

References th_key_create(), and th_oa_table_put_with_key().

Here is the call graph for this function: