1 /*
2 * Copyright (C) 2018 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
7 #ifndef LEXBOR_BST_MAP_H
8 #define LEXBOR_BST_MAP_H
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 #include "lexbor/core/bst.h"
15 #include "lexbor/core/str.h"
16 #include "lexbor/core/mraw.h"
17 #include "lexbor/core/dobject.h"
18
19
20 typedef struct {
21 lexbor_str_t str;
22 void *value;
23 }
24 lexbor_bst_map_entry_t;
25
26 typedef struct {
27 lexbor_bst_t *bst;
28 lexbor_mraw_t *mraw;
29 lexbor_dobject_t *entries;
30
31 }
32 lexbor_bst_map_t;
33
34
35 LXB_API lexbor_bst_map_t *
36 lexbor_bst_map_create(void);
37
38 LXB_API lxb_status_t
39 lexbor_bst_map_init(lexbor_bst_map_t *bst_map, size_t size);
40
41 LXB_API void
42 lexbor_bst_map_clean(lexbor_bst_map_t *bst_map);
43
44 LXB_API lexbor_bst_map_t *
45 lexbor_bst_map_destroy(lexbor_bst_map_t *bst_map, bool self_destroy);
46
47
48 LXB_API lexbor_bst_map_entry_t *
49 lexbor_bst_map_search(lexbor_bst_map_t *bst_map, lexbor_bst_entry_t *scope,
50 const lxb_char_t *key, size_t key_len);
51
52 LXB_API lexbor_bst_map_entry_t *
53 lexbor_bst_map_insert(lexbor_bst_map_t *bst_map, lexbor_bst_entry_t **scope,
54 const lxb_char_t *key, size_t key_len, void *value);
55
56 LXB_API lexbor_bst_map_entry_t *
57 lexbor_bst_map_insert_not_exists(lexbor_bst_map_t *bst_map,
58 lexbor_bst_entry_t **scope,
59 const lxb_char_t *key, size_t key_len);
60
61 LXB_API void *
62 lexbor_bst_map_remove(lexbor_bst_map_t *bst_map, lexbor_bst_entry_t **scope,
63 const lxb_char_t *key, size_t key_len);
64
65
66 /*
67 * Inline functions
68 */
69 lxb_inline lexbor_mraw_t *
lexbor_bst_map_mraw(lexbor_bst_map_t * bst_map)70 lexbor_bst_map_mraw(lexbor_bst_map_t *bst_map)
71 {
72 return bst_map->mraw;
73 }
74
75 /*
76 * No inline functions for ABI.
77 */
78 LXB_API lexbor_mraw_t *
79 lexbor_bst_map_mraw_noi(lexbor_bst_map_t *bst_map);
80
81
82 #ifdef __cplusplus
83 } /* extern "C" */
84 #endif
85
86 #endif /* LEXBOR_BST_MAP_H */
87
88