1 | // This file is part of SmallBASIC |
2 | // |
3 | // Support for dictionary/associative array variables |
4 | // |
5 | // This program is distributed under the terms of the GPL v2.0 or later |
6 | // Download the GNU Public License (GPL) from www.gnu.org |
7 | // |
8 | // Copyright(C) 2007-2019 Chris Warren-Smith. |
9 | |
10 | #ifndef _HASHMAP_H_ |
11 | #define _HASHMAP_H_ |
12 | |
13 | #include "common/var.h" |
14 | |
15 | /** |
16 | * Callback structure for hashmap_foreach |
17 | */ |
18 | typedef struct hashmap_cb { |
19 | var_p_t var; |
20 | var_p_t parent; |
21 | char *buffer; |
22 | int count; |
23 | int index; |
24 | int start; |
25 | } hashmap_cb; |
26 | |
27 | typedef int (*hashmap_foreach_func)(hashmap_cb *cb, var_p_t k, var_p_t v); |
28 | |
29 | void hashmap_create(var_p_t map, int size); |
30 | int hashmap_destroy(var_p_t map); |
31 | var_p_t hashmap_put(var_p_t map, const char *key, int length); |
32 | var_p_t hashmap_putc(var_p_t map, const char *key, int length); |
33 | var_p_t hashmap_putv(var_p_t map, const var_p_t key); |
34 | var_p_t hashmap_get(var_p_t map, const char *key); |
35 | void hashmap_foreach(var_p_t map, hashmap_foreach_func func, hashmap_cb *data); |
36 | |
37 | #endif /* !_HASHMAP_H_ */ |
38 | |
39 | |