aboutsummaryrefslogtreecommitdiff
path: root/include/std/hash_map.h
blob: f3a3a6da537e4f5db0194715978fb9ba97fac70f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef TSL_HASH_MAP_H
#define TSL_HASH_MAP_H

#include "string_view.h"
#include <stdint.h>

typedef uint64_t (*TslHashFunc)(const void *data, size_t size);

/* TODO: Optimize small hash map by using the members of the struct instead of allocating on heap */
typedef struct {
    void *buckets_data; /* value=TslHashMapNode<void*>, data=|hash(uint64_t) + key_size(size_t) + key_data(...) data_size(size_t) + data_data(...)| */
    size_t buckets_size;
    size_t buckets_capacity;
    size_t num_items;
} TslHashMap;

void tsl_hash_map_init(TslHashMap *self);
void tsl_hash_map_deinit(TslHashMap *self);

int tsl_hash_map_insert(TslHashMap *self, const TslStringView *key, const void *data, size_t size, TslHashFunc hash_func);
/* Get a reference to the value by key @key */
void* tsl_hash_map_get(TslHashMap *self, const TslStringView *key, TslHashFunc hash_func);

#endif /* TSL_HASH_MAP_H */