-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashmap.h
45 lines (30 loc) · 842 Bytes
/
hashmap.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef FILANG_HASHMAP_H
#define FILANG_HASHMAP_H
#include <stdint.h>
#include <stddef.h>
#include "value.h"
#include "value.h"
#include "strings.h"
/*
* Robin Hood Hashmap implementation
*/
typedef struct {
Value key;
Value value;
} Entry;
typedef struct {
int count;
int capacity;
Entry *entries;
} Hashmap;
uint32_t hash_string(const char *key, int length);
void init_hashmap(Hashmap *map);
void free_hashmap(Hashmap *map);
bool add_entry(Hashmap *map, Value key, Value value);
Entry *get_entry(Hashmap *map, Value key);
void erase_entry(Hashmap *map, Value key);
bool contains(Hashmap *map, Value key);
ObjString *get_string_entry(Hashmap *map, const char *key, int length, uint32_t hash);
#define HASHMAP_MAX_LOAD 0.57
#define IS_EMPTY(entry) ((entry).key.type == TYPE_NIL)
#endif //FILANG_HASHMAP_H