Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
hashtable.h
Go to the documentation of this file.
1#ifndef ARC_STD_HASHTABLE_H_
2#define ARC_STD_HASHTABLE_H_
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdint.h>
9#include <stddef.h>
10
11/**
12 * @brief the arc hashtable data type
13*/
15
16/**
17 * @brief a node that contains a key-value reference along with a linked list like node
18*/
21 void *key;
22 size_t keysize;
23
24 void *data;
26};
27
28/**
29 * @brief a hashing function ptr
30 *
31 * @param key value to hash
32 * @param keysize should be sizeof(key) before key is a void ptr
33 * @param hashval value of hash, does not need to be within range of buckets
34*/
35typedef void (* ARC_Hashtable_Hash)(void *key, size_t *keysize, uint32_t *hashval);
36
37/**
38 * @brief key comparison function ptr
39 *
40 * @param key1 first key
41 * @param key2 second key
42 *
43 * @return 0 when keys match
44*/
45typedef int8_t (* ARC_Hashtable_KeyCompare)(void *key1, size_t *key1size, void *key2, size_t *key2size);
46
47/**
48 * @brief callback to allow memory freeing of nodes
49 *
50 * @param node node to be destroyed
51 * @param userdata any data the user wants to access in the callback
52*/
53typedef void (* ARC_HashtableNode_DestroyExternal)(ARC_HashtableNode *node, void *userdata);
54
55/**
56 * @brief cteates ARC_Hashtable type
57 *
58 * @param htable where to store data
59 * @param bucketsize num of nodes to create in inital table
60 * @param hash hashing function to be used, if set to NULL, CRC32 will be used
61 * @param compare comparison functon for checking keys, if set to NULL, addresses will be compared
62*/
63void ARC_Hashtable_Create(ARC_Hashtable **htable, uint32_t bucketsize, ARC_Hashtable_Hash hash, ARC_Hashtable_KeyCompare compare);
64
65/**
66 * @brief destroys ARC_Hashtable type
67 *
68 * @param htable htable that will be destroyed
69 * @param external function to allow external freeing of nodes, can be NULL
70 * @param userdata any data the user wants access to in the callback
71*/
73
74/**
75 * @brief adds value to hastable
76 *
77 * @param htable ARC_Hashtable to add to
78 * @param key key for node that is being added
79 * @param keysize sizeof key before it is passed into a void *
80 * @param data data for node that is being added
81*/
82void ARC_Hashtable_Add(ARC_Hashtable *htable, void *key, size_t keysize, void *data);
83
84/**
85 * @brief gets value from hashtable by key
86 *
87 * @param htable table to get value from
88 * @param key key to get value from table
89 * @param keysize sizeof key before it is passed into a void *
90 * @param data data retrieved from table
91*/
92void ARC_Hashtable_Get(ARC_Hashtable *htable, void *key, size_t keysize, void **data);
93
94/**
95 * @brief removes value from hashtable
96 *
97 * @param htable ARC_Hashtable to remove from
98 * @param key key of data to remove from hash table
99 * @param keysize sizeof key before it is passed into a void *
100 * @param external function to allow external freeing of data, can be NULL
101 * @param userdata any data the user wants access to in the callback
102*/
103void ARC_Hashtable_Remove(ARC_Hashtable *htable, void *key, size_t keysize, ARC_HashtableNode_DestroyExternal external, void *userdata);
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif //ARC_STD_HASHTABLE_H_
int8_t(* ARC_Hashtable_KeyCompare)(void *key1, size_t *key1size, void *key2, size_t *key2size)
key comparison function ptr
Definition hashtable.h:45
void ARC_Hashtable_Destroy(ARC_Hashtable *htable, ARC_HashtableNode_DestroyExternal external, void *userdata)
destroys ARC_Hashtable type
void(* ARC_HashtableNode_DestroyExternal)(ARC_HashtableNode *node, void *userdata)
callback to allow memory freeing of nodes
Definition hashtable.h:53
void ARC_Hashtable_Get(ARC_Hashtable *htable, void *key, size_t keysize, void **data)
gets value from hashtable by key
void ARC_Hashtable_Create(ARC_Hashtable **htable, uint32_t bucketsize, ARC_Hashtable_Hash hash, ARC_Hashtable_KeyCompare compare)
cteates ARC_Hashtable type
struct ARC_Hashtable ARC_Hashtable
the arc hashtable data type
Definition hashtable.h:14
void ARC_Hashtable_Remove(ARC_Hashtable *htable, void *key, size_t keysize, ARC_HashtableNode_DestroyExternal external, void *userdata)
removes value from hashtable
void ARC_Hashtable_Add(ARC_Hashtable *htable, void *key, size_t keysize, void *data)
adds value to hastable
void(* ARC_Hashtable_Hash)(void *key, size_t *keysize, uint32_t *hashval)
a hashing function ptr
Definition hashtable.h:35
ARC_HashtableNode * node
Definition hashtable.h:25