Tinyhash
This is a library containing multiple C implementations of hashmap.
Loading...
Searching...
No Matches
Functions
table.c File Reference
#include "../common/table.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "table.h"
Include dependency graph for table.c:

Go to the source code of this file.

Functions

static bool th_sc_table_put_with_key (th_sc_table_t *table, th_key_t *key, th_any_t value)
 Insert a value within the table with an already existing key.
 
void th_sc_table_init (th_sc_table_t *table)
 Initialize a separate chaining table.
 
static th_sc_table_t_th_sc_table_create ()
 Allocate then return a new table.
 
th_generic_table_t th_sc_table_create ()
 Return an allocated separate chaining table.
 
static bool th_sc_table_copy (th_sc_table_t *dest, th_sc_table_t *src)
 Copy and rehash every value from a table to another. Return true on success.
 
static bool th_sc_table_increase (th_sc_table_t *table)
 Increase the size of a table.
 
static th_sc_entry_tth_sc_table_find (th_sc_table_t *table, th_key_t *key)
 Returns a bucket (entry) depending on a key. Return NULL if the entry does not exist.
 
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.
 
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.
 
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.
 
void th_sc_table_free (th_generic_table_t generic_table)
 Free an separate chaining table.
 
static void th_sc_iterator_copy_entry (th_iterator_t *it, th_sc_entry_t *entry)
 
static bool th_sc_iterator_next (th_iterator_t **ptr)
 Get the next key value pair if it exists.
 
th_iterator_tth_sc_iterator_begin (th_generic_table_t generic_table, bool is_begin)
 Return a new iterator.
 
int th_sc_table_len (th_generic_table_t generic_table)
 Returns the table length.
 

Function Documentation

◆ _th_sc_table_create()

static th_sc_table_t * _th_sc_table_create ( )
static

Allocate then return a new table.

Returns
th_sc_table_t*

Definition at line 24 of file table.c.

References th_sc_table_init().

Referenced by th_sc_table_create().

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

◆ th_sc_iterator_begin()

th_iterator_t * th_sc_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 287 of file table.c.

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

Here is the call graph for this function:

◆ th_sc_iterator_copy_entry()

static void th_sc_iterator_copy_entry ( th_iterator_t * it,
th_sc_entry_t * entry )
static

Definition at line 245 of file table.c.

References th_iterator_s::current, th_iterator_s::key, th_sc_entry_s::key, th_iterator_s::value, and th_sc_entry_s::value.

Referenced by th_sc_iterator_next().

Here is the caller graph for this function:

◆ th_sc_iterator_next()

static bool th_sc_iterator_next ( th_iterator_t ** ptr)
static

Get the next key value pair if it exists.

Parameters
ptr
Returns
true
false

Definition at line 258 of file table.c.

References th_sc_table_t::capacity, th_iterator_s::current, th_sc_table_t::entries, th_iterator_s::generic_table, th_iterator_s::index, th_sc_entry_s::next, and th_sc_iterator_copy_entry().

Referenced by th_sc_iterator_begin().

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

◆ th_sc_table_copy()

static bool th_sc_table_copy ( th_sc_table_t * dest,
th_sc_table_t * src )
static

Copy and rehash every value from a table to another. Return true on success.

Parameters
dest
src
Returns
true
false

Definition at line 49 of file table.c.

References th_sc_table_t::capacity, th_sc_table_t::entries, th_sc_entry_s::key, th_sc_entry_s::next, th_sc_table_put_with_key(), and th_sc_entry_s::value.

Referenced by th_sc_table_increase().

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

◆ th_sc_table_create()

th_generic_table_t th_sc_table_create ( )

Return an allocated separate chaining table.

Returns
th_generic_table_t

Definition at line 36 of file table.c.

References _th_sc_table_create().

Here is the call graph for this function:

◆ th_sc_table_delete()

bool th_sc_table_delete ( th_generic_table_t table,
th_any_t data,
size_t data_size )

Delete a key value pair in an separate chaining table. Return true on success.

Parameters
table
data
data_size
Returns
true
false

Definition at line 191 of file table.c.

References th_sc_table_t::capacity, th_sc_table_t::count, th_sc_table_t::entries, th_key_t::hash, th_sc_entry_s::key, th_sc_entry_s::next, th_sc_entry_s::previous, th_key_create(), and th_sc_table_find().

Here is the call graph for this function:

◆ th_sc_table_find()

static th_sc_entry_t * th_sc_table_find ( th_sc_table_t * table,
th_key_t * key )
static

Returns a bucket (entry) depending on a key. Return NULL if the entry does not exist.

Parameters
table
key
Returns
th_sc_entry_t*

Definition at line 113 of file table.c.

References th_sc_table_t::capacity, th_sc_table_t::entries, th_key_t::hash, th_sc_entry_s::key, th_sc_entry_s::next, and th_key_is_equal().

Referenced by th_sc_table_delete(), th_sc_table_get(), and th_sc_table_put_with_key().

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

◆ th_sc_table_free()

void th_sc_table_free ( th_generic_table_t table)

Free an separate chaining table.

Parameters
table

Definition at line 222 of file table.c.

References th_sc_table_t::capacity, th_sc_table_t::entries, th_sc_entry_s::next, and th_sc_table_init().

Referenced by th_sc_table_increase().

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

◆ th_sc_table_get()

th_any_t th_sc_table_get ( th_generic_table_t table,
th_any_t data,
size_t data_size )

Get a value from an separate chaining table. Return NULL if it does exist.

Parameters
table
data
data_size
Returns
th_any_t

Definition at line 133 of file table.c.

References th_key_create(), th_sc_table_find(), and th_sc_entry_s::value.

Here is the call graph for this function:

◆ th_sc_table_increase()

static bool th_sc_table_increase ( th_sc_table_t * table)
static

Increase the size of a table.

Parameters
table
Returns
true
false

Definition at line 76 of file table.c.

References th_sc_table_t::capacity, th_sc_table_t::entries, th_sc_table_copy(), th_sc_table_free(), th_sc_table_init(), and TH_TABLE_NEXT_CAPACITY.

Referenced by th_sc_table_put_with_key().

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

◆ th_sc_table_init()

void th_sc_table_init ( th_sc_table_t * table)

Initialize a separate chaining table.

Parameters
table

Definition at line 13 of file table.c.

References th_sc_table_t::capacity, th_sc_table_t::count, and th_sc_table_t::entries.

Referenced by _th_sc_table_create(), th_sc_table_free(), and th_sc_table_increase().

Here is the caller graph for this function:

◆ th_sc_table_len()

int th_sc_table_len ( th_generic_table_t generic_table)

Returns the table length.

Parameters
generic_table
Returns
int

Definition at line 304 of file table.c.

◆ th_sc_table_put()

bool th_sc_table_put ( th_generic_table_t 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.

Parameters
table
data
data_size
value
Returns
true
false

Definition at line 183 of file table.c.

References th_key_create(), and th_sc_table_put_with_key().

Here is the call graph for this function:

◆ th_sc_table_put_with_key()

static bool th_sc_table_put_with_key ( th_sc_table_t * table,
th_key_t * key,
th_any_t value )
static

Insert a value within the table with an already existing key.

Parameters
table
key
value
Returns
true
false

Definition at line 155 of file table.c.

References th_sc_table_t::capacity, th_sc_table_t::count, th_sc_table_t::entries, th_key_t::hash, th_sc_entry_add(), th_sc_table_find(), th_sc_table_increase(), and th_sc_entry_s::value.

Referenced by th_sc_table_copy(), and th_sc_table_put().

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