@based/db 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/darwin_aarch64/include/selva/db.h +1 -1
- package/dist/lib/darwin_aarch64/include/selva/fields.h +6 -3
- package/dist/lib/darwin_aarch64/include/selva/types.h +2 -1
- package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v25.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +324 -0
- package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +345 -0
- package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
- package/dist/lib/linux_aarch64/include/queue.h +627 -0
- package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
- package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
- package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_aarch64/include/selva/colvec.h +71 -0
- package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +450 -0
- package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +27 -0
- package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +18 -0
- package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_aarch64/include/selva/fields.h +344 -0
- package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_aarch64/include/selva/hll.h +85 -0
- package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_aarch64/include/selva/membar.h +32 -0
- package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +49 -0
- package/dist/lib/linux_aarch64/include/selva/selva_lang.h +112 -0
- package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +683 -0
- package/dist/lib/linux_aarch64/include/selva/sort.h +140 -0
- package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +116 -0
- package/dist/lib/linux_aarch64/include/selva/vector.h +35 -0
- package/dist/lib/linux_aarch64/include/selva_error.h +140 -0
- package/dist/lib/linux_aarch64/include/selva_lang_code.h +160 -0
- package/dist/lib/linux_aarch64/include/tree.h +852 -0
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v25.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +324 -0
- package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +345 -0
- package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
- package/dist/lib/linux_x86_64/include/queue.h +627 -0
- package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
- package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
- package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_x86_64/include/selva/colvec.h +71 -0
- package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +450 -0
- package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +27 -0
- package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +18 -0
- package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_x86_64/include/selva/fields.h +344 -0
- package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_x86_64/include/selva/hll.h +85 -0
- package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_x86_64/include/selva/membar.h +32 -0
- package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +49 -0
- package/dist/lib/linux_x86_64/include/selva/selva_lang.h +112 -0
- package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +683 -0
- package/dist/lib/linux_x86_64/include/selva/sort.h +140 -0
- package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +116 -0
- package/dist/lib/linux_x86_64/include/selva/vector.h +35 -0
- package/dist/lib/linux_x86_64/include/selva_error.h +140 -0
- package/dist/lib/linux_x86_64/include/selva_lang_code.h +160 -0
- package/dist/lib/linux_x86_64/include/tree.h +852 -0
- package/dist/lib/linux_x86_64/libdeflate.so +0 -0
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v25.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/dist/src/client/modify/props/fixed.js +1 -1
- package/dist/src/client/modify/types.d.ts +1 -0
- package/dist/src/client/modify/types.js +1 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +1 -0
- package/dist/src/client/query/BasedDbQuery.js +14 -0
- package/dist/src/client/query/BasedQueryResponse.js +1 -1
- package/dist/src/client/query/filter/filter.js +26 -17
- package/dist/src/client/query/filter/toByteCode.js +18 -9
- package/dist/src/client/query/include/utils.d.ts +2 -2
- package/dist/src/client/query/include/utils.js +7 -6
- package/dist/src/client/query/include/walk.js +20 -2
- package/dist/src/client/query/queryDefToReadSchema.js +1 -1
- package/dist/src/client/query/subscription/index.js +6 -6
- package/dist/src/client/query/subscription/toByteCode.js +11 -6
- package/dist/src/client/query/types.d.ts +17 -1
- package/dist/src/client/query/types.js +23 -0
- package/dist/src/server/schemaSelvaBuffer.js +8 -11
- package/dist/src/server/subscription.js +0 -12
- package/package.json +7 -7
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024-2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <assert.h>
|
|
8
|
+
#include <stddef.h>
|
|
9
|
+
#include <stdint.h>
|
|
10
|
+
#include <sys/types.h>
|
|
11
|
+
#include "selva/_export.h"
|
|
12
|
+
#include "selva/types.h"
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* TODO Don't like this one but it compiles.
|
|
16
|
+
* We should have something with selva_hash_state;
|
|
17
|
+
*/
|
|
18
|
+
struct XXH3_state_s;
|
|
19
|
+
|
|
20
|
+
struct selva_dump_common_data {
|
|
21
|
+
/**
|
|
22
|
+
* Pointer to data returned here when loading; Data read from here when saving.
|
|
23
|
+
*/
|
|
24
|
+
const void *meta_data __pcounted_by(meta_len);
|
|
25
|
+
size_t meta_len;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Can be nullptr. Also set errlog_size to 0.
|
|
29
|
+
*/
|
|
30
|
+
char *errlog_buf __pcounted_by(errlog_size);
|
|
31
|
+
size_t errlog_size;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a new DB instance.
|
|
36
|
+
*/
|
|
37
|
+
SELVA_EXPORT
|
|
38
|
+
struct SelvaDb *selva_db_create(void);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Destroy a DB instance.
|
|
42
|
+
*/
|
|
43
|
+
SELVA_EXPORT
|
|
44
|
+
void selva_db_destroy(struct SelvaDb *db) __attribute__((nonnull));
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a new node type with a schema.
|
|
48
|
+
* @param type must not exist before.
|
|
49
|
+
*/
|
|
50
|
+
SELVA_EXPORT
|
|
51
|
+
int selva_db_create_type(struct SelvaDb *db, node_type_t type, const uint8_t *schema_buf, size_t schema_len) __attribute__((nonnull));
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Save the common/shared data of the database.
|
|
55
|
+
*/
|
|
56
|
+
SELVA_EXPORT
|
|
57
|
+
int selva_dump_save_common(struct SelvaDb *db, struct selva_dump_common_data *com, const char *filename) __attribute__((nonnull));
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Save a nodes block starting from start.
|
|
61
|
+
*/
|
|
62
|
+
SELVA_EXPORT
|
|
63
|
+
int selva_dump_save_block(struct SelvaDb *db, struct SelvaTypeEntry *te, const char *filename, node_id_t start, selva_hash128_t *range_hash_out) __attribute__((nonnull));
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* **Usage:**
|
|
67
|
+
* ```c
|
|
68
|
+
* struct SelvaDb *db = selva_db_create();
|
|
69
|
+
* selva_dump_load_common(db, filename_common);
|
|
70
|
+
* selva_dump_load_block(db, filename_range_n);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
SELVA_EXPORT
|
|
74
|
+
int selva_dump_load_common(struct SelvaDb *db, struct selva_dump_common_data *com, const char *filename) __attribute__((nonnull));
|
|
75
|
+
|
|
76
|
+
SELVA_EXPORT
|
|
77
|
+
int selva_dump_load_block(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Find a type by type id.
|
|
81
|
+
*/
|
|
82
|
+
SELVA_EXPORT
|
|
83
|
+
struct SelvaTypeEntry *selva_get_type_by_index(const struct SelvaDb *db, node_type_t type) __attribute__((nonnull));
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get the type for node.
|
|
87
|
+
*/
|
|
88
|
+
SELVA_EXPORT
|
|
89
|
+
struct SelvaTypeEntry *selva_get_type_by_node(const struct SelvaDb *db, struct SelvaNode *node) __attribute__((nonnull, pure));
|
|
90
|
+
|
|
91
|
+
SELVA_EXPORT
|
|
92
|
+
inline block_id_t selva_get_block_capacity(const struct SelvaTypeEntry *te)
|
|
93
|
+
#ifndef __zig
|
|
94
|
+
{
|
|
95
|
+
return te->blocks->block_capacity;
|
|
96
|
+
}
|
|
97
|
+
#else
|
|
98
|
+
;
|
|
99
|
+
#endif
|
|
100
|
+
|
|
101
|
+
inline block_id_t selva_node_id2block_i3(block_id_t block_capacity, node_id_t node_id)
|
|
102
|
+
{
|
|
103
|
+
assert(node_id > 0);
|
|
104
|
+
return ((node_id - 1) - ((node_id - 1) % block_capacity)) / block_capacity;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
SELVA_EXPORT
|
|
108
|
+
inline block_id_t selva_node_id2block_i(const struct SelvaTypeBlocks *blocks, node_id_t node_id)
|
|
109
|
+
#ifndef __zig
|
|
110
|
+
{
|
|
111
|
+
return selva_node_id2block_i3(blocks->block_capacity, node_id);
|
|
112
|
+
}
|
|
113
|
+
#else
|
|
114
|
+
;
|
|
115
|
+
#endif
|
|
116
|
+
|
|
117
|
+
SELVA_EXPORT
|
|
118
|
+
inline block_id_t selva_node_id2block_i2(const struct SelvaTypeEntry *te, node_id_t node_id)
|
|
119
|
+
#ifndef __zig
|
|
120
|
+
{
|
|
121
|
+
return selva_node_id2block_i(te->blocks, node_id);
|
|
122
|
+
}
|
|
123
|
+
#else
|
|
124
|
+
;
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get the node schema for type.
|
|
129
|
+
*/
|
|
130
|
+
SELVA_EXPORT
|
|
131
|
+
__attribute__((nonnull, pure))
|
|
132
|
+
inline const struct SelvaNodeSchema *selva_get_ns_by_te(const struct SelvaTypeEntry *te)
|
|
133
|
+
#ifndef __zig
|
|
134
|
+
{
|
|
135
|
+
return &te->ns;
|
|
136
|
+
}
|
|
137
|
+
#else
|
|
138
|
+
;
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
SELVA_EXPORT
|
|
142
|
+
inline const struct SelvaFieldSchema *get_fs_by_fields_schema_field(const struct SelvaFieldsSchema *fields_schema, field_t field)
|
|
143
|
+
#ifndef __zig
|
|
144
|
+
{
|
|
145
|
+
if (!fields_schema || field >= fields_schema->nr_fields) {
|
|
146
|
+
return nullptr;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return &fields_schema->field_schemas[field];
|
|
150
|
+
}
|
|
151
|
+
#else
|
|
152
|
+
;
|
|
153
|
+
#endif
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get the field schema for field.
|
|
157
|
+
*/
|
|
158
|
+
SELVA_EXPORT
|
|
159
|
+
__attribute__((nonnull, pure))
|
|
160
|
+
inline const struct SelvaFieldSchema *selva_get_fs_by_te_field(const struct SelvaTypeEntry *te, field_t field)
|
|
161
|
+
#ifndef __zig
|
|
162
|
+
{
|
|
163
|
+
return get_fs_by_fields_schema_field(&te->ns.fields_schema, field);
|
|
164
|
+
}
|
|
165
|
+
#else
|
|
166
|
+
;
|
|
167
|
+
#endif
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get the field schema for field.
|
|
171
|
+
*/
|
|
172
|
+
SELVA_EXPORT
|
|
173
|
+
__attribute__((nonnull, pure))
|
|
174
|
+
inline const struct SelvaFieldSchema *selva_get_fs_by_ns_field(const struct SelvaNodeSchema *ns, field_t field)
|
|
175
|
+
#ifndef __zig
|
|
176
|
+
{
|
|
177
|
+
return get_fs_by_fields_schema_field(&ns->fields_schema, field);
|
|
178
|
+
}
|
|
179
|
+
#else
|
|
180
|
+
;
|
|
181
|
+
#endif
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get the field schema for field.
|
|
185
|
+
*/
|
|
186
|
+
SELVA_EXPORT
|
|
187
|
+
__attribute__((nonnull, pure))
|
|
188
|
+
inline const struct SelvaFieldSchema *selva_get_fs_by_node(struct SelvaDb *db, struct SelvaNode *node, field_t field)
|
|
189
|
+
#ifndef __zig
|
|
190
|
+
{
|
|
191
|
+
struct SelvaTypeEntry *type;
|
|
192
|
+
|
|
193
|
+
type = selva_get_type_by_node(db, node);
|
|
194
|
+
if (!type) {
|
|
195
|
+
return nullptr;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return selva_get_fs_by_ns_field(&type->ns, field);
|
|
199
|
+
}
|
|
200
|
+
#else
|
|
201
|
+
;
|
|
202
|
+
#endif
|
|
203
|
+
|
|
204
|
+
SELVA_EXPORT
|
|
205
|
+
#if __has_c_attribute(reproducible)
|
|
206
|
+
[[reproducible]]
|
|
207
|
+
#endif
|
|
208
|
+
inline enum SelvaFieldType selva_get_fs_type(const struct SelvaFieldSchema *fs)
|
|
209
|
+
#ifndef __zig
|
|
210
|
+
{
|
|
211
|
+
return fs->type;
|
|
212
|
+
}
|
|
213
|
+
#else
|
|
214
|
+
;
|
|
215
|
+
#endif
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Get the EdgeFieldConstraint from a ref field schema.
|
|
219
|
+
* struct EdgeFieldConstraint *efc = selva_get_edge_field_constraint(src_fs);
|
|
220
|
+
* struct SelvaTypeEntry *dst_type = selva_get_type_by_index(db, efc->dst_node_type);
|
|
221
|
+
* struct SelvaFieldSchema *dst_fs = selva_get_fs_by_node(db, dst, efc->inverse_field);
|
|
222
|
+
*/
|
|
223
|
+
SELVA_EXPORT
|
|
224
|
+
__attribute__((returns_nonnull))
|
|
225
|
+
__attribute__((nonnull))
|
|
226
|
+
inline const struct EdgeFieldConstraint *selva_get_edge_field_constraint(const struct SelvaFieldSchema *fs)
|
|
227
|
+
#ifndef __zig
|
|
228
|
+
{
|
|
229
|
+
assert(fs->type == SELVA_FIELD_TYPE_REFERENCE ||
|
|
230
|
+
fs->type == SELVA_FIELD_TYPE_REFERENCES);
|
|
231
|
+
return &fs->edge_constraint;
|
|
232
|
+
}
|
|
233
|
+
#else
|
|
234
|
+
;
|
|
235
|
+
#endif
|
|
236
|
+
|
|
237
|
+
SELVA_EXPORT
|
|
238
|
+
inline const struct SelvaFieldsSchema *selva_get_edge_field_fields_schema(struct SelvaDb *db, const struct EdgeFieldConstraint *efc)
|
|
239
|
+
#ifndef __zig
|
|
240
|
+
{
|
|
241
|
+
struct SelvaTypeEntry *te = selva_get_type_by_index(db, efc->edge_node_type);
|
|
242
|
+
|
|
243
|
+
return (te) ? &selva_get_ns_by_te(te)->fields_schema : nullptr;
|
|
244
|
+
}
|
|
245
|
+
#else
|
|
246
|
+
;
|
|
247
|
+
#endif
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Strategy for adding new node expires.
|
|
251
|
+
*/
|
|
252
|
+
enum selva_expire_node_strategy {
|
|
253
|
+
/**
|
|
254
|
+
* Ignore any existing expire and just add a new one.
|
|
255
|
+
*/
|
|
256
|
+
SELVA_EXPIRE_NODE_STRATEGY_IGNORE = 0,
|
|
257
|
+
/**
|
|
258
|
+
* Cancel adding an expire if one already exists.
|
|
259
|
+
*/
|
|
260
|
+
SELVA_EXPIRE_NODE_STRATEGY_CANCEL = 1,
|
|
261
|
+
/**
|
|
262
|
+
* Cancel the previous expire before adding a new one.
|
|
263
|
+
* TODO This will currently only cancel one previous hit.
|
|
264
|
+
*/
|
|
265
|
+
SELVA_EXPIRE_NODE_STRATEGY_CANCEL_OLD = 2,
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
SELVA_EXPORT
|
|
269
|
+
void selva_expire_node(struct SelvaDb *db, node_type_t type, node_id_t node_id, int64_t ts, enum selva_expire_node_strategy stg);
|
|
270
|
+
|
|
271
|
+
SELVA_EXPORT
|
|
272
|
+
void selva_expire_node_cancel(struct SelvaDb *db, node_type_t type, node_id_t node_id);
|
|
273
|
+
|
|
274
|
+
SELVA_EXPORT
|
|
275
|
+
void selva_db_expire_tick(struct SelvaDb *db, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx, int64_t now);
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Delete a node.
|
|
279
|
+
* @param dirty_cb is called for any newly dirty nodes in addition to the node being deleted.
|
|
280
|
+
*/
|
|
281
|
+
SELVA_EXPORT
|
|
282
|
+
void selva_del_node(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx) __attribute__((nonnull(1, 2, 3)));
|
|
283
|
+
|
|
284
|
+
SELVA_EXPORT
|
|
285
|
+
void selva_flush_node(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx);
|
|
286
|
+
|
|
287
|
+
SELVA_EXPORT
|
|
288
|
+
void selva_del_block(struct SelvaDb *db, struct SelvaTypeEntry *te, node_id_t start);
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Get a node by id.
|
|
292
|
+
*/
|
|
293
|
+
SELVA_EXPORT
|
|
294
|
+
struct SelvaNode *selva_find_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Find the first node greater than or equal to the provided id, or NULL.
|
|
298
|
+
*/
|
|
299
|
+
SELVA_EXPORT
|
|
300
|
+
struct SelvaNode *selva_nfind_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Get or create a node by id.
|
|
304
|
+
*/
|
|
305
|
+
SELVA_EXPORT
|
|
306
|
+
struct SelvaNode *selva_upsert_node(struct SelvaDb *db, struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* **Example**
|
|
310
|
+
* ```c
|
|
311
|
+
* for (struct SelvaNode *np = selva_min_node(type); np; np = selva_next_node(type, np))
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
SELVA_EXPORT
|
|
315
|
+
struct SelvaNode *selva_min_node(struct SelvaTypeEntry *type) __attribute__((nonnull));
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* **Example**
|
|
319
|
+
* ```c
|
|
320
|
+
* for (struct SelvaNode *np = selva_max_node(type); np; np = selva_prev_node(type, np))
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
SELVA_EXPORT
|
|
324
|
+
struct SelvaNode *selva_max_node(struct SelvaTypeEntry *type) __attribute__((nonnull));
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Get previous node with a lower node id.
|
|
328
|
+
*/
|
|
329
|
+
SELVA_EXPORT
|
|
330
|
+
struct SelvaNode *selva_prev_node(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Get next node with higher node id.
|
|
334
|
+
*/
|
|
335
|
+
SELVA_EXPORT
|
|
336
|
+
struct SelvaNode *selva_next_node(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Total count of nodes of type.
|
|
340
|
+
*/
|
|
341
|
+
SELVA_EXPORT
|
|
342
|
+
size_t selva_node_count(const struct SelvaTypeEntry *type) __attribute__((nonnull));
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get the node id of of node.
|
|
346
|
+
*/
|
|
347
|
+
SELVA_EXPORT
|
|
348
|
+
__attribute__((nonnull, pure))
|
|
349
|
+
inline node_id_t selva_get_node_id(const struct SelvaNode *node)
|
|
350
|
+
#ifndef __zig
|
|
351
|
+
{
|
|
352
|
+
return node->node_id;
|
|
353
|
+
}
|
|
354
|
+
#else
|
|
355
|
+
;
|
|
356
|
+
#endif
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Get the type of of node.
|
|
360
|
+
*/
|
|
361
|
+
SELVA_EXPORT
|
|
362
|
+
__attribute__((nonnull, pure))
|
|
363
|
+
inline node_type_t selva_get_node_type(const struct SelvaNode *node)
|
|
364
|
+
#ifndef __zig
|
|
365
|
+
{
|
|
366
|
+
return node->type;
|
|
367
|
+
}
|
|
368
|
+
#else
|
|
369
|
+
;
|
|
370
|
+
#endif
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* \addtogroup node_hash
|
|
374
|
+
* @{
|
|
375
|
+
*/
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Calculate the node hash.
|
|
379
|
+
* Update node hash by using a temp hash state allocated earlier.
|
|
380
|
+
* @param tmp_hash_state is only used for computation and it's reset before use.
|
|
381
|
+
*/
|
|
382
|
+
SELVA_EXPORT
|
|
383
|
+
selva_hash128_t selva_node_hash_update(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, struct XXH3_state_s *tmp_hash_state);
|
|
384
|
+
|
|
385
|
+
SELVA_EXPORT
|
|
386
|
+
selva_hash128_t selva_node_hash(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node);
|
|
387
|
+
|
|
388
|
+
SELVA_EXPORT
|
|
389
|
+
int selva_node_hash_range(struct SelvaDb *db, struct SelvaTypeEntry *type, node_id_t start, node_id_t end, selva_hash128_t *hash_out) __attribute__((nonnull, warn_unused_result));
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @}
|
|
393
|
+
*/
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Get the number of aliases under given type.
|
|
397
|
+
*/
|
|
398
|
+
SELVA_EXPORT
|
|
399
|
+
size_t selva_alias_count(const struct SelvaAliases *aliases);
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Set new alias.
|
|
403
|
+
* @param name is copied.
|
|
404
|
+
* @returns the previous node_id the alias was pointing to; Otherwise 0.
|
|
405
|
+
*/
|
|
406
|
+
SELVA_EXPORT
|
|
407
|
+
node_id_t selva_set_alias(struct SelvaAliases *aliases, node_id_t dest, const char *name_str, size_t name_len);
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Delete alias by name.
|
|
411
|
+
* @return the destination node_id the alias was pointing to; 0 if SELVA_ENOENT.
|
|
412
|
+
*/
|
|
413
|
+
SELVA_EXPORT
|
|
414
|
+
node_id_t selva_del_alias_by_name(struct SelvaAliases *aliases, const char *name_str, size_t name_len);
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Delete all aliases pointing to dest.
|
|
418
|
+
*/
|
|
419
|
+
SELVA_EXPORT
|
|
420
|
+
void selva_del_alias_by_dest(struct SelvaAliases *aliases, node_id_t dest);
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Get alias by name.
|
|
424
|
+
*/
|
|
425
|
+
SELVA_EXPORT
|
|
426
|
+
struct SelvaNode *selva_get_alias(struct SelvaTypeEntry *type, struct SelvaAliases *aliases, const char *name_str, size_t name_len);
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Get alias by destination id.
|
|
430
|
+
* This may not seem very useful but this is actually the way that allows you to
|
|
431
|
+
* traverse all aliases to the given node_id by following the `next` pointer or
|
|
432
|
+
* by calling selva_get_next_alias().
|
|
433
|
+
*/
|
|
434
|
+
SELVA_EXPORT
|
|
435
|
+
const struct SelvaAlias *selva_get_alias_by_dest(struct SelvaAliases *aliases, node_id_t dest);
|
|
436
|
+
|
|
437
|
+
SELVA_EXPORT
|
|
438
|
+
const struct SelvaAlias *selva_get_next_alias(const struct SelvaAlias *alias);
|
|
439
|
+
|
|
440
|
+
SELVA_EXPORT
|
|
441
|
+
const char *selva_get_alias_name(const struct SelvaAlias *alias, size_t *len) __attribute__((nonnull, pure));
|
|
442
|
+
|
|
443
|
+
SELVA_EXPORT
|
|
444
|
+
struct SelvaAliases *selva_get_aliases(struct SelvaTypeEntry *type, field_t field);
|
|
445
|
+
|
|
446
|
+
/***
|
|
447
|
+
* Remove all aliases to the given node_id.
|
|
448
|
+
*/
|
|
449
|
+
SELVA_EXPORT
|
|
450
|
+
void selva_remove_all_aliases(struct SelvaTypeEntry *type, node_id_t node_id);
|