blob: e1a016d36ebca75a49900d7c27eadef08c88b8f1 (
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
25
26
27
28
29
30
|
#ifndef TSL_HASH_MAP_H
#define TSL_HASH_MAP_H
#include "../forward_decl.h"
#include <stdint.h>
#include <stddef.h>
/* TODO: Optimize small hash map by using the members of the struct instead of allocating on heap */
typedef struct {
void *buckets_data; /* value=TslHashMapNode */
size_t buckets_size;
size_t buckets_capacity;
} TslHashMap;
void tsl_hash_map_init(TslHashMap *self);
int tsl_hash_map_insert(TslHashMap *self, const TslValue *key, TslValue *value);
/*
Get a reference to the value by key @key, or NULL if it doesn't exist.
The returned pointer is only valid until until reallocation after after insert inserting a new value into the hash map.
*/
TslValue* tsl_hash_map_get(TslHashMap *self, const TslValue *key);
/*
Get a reference to the value by key @key, or insert a new value for the key (a TslValue).
Returns NULL on failure.
The returned pointer is only valid until until reallocation after after insert inserting a new value into the hash map.
*/
TslValue* tsl_hash_map_get_or_create(TslHashMap *self, const TslValue *key);
#endif /* TSL_HASH_MAP_H */
|