@based/db 0.1.3 → 0.1.5
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/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +320 -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 +430 -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 +379 -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 +105 -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 +119 -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/libselva.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +320 -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 +430 -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 +379 -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 +105 -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 +119 -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/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/dist/src/server/migrate/worker.js +87 -84
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
#include <sys/types.h>
|
|
8
|
+
#include "selva/types.h"
|
|
9
|
+
|
|
10
|
+
struct SelvaNode;
|
|
11
|
+
struct SelvaNodeSmallReference;
|
|
12
|
+
struct SelvaNodeLargeReference;
|
|
13
|
+
|
|
14
|
+
SELVA_EXPORT
|
|
15
|
+
ssize_t fast_linear_search_uint32(const uint32_t arr[], size_t len, uint32_t x);
|
|
16
|
+
|
|
17
|
+
SELVA_EXPORT
|
|
18
|
+
ssize_t fast_linear_search_node_id(const node_id_t arr[], size_t len, node_id_t x);
|
|
19
|
+
|
|
20
|
+
SELVA_EXPORT
|
|
21
|
+
ssize_t fast_linear_search_node(const struct SelvaNode *arr[], size_t len, const struct SelvaNode *x);
|
|
22
|
+
|
|
23
|
+
SELVA_EXPORT
|
|
24
|
+
ssize_t fast_linear_search_references_small(const struct SelvaNodeSmallReference *arr, size_t len, node_id_t x);
|
|
25
|
+
|
|
26
|
+
SELVA_EXPORT
|
|
27
|
+
ssize_t fast_linear_search_references_large(const struct SelvaNodeLargeReference *arr, size_t len, node_id_t x);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include "selva/_export.h"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fast buffer equals comparison.
|
|
12
|
+
* @param a is an array of length len.
|
|
13
|
+
* @param b is an array of length len.
|
|
14
|
+
* @param len length of a and b in bytes, must be greater than 0.
|
|
15
|
+
* @returns true if a and b contains the same byte sequence; Otherwise false.
|
|
16
|
+
*/
|
|
17
|
+
SELVA_EXPORT
|
|
18
|
+
bool fast_memcmp(const void *restrict a, const void *restrict b, size_t len);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2023, 2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Like atoi but faster and more unsafe.
|
|
9
|
+
* This is way faster than strtoll() in glibc.
|
|
10
|
+
*/
|
|
11
|
+
static inline int fast_atou(const char *str)
|
|
12
|
+
{
|
|
13
|
+
int n = 0;
|
|
14
|
+
|
|
15
|
+
while (*str >= '0' && *str <= '9') {
|
|
16
|
+
n = n * 10 + (int)(*str++) - '0';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return n;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Like strtol but faster and more unsafe.
|
|
24
|
+
* This is way faster than strtoll() in glibc.
|
|
25
|
+
*/
|
|
26
|
+
static inline int fast_strtou(const char *str, const char **end)
|
|
27
|
+
{
|
|
28
|
+
int n = 0;
|
|
29
|
+
|
|
30
|
+
while (*str >= '0' && *str <= '9') {
|
|
31
|
+
n = n * 10 + (int)(*str++) - '0';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
*end = str;
|
|
35
|
+
return n;
|
|
36
|
+
}
|
|
@@ -0,0 +1,379 @@
|
|
|
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 SelvaNodeWeakReference {
|
|
74
|
+
/* The type can be found from the schema. */
|
|
75
|
+
#if 0
|
|
76
|
+
node_type_t dst_type;
|
|
77
|
+
#endif
|
|
78
|
+
node_id_t dst_id;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
struct SelvaNodeWeakReferences {
|
|
82
|
+
uint32_t nr_refs;
|
|
83
|
+
uint32_t offset;
|
|
84
|
+
struct SelvaNodeWeakReference *refs __pcounted_by(nr_refs);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
struct SelvaFieldsPointer {
|
|
88
|
+
uint8_t *ptr;
|
|
89
|
+
size_t off;
|
|
90
|
+
size_t len;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Precalculated empty strings for text translations.
|
|
95
|
+
* The size of the string is 8 for better alignment but they are only
|
|
96
|
+
* filled upto 6 bytes.
|
|
97
|
+
*/
|
|
98
|
+
SELVA_EXPORT
|
|
99
|
+
extern const uint8_t selva_fields_text_tl_empty[_selva_lang_last][8];
|
|
100
|
+
|
|
101
|
+
#define SELVA_FIELDS_TEXT_TL_EMPTY_LEN 6
|
|
102
|
+
|
|
103
|
+
#if __has_c_attribute(unsequenced)
|
|
104
|
+
[[unsequenced]]
|
|
105
|
+
#else
|
|
106
|
+
__purefn
|
|
107
|
+
#endif
|
|
108
|
+
size_t selva_fields_get_data_size(const struct SelvaFieldSchema *fs);
|
|
109
|
+
|
|
110
|
+
SELVA_EXPORT
|
|
111
|
+
#if __has_c_attribute(reproducible)
|
|
112
|
+
[[reproducible]]
|
|
113
|
+
#endif
|
|
114
|
+
void *selva_fields_nfo2p(struct SelvaFields *fields, const struct SelvaFieldInfo *nfo);
|
|
115
|
+
|
|
116
|
+
SELVA_EXPORT
|
|
117
|
+
struct SelvaFields *selva_fields_node2fields(struct SelvaNode *node);
|
|
118
|
+
|
|
119
|
+
SELVA_EXPORT
|
|
120
|
+
struct SelvaNode *selva_fields_ensure_ref_meta(
|
|
121
|
+
struct SelvaDb *db,
|
|
122
|
+
struct SelvaNode *node,
|
|
123
|
+
const struct EdgeFieldConstraint *efc,
|
|
124
|
+
struct SelvaNodeLargeReference *ref,
|
|
125
|
+
node_id_t meta_id,
|
|
126
|
+
selva_dirty_node_cb_t dirty_cb, void *dirty_ctx);
|
|
127
|
+
|
|
128
|
+
SELVA_EXPORT
|
|
129
|
+
int selva_fields_get_mutable_string(
|
|
130
|
+
struct SelvaNode *node,
|
|
131
|
+
const struct SelvaFieldSchema *fs,
|
|
132
|
+
size_t len,
|
|
133
|
+
struct selva_string **s)
|
|
134
|
+
__attribute__((access(write_only, 4)));
|
|
135
|
+
|
|
136
|
+
SELVA_EXPORT
|
|
137
|
+
struct SelvaFieldInfo *selva_fields_ensure(struct SelvaFields *fields, const struct SelvaFieldSchema *fs);
|
|
138
|
+
|
|
139
|
+
/*
|
|
140
|
+
* TODO Document diff to get_mutable_string
|
|
141
|
+
*/
|
|
142
|
+
SELVA_EXPORT
|
|
143
|
+
struct selva_string *selva_fields_ensure_string(
|
|
144
|
+
struct SelvaNode *node,
|
|
145
|
+
const struct SelvaFieldSchema *fs,
|
|
146
|
+
size_t initial_len);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Set reference to fields.
|
|
150
|
+
*/
|
|
151
|
+
SELVA_EXPORT
|
|
152
|
+
int selva_fields_reference_set(
|
|
153
|
+
struct SelvaDb *db,
|
|
154
|
+
struct SelvaNode * restrict src,
|
|
155
|
+
const struct SelvaFieldSchema *fs_src,
|
|
156
|
+
struct SelvaNode * restrict dst,
|
|
157
|
+
struct SelvaNodeReferenceAny *ref_out,
|
|
158
|
+
selva_dirty_node_cb_t dirty_cb,
|
|
159
|
+
void *dirty_ctx);
|
|
160
|
+
// __attribute__((access(write_only, 5), access(write_only, 6)));
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param index 0 = first; -1 = last.
|
|
164
|
+
* @param reorder move the existing ref to `index` instead of returning EEXIST.
|
|
165
|
+
*/
|
|
166
|
+
SELVA_EXPORT
|
|
167
|
+
int selva_fields_references_insert(
|
|
168
|
+
struct SelvaDb *db,
|
|
169
|
+
struct SelvaNode * restrict node,
|
|
170
|
+
const struct SelvaFieldSchema *fs,
|
|
171
|
+
ssize_t index,
|
|
172
|
+
bool reorder,
|
|
173
|
+
struct SelvaTypeEntry *te_dst,
|
|
174
|
+
struct SelvaNode * restrict dst,
|
|
175
|
+
struct SelvaNodeReferenceAny *ref_out,
|
|
176
|
+
selva_dirty_node_cb_t dirty_cb, void *dirty_ctx, bool ignore_src_dependent)
|
|
177
|
+
__attribute__((access(write_only, 8)));
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Prealloc a references field buffer.
|
|
181
|
+
* @returns nr_refs.
|
|
182
|
+
*/
|
|
183
|
+
SELVA_EXPORT
|
|
184
|
+
size_t selva_fields_prealloc_refs(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, size_t nr_refs_min);
|
|
185
|
+
|
|
186
|
+
SELVA_EXPORT
|
|
187
|
+
int selva_fields_references_insert_tail_wupsert(
|
|
188
|
+
struct SelvaDb *db,
|
|
189
|
+
struct SelvaNode * restrict node,
|
|
190
|
+
const struct SelvaFieldSchema *fs,
|
|
191
|
+
struct SelvaTypeEntry *te_dst,
|
|
192
|
+
const node_id_t ids[],
|
|
193
|
+
size_t nr_ids,
|
|
194
|
+
selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
195
|
+
__attribute__((access(read_only, 5, 6)));
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Move reference from old to new index in a references field array.
|
|
199
|
+
* If index_new > index_old then the ref will be after the reference that was in index_new before the operation;
|
|
200
|
+
* If index_new < index_ld then the ref will be before the reference that was in the index_new before the operation.
|
|
201
|
+
* index_new and index_old can be negative, which will start counting the references array from the last position.
|
|
202
|
+
* It's not possible to create a gap of null references using this function.
|
|
203
|
+
*/
|
|
204
|
+
SELVA_EXPORT
|
|
205
|
+
int selva_fields_references_move(
|
|
206
|
+
struct SelvaNode *node,
|
|
207
|
+
const struct SelvaFieldSchema *fs,
|
|
208
|
+
ssize_t index_old,
|
|
209
|
+
ssize_t index_new);
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Swap two references in a references field array.
|
|
213
|
+
*/
|
|
214
|
+
SELVA_EXPORT
|
|
215
|
+
int selva_fields_references_swap(
|
|
216
|
+
struct SelvaNode *node,
|
|
217
|
+
const struct SelvaFieldSchema *fs,
|
|
218
|
+
size_t index_a,
|
|
219
|
+
size_t index_b);
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Set string field.
|
|
223
|
+
*
|
|
224
|
+
* str format:
|
|
225
|
+
* 0 1 2 len
|
|
226
|
+
* +------+------+--------+-----+
|
|
227
|
+
* | LANG | COMP | DATA | CRC |
|
|
228
|
+
* +------+------+--------+-----+
|
|
229
|
+
*/
|
|
230
|
+
SELVA_EXPORT
|
|
231
|
+
int selva_fields_set_string(
|
|
232
|
+
struct SelvaNode *node,
|
|
233
|
+
const struct SelvaFieldSchema *fs,
|
|
234
|
+
const char *str,
|
|
235
|
+
size_t len);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Set text field translation.
|
|
239
|
+
*
|
|
240
|
+
* str format:
|
|
241
|
+
* 0 1 2 len
|
|
242
|
+
* +------+------+--------+-----+
|
|
243
|
+
* | LANG | COMP | DATA | CRC |
|
|
244
|
+
* +------+------+--------+-----+
|
|
245
|
+
*/
|
|
246
|
+
SELVA_EXPORT
|
|
247
|
+
int selva_fields_set_text(
|
|
248
|
+
struct SelvaNode *node,
|
|
249
|
+
const struct SelvaFieldSchema *fs,
|
|
250
|
+
const char *str,
|
|
251
|
+
size_t len);
|
|
252
|
+
|
|
253
|
+
int selva_fields_get_mutable_text(
|
|
254
|
+
struct SelvaNode *node,
|
|
255
|
+
const struct SelvaFieldSchema *fs,
|
|
256
|
+
enum selva_lang_code lang,
|
|
257
|
+
size_t len,
|
|
258
|
+
struct selva_string **out);
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Get text field translation.
|
|
262
|
+
*
|
|
263
|
+
* str format:
|
|
264
|
+
* 0 1 2 len
|
|
265
|
+
* +------+------+--------+-----+
|
|
266
|
+
* | LANG | COMP | DATA | CRC |
|
|
267
|
+
* +------+------+--------+-----+
|
|
268
|
+
*/
|
|
269
|
+
SELVA_EXPORT
|
|
270
|
+
int selva_fields_get_text(
|
|
271
|
+
struct SelvaNode * restrict node,
|
|
272
|
+
const struct SelvaFieldSchema *fs,
|
|
273
|
+
enum selva_lang_code lang,
|
|
274
|
+
const char **str,
|
|
275
|
+
size_t *len);
|
|
276
|
+
|
|
277
|
+
SELVA_EXPORT
|
|
278
|
+
int selva_fields_set_micro_buffer(struct SelvaFields *fields, const struct SelvaFieldSchema *fs, const void *value, size_t len);
|
|
279
|
+
|
|
280
|
+
SELVA_EXPORT
|
|
281
|
+
int selva_fields_set_micro_buffer2(struct SelvaNode *node, const struct SelvaFieldSchema *fs, const void *value, size_t len);
|
|
282
|
+
|
|
283
|
+
SELVA_EXPORT
|
|
284
|
+
int selva_fields_set_weak_reference(struct SelvaNode *node, const struct SelvaFieldSchema *fs, node_id_t dst);
|
|
285
|
+
|
|
286
|
+
SELVA_EXPORT
|
|
287
|
+
int selva_fields_set_weak_reference2(struct SelvaFields *fields, const struct SelvaFieldSchema *fs, node_id_t dst);
|
|
288
|
+
|
|
289
|
+
SELVA_EXPORT
|
|
290
|
+
int selva_fields_set_weak_references2(struct SelvaFields *fields, const struct SelvaFieldSchema *fs, node_id_t dst[], size_t nr_dsts);
|
|
291
|
+
|
|
292
|
+
SELVA_EXPORT
|
|
293
|
+
int selva_fields_set_weak_references(struct SelvaNode *node, const struct SelvaFieldSchema *fs, node_id_t dst[], size_t nr_dsts);
|
|
294
|
+
|
|
295
|
+
SELVA_EXPORT
|
|
296
|
+
struct SelvaNodeLargeReference *selva_fields_get_reference(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
297
|
+
__attribute__((nonnull));
|
|
298
|
+
|
|
299
|
+
SELVA_EXPORT
|
|
300
|
+
struct SelvaNodeReferences *selva_fields_get_references(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
301
|
+
__attribute__((nonnull));
|
|
302
|
+
|
|
303
|
+
SELVA_EXPORT
|
|
304
|
+
struct SelvaNodeWeakReference selva_fields_get_weak_reference(struct SelvaFields *fields, field_t field)
|
|
305
|
+
__attribute__((nonnull));
|
|
306
|
+
|
|
307
|
+
SELVA_EXPORT
|
|
308
|
+
struct SelvaNodeWeakReferences selva_fields_get_weak_references(struct SelvaFields *fields, field_t field)
|
|
309
|
+
__attribute__((nonnull));
|
|
310
|
+
|
|
311
|
+
SELVA_EXPORT
|
|
312
|
+
struct SelvaNode *selva_fields_resolve_weak_reference(
|
|
313
|
+
const struct SelvaDb *db,
|
|
314
|
+
const struct SelvaFieldSchema *fs,
|
|
315
|
+
const struct SelvaNodeWeakReference *weak_ref)
|
|
316
|
+
__attribute__((nonnull));
|
|
317
|
+
|
|
318
|
+
SELVA_EXPORT
|
|
319
|
+
struct selva_string *selva_fields_get_selva_string2(struct SelvaFields *fields, const struct SelvaFieldSchema *fs)
|
|
320
|
+
__attribute__((nonnull));
|
|
321
|
+
|
|
322
|
+
SELVA_EXPORT
|
|
323
|
+
struct selva_string *selva_fields_get_selva_string(struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
324
|
+
__attribute__((nonnull));
|
|
325
|
+
|
|
326
|
+
SELVA_EXPORT
|
|
327
|
+
struct SelvaFieldInfo *selva_field_get_nfo(struct SelvaFields *fields, const struct SelvaFieldSchema *fs);
|
|
328
|
+
|
|
329
|
+
SELVA_EXPORT
|
|
330
|
+
struct SelvaFieldsPointer selva_fields_get_raw2(struct SelvaFields *fields, const struct SelvaFieldSchema *fs)
|
|
331
|
+
__attribute__((nonnull));
|
|
332
|
+
|
|
333
|
+
SELVA_EXPORT
|
|
334
|
+
struct SelvaFieldsPointer selva_fields_get_raw(struct SelvaNode *node, const struct SelvaFieldSchema *fs)
|
|
335
|
+
__attribute__((nonnull));
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Delete field.
|
|
339
|
+
* @param dirty_cb will be called with the deleted node_id in case of a reference(s) field.
|
|
340
|
+
*/
|
|
341
|
+
SELVA_EXPORT
|
|
342
|
+
int selva_fields_del(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFieldSchema *fs, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
343
|
+
__attribute__((nonnull(1, 2, 3)));
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Delete an edge from a references field.
|
|
347
|
+
*/
|
|
348
|
+
SELVA_EXPORT
|
|
349
|
+
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);
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Clear a references field but don't free it.
|
|
353
|
+
*/
|
|
354
|
+
SELVA_EXPORT
|
|
355
|
+
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)
|
|
356
|
+
__attribute__((nonnull(1, 2, 3)));
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Init the fields struct of a node or edge.
|
|
360
|
+
*/
|
|
361
|
+
SELVA_EXPORT
|
|
362
|
+
void selva_fields_init(const struct SelvaFieldsSchema *schema, struct SelvaFields *fields)
|
|
363
|
+
__attribute__((nonnull));
|
|
364
|
+
|
|
365
|
+
void selva_fields_init_node(struct SelvaTypeEntry *te, struct SelvaNode *node)
|
|
366
|
+
__attribute__((nonnull));
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Destroy all fields of a node.
|
|
370
|
+
*/
|
|
371
|
+
SELVA_EXPORT
|
|
372
|
+
void selva_fields_destroy(struct SelvaDb *db, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx)
|
|
373
|
+
__attribute__((nonnull(1, 2)));
|
|
374
|
+
|
|
375
|
+
SELVA_EXPORT
|
|
376
|
+
void selva_fields_hash_update(struct XXH3_state_s *hash_state, struct SelvaDb *db, const struct SelvaFieldsSchema *schema, const struct SelvaFields *fields);
|
|
377
|
+
|
|
378
|
+
SELVA_EXPORT
|
|
379
|
+
selva_hash128_t selva_fields_hash(struct SelvaDb *db, const struct SelvaFieldsSchema *schema, const struct SelvaFields *fields);
|
|
@@ -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);
|