Tinyhash
This is a library containing multiple C implementations of hashmap.
Loading...
Searching...
No Matches
key.c
Go to the documentation of this file.
1#include <string.h>
2
3#include "hash.h"
4#include "key.h"
5
6th_key_t th_key_create(th_any_t data, size_t size) {
7 return (th_key_t){
8 .hash = th_hash(data, size),
9 .size = size,
10 .data = data,
11 };
12}
13
14bool th_key_is_equal(th_key_t *first, th_key_t *second) {
15 if (first == NULL || second == NULL) {
16 return false;
17 }
18
19 if (first->size != second->size) {
20 return false;
21 }
22
23 return memcmp(first->data, second->data, first->size) == 0;
24}
uint32_t th_hash(uint8_t *bytes, size_t size)
Compute an unsigned int from bytes.
Definition hash.c:16
th_key_t th_key_create(th_any_t data, size_t size)
Create a key struct from data and size, it will automatically compute its hash.
Definition key.c:6
bool th_key_is_equal(th_key_t *first, th_key_t *second)
Key comparator function.
Definition key.c:14
Represent an entry key.
Definition key.h:14
uint32_t hash
Definition key.h:15
th_any_t data
Definition key.h:17
size_t size
Definition key.h:16
void * th_any_t
Represent any type of data.
Definition types.h:8