asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
flat_tree.h
1
11
27
28#ifndef ASRT_FLAT_TREE_H
29#define ASRT_FLAT_TREE_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include "./allocator.h"
36#include "./status.h"
37#include "./util.h"
38
39#include <stdint.h>
40#include <string.h>
41
42typedef uint32_t asrt_flat_id;
43
45enum asrt_flat_stype
46{
47 ASRT_FLAT_STYPE_NONE = 0,
48 ASRT_FLAT_STYPE_STR = 1,
49 ASRT_FLAT_STYPE_U32 = 2,
50 ASRT_FLAT_STYPE_FLOAT = 3,
51 ASRT_FLAT_STYPE_BOOL = 4,
52 ASRT_FLAT_STYPE_NULL = 5,
53 ASRT_FLAT_STYPE_I32 = 6,
54};
55
57enum asrt_flat_ctype
58{
59 ASRT_FLAT_CTYPE_NONE = 0,
60 ASRT_FLAT_CTYPE_OBJECT = 7,
61 ASRT_FLAT_CTYPE_ARRAY = 8,
62};
63
66typedef uint8_t asrt_flat_value_type;
67
69{
70 asrt_flat_id first_child;
71 asrt_flat_id last_child;
72};
73
75{
76 char const* str_val;
77 uint32_t u32_val;
78 int32_t i32_val;
79 float float_val;
80 uint32_t bool_val;
81};
82
84{
85 union asrt_flat_scalar s;
86 struct asrt_flat_child_list cont;
87};
88
90{
91 asrt_flat_value_type type;
92 union asrt_flat_data data;
93};
94
96{
97 struct asrt_flat_value value;
98 char const* key;
99 asrt_flat_id next_sibling;
100};
101
104{
105 struct asrt_flat_node* nodes;
106 uint32_t node_count;
107};
108
109enum asrt_status asrt_flat_block_init(
110 struct asrt_flat_block* block,
111 struct asrt_allocator* alloc,
112 uint32_t node_capacity );
113
114enum asrt_status asrt_flat_block_deinit(
115 struct asrt_flat_block* block,
116 struct asrt_allocator* alloc,
117 uint32_t node_capacity );
118
121{
122 struct asrt_allocator alloc;
123
124 struct asrt_flat_block* blocks;
125 uint32_t block_capacity;
126
127 uint32_t node_capacity;
128};
129
130enum asrt_status asrt_flat_tree_init(
131 struct asrt_flat_tree* tree,
132 struct asrt_allocator alloc,
133 uint32_t block_capacity,
134 uint32_t node_capacity );
135
139enum asrt_status asrt_flat_tree_append_scalar(
140 struct asrt_flat_tree* tree,
141 asrt_flat_id parent_id,
142 asrt_flat_id node_id,
143 char const* key,
144 asrt_flat_value_type type,
145 union asrt_flat_scalar scalar );
146
148enum asrt_status asrt_flat_tree_append_cont(
149 struct asrt_flat_tree* tree,
150 asrt_flat_id parent_id,
151 asrt_flat_id node_id,
152 char const* key,
153 asrt_flat_value_type type );
154
156{
157 asrt_flat_id id;
158 char const* key;
159 struct asrt_flat_value value;
160 asrt_flat_id next_sibling;
161};
162
164enum asrt_status asrt_flat_tree_query(
165 struct asrt_flat_tree const* tree,
166 asrt_flat_id node_id,
167 struct asrt_flat_query_result* result );
168
170enum asrt_status asrt_flat_tree_find_by_key(
171 struct asrt_flat_tree* tree,
172 asrt_flat_id parent_id,
173 char const* key,
174 struct asrt_flat_query_result* result );
175
176enum asrt_status asrt_flat_tree_deinit( struct asrt_flat_tree* tree );
177
180size_t asrt_flat_value_wire_size( struct asrt_flat_value v );
181
184void asrt_flat_value_write( uint8_t** p, struct asrt_flat_value v );
185
188enum asrt_status asrt_flat_value_decode(
189 struct asrt_span* buff,
190 uint8_t raw_type,
191 struct asrt_flat_value* val );
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: allocator.h:28
Contiguous array of nodes. Lazily allocated per block.
Definition: flat_tree.h:104
Definition: flat_tree.h:69
Definition: flat_tree.h:96
char const * key
Owned copy. Non-NULL for OBJECT children, NULL for ARRAY children.
Definition: flat_tree.h:98
asrt_flat_id next_sibling
0 = no next sibling.
Definition: flat_tree.h:99
Definition: flat_tree.h:156
asrt_flat_id next_sibling
0 = no next sibling.
Definition: flat_tree.h:160
node_id maps to blocks[node_id / node_capacity][node_id % node_capacity].
Definition: flat_tree.h:121
uint32_t node_capacity
Nodes per block, fixed at init.
Definition: flat_tree.h:127
Definition: flat_tree.h:90
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: span.h:23
Definition: flat_tree.h:84
Definition: flat_tree.h:75