libcproject
C static library easier to use than libc (C standard library).
hash_map.h File Reference
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "linked_list.h"
#include "types.h"
Include dependency graph for hash_map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  hash_map
 Hash map data structure. More...
 
struct  hash_map_item
 Hash map item data structure. More...
 

Macros

#define HASH_MAP_INITIAL_CAPACITY   10
 

Functions

uint64_t hash (string_t key, size_t capacity)
 Hash function (using SipHash 1-3 algorithm). More...
 
struct hash_maphash_map_initialization ()
 Hash map initialization. More...
 
void hash_map_add (struct hash_map *hash_map, string_t key, void *data)
 Add an item to the hash map. More...
 
void hash_map_remove (struct hash_map *hash_map, string_t key)
 Remove an item from the hash map. More...
 
void * hash_map_get (struct hash_map *hash_map, string_t key)
 Get an item from the hash map. More...
 
bool hash_map_contains_key (struct hash_map *hash_map, string_t key)
 Check if the hash map contains a key. More...
 
string_thash_map_get_keys (struct hash_map *hash_map)
 Get the hash map keys. More...
 
void hash_map_free (struct hash_map *hash_map)
 Frees the hash map. More...
 

Data Structure Documentation

◆ hash_map

struct hash_map

Hash map data structure.

Since
v2.0.0

Definition at line 20 of file hash_map.h.

Collaboration diagram for hash_map:
Data Fields
struct linked_list ** items
size_t length
size_t capacity

◆ hash_map_item

struct hash_map_item

Hash map item data structure.

Since
v2.0.0

Definition at line 31 of file hash_map.h.

Data Fields
void * data
string_t key

Macro Definition Documentation

◆ HASH_MAP_INITIAL_CAPACITY

#define HASH_MAP_INITIAL_CAPACITY   10

Definition at line 14 of file hash_map.h.

Function Documentation

◆ hash()

uint64_t hash ( string_t  key,
size_t  capacity 
)

Hash function (using SipHash 1-3 algorithm).

See also
https://en.wikipedia.org/wiki/SipHash
https://github.com/veorq/SipHash
Parameters
key
capacity
Returns
uint64_t
Since
v2.0.0

◆ hash_map_initialization()

struct hash_map* hash_map_initialization ( )

Hash map initialization.

Returns
struct hash_map*
Since
v2.0.0

◆ hash_map_add()

void hash_map_add ( struct hash_map hash_map,
string_t  key,
void *  data 
)

Add an item to the hash map.

Parameters
hash_map
key
data
Since
v2.0.0

◆ hash_map_remove()

void hash_map_remove ( struct hash_map hash_map,
string_t  key 
)

Remove an item from the hash map.

Parameters
hash_map
key
Since
v2.0.0

◆ hash_map_get()

void* hash_map_get ( struct hash_map hash_map,
string_t  key 
)

Get an item from the hash map.

Parameters
hash_map
key
Returns
void*
Since
v2.0.0

◆ hash_map_contains_key()

bool hash_map_contains_key ( struct hash_map hash_map,
string_t  key 
)

Check if the hash map contains a key.

Parameters
hash_map
key
Returns
bool
Since
v2.0.0

◆ hash_map_get_keys()

string_t* hash_map_get_keys ( struct hash_map hash_map)

Get the hash map keys.

Parameters
hash_map
Returns
string_t*
Since
v2.0.0

◆ hash_map_free()

void hash_map_free ( struct hash_map hash_map)

Frees the hash map.

Parameters
hash_map
Since
v3.0.0