8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
0
|
// util/map.h, version 0.1.2 |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
1
|
// Map utility header file from libutil |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
2
|
// Copyright (C) 2021, Jakob Wakeling |
7f427d9 |
Jamozed |
2022-03-06 12:55:13 |
3
|
// MIT Licence |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
4
|
|
ce5f15c |
Jamozed |
2022-01-06 00:56:12 |
5
|
#ifndef UTIL_MAP_H_NB53CJJ8 |
ce5f15c |
Jamozed |
2022-01-06 00:56:12 |
6
|
#define UTIL_MAP_H_NB53CJJ8 |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
7
|
|
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
8
|
#ifdef __cplusplus |
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
9
|
extern "C" { |
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
10
|
#endif |
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
11
|
|
6217745 |
Jamozed |
2021-12-08 20:00:24 |
12
|
#include "util.h" |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
13
|
|
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
14
|
typedef struct { |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
15
|
struct { u64 h; char *k; void *v; } *a; |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
16
|
UINT al, ac; void (*free)(void *); |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
17
|
} map; |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
18
|
|
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
19
|
// #define MAP_INIT(type, free) map_init(sizeof (type), (free)) |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
20
|
// #define MAP_INSERT(m, k, v) map_insert(m, k, (void *)(UINT)(e)) |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
21
|
|
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
22
|
/* This should be used for debugging or testing only. */ |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
23
|
extern UINT map_initial_capacity; |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
24
|
|
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
25
|
extern map map_init(void (*free)(void *)); |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
26
|
extern void map_free(map *m); |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
27
|
|
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
28
|
extern void map_insert(map *m, char *k, void *v); |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
29
|
extern void *map_lookup(map *m, char *k); |
7af2131 |
Jamozed |
2022-01-06 00:39:34 |
30
|
extern void *map_remove(map *m, char *k); |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
31
|
|
6217745 |
Jamozed |
2021-12-08 20:00:24 |
32
|
extern void map_print(map *m); |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
33
|
extern void map_debug(map *m); |
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
34
|
|
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
35
|
#ifdef __cplusplus |
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
36
|
} // extern "C" |
8a5f06f |
Jamozed |
2022-02-09 20:04:50 |
37
|
#endif |
6217745 |
Jamozed |
2021-12-08 20:00:24 |
38
|
|
ce5f15c |
Jamozed |
2022-01-06 00:56:12 |
39
|
#endif // UTIL_MAP_H_NB53CJJ8 |
|
|
|
40
|
|