@based/db 0.2.5 → 0.2.6
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/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 +341 -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 +115 -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 +341 -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 +115 -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/package.json +1 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024-2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <stdint.h>
|
|
8
|
+
#include <sys/types.h>
|
|
9
|
+
#include "selva/_export.h"
|
|
10
|
+
#ifdef __zig
|
|
11
|
+
struct selva_string;
|
|
12
|
+
#else
|
|
13
|
+
#include "selva/selva_string.h"
|
|
14
|
+
#endif
|
|
15
|
+
#include "selva/types.h"
|
|
16
|
+
#include "selva_lang_code.h"
|
|
17
|
+
|
|
18
|
+
struct XXH3_state_s; /* RFE Not good? */
|
|
19
|
+
|
|
20
|
+
#ifndef __zig
|
|
21
|
+
struct SelvaTextField {
|
|
22
|
+
struct selva_string *tl __pcounted_by(len);
|
|
23
|
+
uint8_t len;
|
|
24
|
+
} __packed;
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
struct SelvaNodeSmallReference {
|
|
28
|
+
node_id_t dst;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
struct SelvaNodeLargeReference {
|
|
32
|
+
node_id_t dst;
|
|
33
|
+
node_id_t meta;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
enum SelvaNodeReferenceType {
|
|
37
|
+
SELVA_NODE_REFERENCE_NULL = 0,
|
|
38
|
+
SELVA_NODE_REFERENCE_SMALL = 1,
|
|
39
|
+
SELVA_NODE_REFERENCE_LARGE = 2,
|
|
40
|
+
} __packed;
|
|
41
|
+
|
|
42
|
+
struct SelvaNodeReferenceAny {
|
|
43
|
+
enum SelvaNodeReferenceType type;
|
|
44
|
+
union {
|
|
45
|
+
void *any;
|
|
46
|
+
struct SelvaNodeSmallReference *small;
|
|
47
|
+
struct SelvaNodeLargeReference *large;
|
|
48
|
+
}
|
|
49
|
+
#ifdef __zig
|
|
50
|
+
p
|
|
51
|
+
#endif
|
|
52
|
+
;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
static_assert(offsetof(struct SelvaNodeLargeReference, dst) == offsetof(struct SelvaNodeSmallReference, dst));
|
|
56
|
+
|
|
57
|
+
struct SelvaNodeReferences {
|
|
58
|
+
uint32_t nr_refs;
|
|
59
|
+
uint16_t offset;
|
|
60
|
+
enum SelvaNodeReferenceType size;
|
|
61
|
+
|
|
62
|
+
union {
|
|
63
|
+
void *any;
|
|
64
|
+
struct SelvaNodeLargeReference *large __pcounted_by(nr_refs);
|
|
65
|
+
struct SelvaNodeSmallReference *small __pcounted_by(nr_refs);
|
|
66
|
+
};
|
|
67
|
+
node_id_t *index __pcounted_by(nr_refs); /*!< Sorted index of all nodes in `.refs`. */
|
|
68
|
+
};
|
|
69
|
+
static_assert(offsetof(struct SelvaNodeReferences, any) == offsetof(struct SelvaNodeReferences, small));
|
|
70
|
+
static_assert(offsetof(struct SelvaNodeReferences, any) == offsetof(struct SelvaNodeReferences, large));
|
|
71
|
+
static_assert(offsetof(struct SelvaNodeReferences, small) == offsetof(struct SelvaNodeReferences, large));
|
|
72
|
+
|
|
73
|
+
struct SelvaFieldsPointer {
|
|
74
|
+
uint8_t *ptr;
|
|
75
|
+
size_t off;
|
|
76
|
+
size_t len;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Precalculated empty strings for text translations.
|
|
81
|
+
* The size of the string is 8 for better alignment but they are only
|
|
82
|
+
* filled upto 6 bytes.
|
|
83
|
+
*/
|
|
84
|
+
SELVA_EXPORT
|
|
85
|
+
extern const uint8_t selva_fields_text_tl_empty[_selva_lang_last][8];
|
|
86
|
+
|
|
87
|
+
#define SELVA_FIELDS_TEXT_TL_EMPTY_LEN 6
|
|
88
|
+
|
|
89
|
+
#if __has_c_attribute(unsequenced)
|
|
90
|
+
[[unsequenced]]
|
|
91
|
+
#else
|
|
92
|
+
__purefn
|
|
93
|
+
#endif
|
|
94
|
+
size_t selva_fields_get_data_size(const struct SelvaFieldSchema *fs);
|
|
95
|
+
|
|
96
|
+
#if __has_c_attribute(reproducible)
|
|
97
|
+
[[reproducible]]
|
|
98
|
+
#endif
|
|
99
|
+
void *selva_fields_nfo2p(struct SelvaFields *fields, const struct SelvaFieldInfo *nfo);
|
|
100
|
+
|
|
101
|
+
struct SelvaNodeLargeReference *selva_fields_ensure_reference(
|
|
102
|
+
struct SelvaNode *node,
|
|
103
|
+
const struct SelvaFieldSchema *fs);
|
|
104
|
+
|
|
105
|
+
SELVA_EXPORT
|
|
106
|
+
struct SelvaNode *selva_fields_ensure_ref_meta(
|
|
107
|
+
struct SelvaDb *db,
|
|
108
|
+
struct SelvaNode *node,
|
|
109
|
+
const struct EdgeFieldConstraint *efc,
|
|
110
|
+
struct SelvaNodeLargeReference *ref,
|
|
111
|
+
node_id_t meta_id,
|
|
112
|
+
selva_dirty_node_cb_t dirty_cb, void *dirty_ctx);
|
|
113
|
+
|
|
114
|
+
SELVA_EXPORT
|
|
115
|
+
void selva_faux_dirty_cb(void *, node_type_t, node_id_t);
|
|
116
|
+
|
|
117
|
+
SELVA_EXPORT
|
|
118
|
+
int selva_fields_get_mutable_string(
|
|
119
|
+
struct SelvaNode *node,
|
|
120
|
+
const struct SelvaFieldSchema *fs,
|
|
121
|
+
size_t len,
|
|
122
|
+
struct selva_string **s)
|
|
123
|
+
__attribute__((access(write_only, 4)));
|
|
124
|
+
|
|
125
|
+
SELVA_EXPORT
|
|
126
|
+
void *selva_fields_ensure_micro_buffer(struct SelvaNode *node, const struct SelvaFieldSchema *fs);
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* TODO Document diff to get_mutable_string
|
|
130
|
+
*/
|
|
131
|
+
SELVA_EXPORT
|
|
132
|
+
struct selva_string *selva_fields_ensure_string(
|
|
133
|
+
struct SelvaNode *node,
|
|
134
|
+
const struct SelvaFieldSchema *fs,
|
|
135
|
+
size_t initial_len);
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Set reference to fields.
|
|
139
|
+
*/
|
|
140
|
+
SELVA_EXPORT
|
|
141
|
+
int selva_fields_reference_set(
|
|
142
|
+
struct SelvaDb *db,
|
|
143
|
+
struct SelvaNode * restrict src,
|
|
144
|
+
const struct SelvaFieldSchema *fs_src,
|
|
145
|
+
struct SelvaNode * restrict dst,
|
|
146
|
+
struct SelvaNodeReferenceAny *ref_out,
|
|
147
|
+
selva_dirty_node_cb_t dirty_cb,
|
|
148
|
+
void *dirty_ctx);
|
|
149
|
+
|
|
150
|
+
enum selva_fields_references_insert_flags {
|
|
151
|
+
/**
|
|
152
|
+
* Reorder existing reference to the new index.
|
|
153
|
+
* The reference is either inserted or moved to the given index.
|
|
154
|
+
*/
|
|
155
|
+
SELVA_FIELDS_REFERENCES_INSERT_FLAGS_REORDER = 0x01,
|
|
156
|
+
SELVA_FIELDS_REFERENCES_INSERT_FLAGS_IGNORE_SRC_DEPENDENT = 0x02,
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @param index 0 = first; -1 = last.
|
|
161
|
+
* @param reorder move the existing ref to `index` instead of returning EEXIST.
|
|
162
|
+
*/
|
|
163
|
+
SELVA_EXPORT
|
|
164
|
+
int selva_fields_references_insert(
|
|
165
|
+
struct SelvaDb *db,
|
|
166
|
+
struct SelvaNode * restrict node,
|
|
167
|
+
const struct SelvaFieldSchema *fs,
|
|
168
|
+
ssize_t index,
|
|
169
|
+
enum selva_fields_references_insert_flags flags,
|
|
170
|
+
struct SelvaTypeEntry *te_dst,
|
|
171
|
+
struct SelvaNode * restrict dst,
|
|
172
|
+
struct SelvaNodeReferenceAny *ref_out,
|
|
173
|
+
selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
174
|
+
__attribute__((access(write_only, 8)));
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Prealloc a references field buffer.
|
|
178
|
+
* @returns nr_refs.
|
|
179
|
+
*/
|
|
180
|
+
SELVA_EXPORT
|
|
181
|
+
size_t selva_fields_prealloc_refs(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, size_t nr_refs_min);
|
|
182
|
+
|
|
183
|
+
SELVA_EXPORT
|
|
184
|
+
int selva_fields_references_insert_tail(
|
|
185
|
+
struct SelvaDb *db,
|
|
186
|
+
struct SelvaNode * restrict node,
|
|
187
|
+
const struct SelvaFieldSchema *fs,
|
|
188
|
+
struct SelvaTypeEntry *te_dst,
|
|
189
|
+
const node_id_t ids[],
|
|
190
|
+
size_t nr_ids,
|
|
191
|
+
selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
192
|
+
__attribute__((access(read_only, 5, 6)));
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Move reference from old to new index in a references field array.
|
|
196
|
+
* If index_new > index_old then the ref will be after the reference that was in index_new before the operation;
|
|
197
|
+
* If index_new < index_ld then the ref will be before the reference that was in the index_new before the operation.
|
|
198
|
+
* index_new and index_old can be negative, which will start counting the references array from the last position.
|
|
199
|
+
* It's not possible to create a gap of null references using this function.
|
|
200
|
+
*/
|
|
201
|
+
SELVA_EXPORT
|
|
202
|
+
int selva_fields_references_move(
|
|
203
|
+
struct SelvaNode *node,
|
|
204
|
+
const struct SelvaFieldSchema *fs,
|
|
205
|
+
ssize_t index_old,
|
|
206
|
+
ssize_t index_new);
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Swap two references in a references field array.
|
|
210
|
+
*/
|
|
211
|
+
SELVA_EXPORT
|
|
212
|
+
int selva_fields_references_swap(
|
|
213
|
+
struct SelvaNode *node,
|
|
214
|
+
const struct SelvaFieldSchema *fs,
|
|
215
|
+
size_t index_a,
|
|
216
|
+
size_t index_b);
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Set string field.
|
|
220
|
+
*
|
|
221
|
+
* str format:
|
|
222
|
+
* 0 1 2 len
|
|
223
|
+
* +------+------+--------+-----+
|
|
224
|
+
* | LANG | COMP | DATA | CRC |
|
|
225
|
+
* +------+------+--------+-----+
|
|
226
|
+
*/
|
|
227
|
+
SELVA_EXPORT
|
|
228
|
+
int selva_fields_set_string(
|
|
229
|
+
struct SelvaNode *node,
|
|
230
|
+
const struct SelvaFieldSchema *fs,
|
|
231
|
+
const char *str,
|
|
232
|
+
size_t len);
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Set text field translation.
|
|
236
|
+
*
|
|
237
|
+
* str format:
|
|
238
|
+
* 0 1 2 len
|
|
239
|
+
* +------+------+--------+-----+
|
|
240
|
+
* | LANG | COMP | DATA | CRC |
|
|
241
|
+
* +------+------+--------+-----+
|
|
242
|
+
*/
|
|
243
|
+
SELVA_EXPORT
|
|
244
|
+
int selva_fields_set_text(
|
|
245
|
+
struct SelvaNode *node,
|
|
246
|
+
const struct SelvaFieldSchema *fs,
|
|
247
|
+
const char *str,
|
|
248
|
+
size_t len);
|
|
249
|
+
|
|
250
|
+
int selva_fields_get_mutable_text(
|
|
251
|
+
struct SelvaNode *node,
|
|
252
|
+
const struct SelvaFieldSchema *fs,
|
|
253
|
+
enum selva_lang_code lang,
|
|
254
|
+
size_t len,
|
|
255
|
+
struct selva_string **out);
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Get text field translation.
|
|
259
|
+
*
|
|
260
|
+
* str format:
|
|
261
|
+
* 0 1 2 len
|
|
262
|
+
* +------+------+--------+-----+
|
|
263
|
+
* | LANG | COMP | DATA | CRC |
|
|
264
|
+
* +------+------+--------+-----+
|
|
265
|
+
*/
|
|
266
|
+
SELVA_EXPORT
|
|
267
|
+
int selva_fields_get_text(
|
|
268
|
+
struct SelvaNode * restrict node,
|
|
269
|
+
const struct SelvaFieldSchema *fs,
|
|
270
|
+
enum selva_lang_code lang,
|
|
271
|
+
const char **str,
|
|
272
|
+
size_t *len);
|
|
273
|
+
|
|
274
|
+
SELVA_EXPORT
|
|
275
|
+
int selva_fields_set_micro_buffer(struct SelvaNode *node, const struct SelvaFieldSchema *fs, const void *value, size_t len);
|
|
276
|
+
|
|
277
|
+
SELVA_EXPORT
|
|
278
|
+
struct SelvaNodeLargeReference *selva_fields_get_reference(struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
279
|
+
__attribute__((nonnull));
|
|
280
|
+
|
|
281
|
+
SELVA_EXPORT
|
|
282
|
+
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
283
|
+
__attribute__((nonnull));
|
|
284
|
+
|
|
285
|
+
SELVA_EXPORT
|
|
286
|
+
struct selva_string *selva_fields_get_selva_string(struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
287
|
+
__attribute__((nonnull));
|
|
288
|
+
|
|
289
|
+
SELVA_EXPORT
|
|
290
|
+
struct SelvaFieldsPointer selva_fields_get_raw(struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
291
|
+
__attribute__((nonnull));
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Delete field.
|
|
295
|
+
* @param dirty_cb will be called with the deleted node_id in case of a reference(s) field.
|
|
296
|
+
*/
|
|
297
|
+
SELVA_EXPORT
|
|
298
|
+
int selva_fields_del(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
299
|
+
__attribute__((nonnull(1, 2, 3)));
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Delete an edge from a references field.
|
|
303
|
+
*/
|
|
304
|
+
SELVA_EXPORT
|
|
305
|
+
int selva_fields_del_ref(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, node_id_t dst_node_id, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx);
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Clear a references field but don't free it.
|
|
309
|
+
*/
|
|
310
|
+
SELVA_EXPORT
|
|
311
|
+
void selva_fields_clear_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
312
|
+
__attribute__((nonnull(1, 2, 3)));
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Init the fields struct of a node or edge.
|
|
316
|
+
*/
|
|
317
|
+
void selva_fields_init_node(struct SelvaDb *db, struct SelvaTypeEntry *te, struct SelvaNode *node)
|
|
318
|
+
__attribute__((nonnull));
|
|
319
|
+
|
|
320
|
+
void selva_fields_flush(struct SelvaDb *db, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx);
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Destroy all fields of a node.
|
|
324
|
+
*/
|
|
325
|
+
SELVA_EXPORT
|
|
326
|
+
void selva_fields_destroy(struct SelvaDb *db, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
327
|
+
__attribute__((nonnull(1, 2)));
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Unload node fields.
|
|
331
|
+
* Same as selva_fields_destroy() but only clears references from one side.
|
|
332
|
+
*/
|
|
333
|
+
SELVA_EXPORT
|
|
334
|
+
void selva_fields_unload(struct SelvaDb *db, struct SelvaNode *node)
|
|
335
|
+
__attribute__((nonnull));
|
|
336
|
+
|
|
337
|
+
SELVA_EXPORT
|
|
338
|
+
void selva_fields_hash_update(struct XXH3_state_s *hash_state, struct SelvaDb *db, const struct SelvaFieldsSchema *schema, const struct SelvaNode *node);
|
|
339
|
+
|
|
340
|
+
SELVA_EXPORT
|
|
341
|
+
selva_hash128_t selva_fields_hash(struct SelvaDb *db, const struct SelvaFieldsSchema *schema, const struct SelvaNode *node);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*******************************************************************************
|
|
3
|
+
* @file gmtime.h
|
|
4
|
+
* @author Olli Vanhoja
|
|
5
|
+
* @brief Calendar calculations.
|
|
6
|
+
* @section LICENSE
|
|
7
|
+
* Copyright (c) 2025 Saulx
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
*******************************************************************************
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#pragma once
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
#include "selva/_export.h"
|
|
15
|
+
|
|
16
|
+
#define SELVA_TM_SUNDAY 0
|
|
17
|
+
#define SELVA_TM_MONDAY 1
|
|
18
|
+
#define SELVA_TM_TUESDAY 2
|
|
19
|
+
#define SELVA_TM_WEDNESDAY 3
|
|
20
|
+
#define SELVA_TM_THURSDAY 4
|
|
21
|
+
#define SELVA_TM_FRIDAY 5
|
|
22
|
+
#define SELVA_TM_SATURDAY 6
|
|
23
|
+
|
|
24
|
+
#define SELVA_TM_JANUARY 0
|
|
25
|
+
#define SELVA_TM_FEBRUARY 1
|
|
26
|
+
#define SELVA_TM_MARCH 2
|
|
27
|
+
#define SELVA_TM_APRIL 3
|
|
28
|
+
#define SELVA_TM_MAY 4
|
|
29
|
+
#define SELVA_TM_JUNE 5
|
|
30
|
+
#define SELVA_TM_JULY 6
|
|
31
|
+
#define SELVA_TM_AUGUST 7
|
|
32
|
+
#define SELVA_TM_SEPTEMBER 8
|
|
33
|
+
#define SELVA_TM_OCTOBER 9
|
|
34
|
+
#define SELVA_TM_NOVEMBER 10
|
|
35
|
+
#define SELVA_TM_DECEMBER 11
|
|
36
|
+
|
|
37
|
+
#define SELVA_EPOCH_YEAR 1970
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gregorian Calendar.
|
|
41
|
+
*/
|
|
42
|
+
struct selva_tm {
|
|
43
|
+
int32_t tm_sec; /*!< Seconds [0,60]. */
|
|
44
|
+
int32_t tm_min; /*!< Minutes [0,59]. */
|
|
45
|
+
int32_t tm_hour; /*!< Hour [0,23]. */
|
|
46
|
+
int32_t tm_mday; /*!< Day of month [1,31]. */
|
|
47
|
+
int32_t tm_mon; /*!< Month of year [0,11]. */
|
|
48
|
+
int32_t tm_year; /*!< Year. */
|
|
49
|
+
int32_t tm_wday; /*!< Day of week [0,6] (Sunday =0). */
|
|
50
|
+
int32_t tm_yday; /*!< Day of year [0,365]. */
|
|
51
|
+
bool tm_yleap; /*!< Is leap year. */
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* ISO-8601 Week Date.
|
|
56
|
+
*/
|
|
57
|
+
struct selva_iso_week {
|
|
58
|
+
int32_t iso_year; /*!< ISO year. */
|
|
59
|
+
int32_t iso_week; /*!< ISO week [1,54]. */
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
static inline int32_t selva_gmtime_wday2iso_wday(int32_t wday)
|
|
63
|
+
{
|
|
64
|
+
/* Same as (tm.tm_wday + 6) % 7 + 1 but fewer instructions. */
|
|
65
|
+
return wday ? wday : 7;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Calculate struct selva_tm from ts and tmz in Gregorian calendar.
|
|
70
|
+
* @param ts in ms.
|
|
71
|
+
* @param tmz in minutes.
|
|
72
|
+
*/
|
|
73
|
+
SELVA_EXPORT
|
|
74
|
+
void selva_gmtime(struct selva_tm *result, int64_t ts, int64_t tmz);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Calculate Gregorian year from ts and tmz.
|
|
78
|
+
* @param ts in ms.
|
|
79
|
+
* @param tmz in minutes.
|
|
80
|
+
* @returns Gregorian year.
|
|
81
|
+
*/
|
|
82
|
+
SELVA_EXPORT
|
|
83
|
+
int32_t selva_gmtime_year(int64_t ts, int64_t tmz);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Calculate Gregorian month from ts and tmz.
|
|
87
|
+
* @param ts in ms.
|
|
88
|
+
* @param tmz in minutes.
|
|
89
|
+
* @returns Gregorian month of year [0,11].
|
|
90
|
+
*/
|
|
91
|
+
SELVA_EXPORT
|
|
92
|
+
int32_t selva_gmtime_mon(int64_t ts, int64_t tmz);
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Calculate Gregorian day of year from ts and tmz.
|
|
96
|
+
* @param ts in ms.
|
|
97
|
+
* @param tmz in minutes.
|
|
98
|
+
* @returns Gregorian day of year [0,365].
|
|
99
|
+
*/
|
|
100
|
+
SELVA_EXPORT
|
|
101
|
+
int32_t selva_gmtime_yday(int64_t ts, int64_t tmz);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Calculate Gregorian day of week from ts and tmz.
|
|
105
|
+
* @param ts in ms.
|
|
106
|
+
* @param tmz in minutes.
|
|
107
|
+
* @returns Gregorian day of week [0,6] (Sunday =0).
|
|
108
|
+
*/
|
|
109
|
+
SELVA_EXPORT
|
|
110
|
+
int32_t selva_gmtime_wday(int64_t ts, int64_t tmz);
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Calculate Gregorian day of month from ts and tmz.
|
|
114
|
+
* @param ts in ms.
|
|
115
|
+
* @param tmz in minutes.
|
|
116
|
+
* @returns Gregorian day of month [1,31].
|
|
117
|
+
*/
|
|
118
|
+
SELVA_EXPORT
|
|
119
|
+
int32_t selva_gmtime_mday(int64_t ts, int64_t tmz);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Calculate hour from ts and tmz.
|
|
123
|
+
* @param ts in ms.
|
|
124
|
+
* @param tmz in minutes.
|
|
125
|
+
* @returns Hour [0, 23].
|
|
126
|
+
*/
|
|
127
|
+
SELVA_EXPORT
|
|
128
|
+
int32_t selva_gmtime_hour(int64_t ts, int64_t tmz);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Calculate the ISO-8601 week date from ts and tmz.
|
|
132
|
+
* @param ts in ms.
|
|
133
|
+
* @param tmz in minutes.
|
|
134
|
+
* @returns wyear.
|
|
135
|
+
*/
|
|
136
|
+
SELVA_EXPORT
|
|
137
|
+
struct selva_iso_week *selva_gmtime_iso_wyear(struct selva_iso_week *wyear, int64_t ts, int64_t tmz);
|