@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.
Files changed (102) hide show
  1. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  2. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  3. package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
  4. package/dist/lib/darwin_aarch64/libnode-v25.node +0 -0
  5. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  6. package/dist/lib/linux_aarch64/include/cdefs.h +324 -0
  7. package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
  8. package/dist/lib/linux_aarch64/include/libdeflate.h +345 -0
  9. package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
  10. package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
  11. package/dist/lib/linux_aarch64/include/queue.h +627 -0
  12. package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
  13. package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
  14. package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
  15. package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
  16. package/dist/lib/linux_aarch64/include/selva/colvec.h +71 -0
  17. package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
  18. package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
  19. package/dist/lib/linux_aarch64/include/selva/db.h +450 -0
  20. package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
  21. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +27 -0
  22. package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +18 -0
  23. package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
  24. package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
  25. package/dist/lib/linux_aarch64/include/selva/fields.h +341 -0
  26. package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
  27. package/dist/lib/linux_aarch64/include/selva/hll.h +85 -0
  28. package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
  29. package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
  30. package/dist/lib/linux_aarch64/include/selva/membar.h +32 -0
  31. package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
  32. package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
  33. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +49 -0
  34. package/dist/lib/linux_aarch64/include/selva/selva_lang.h +112 -0
  35. package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
  36. package/dist/lib/linux_aarch64/include/selva/selva_string.h +683 -0
  37. package/dist/lib/linux_aarch64/include/selva/sort.h +140 -0
  38. package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
  39. package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
  40. package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
  41. package/dist/lib/linux_aarch64/include/selva/types.h +115 -0
  42. package/dist/lib/linux_aarch64/include/selva/vector.h +35 -0
  43. package/dist/lib/linux_aarch64/include/selva_error.h +140 -0
  44. package/dist/lib/linux_aarch64/include/selva_lang_code.h +160 -0
  45. package/dist/lib/linux_aarch64/include/tree.h +852 -0
  46. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  47. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  48. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  49. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  50. package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
  51. package/dist/lib/linux_aarch64/libnode-v25.node +0 -0
  52. package/dist/lib/linux_aarch64/libselva.so +0 -0
  53. package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
  54. package/dist/lib/linux_x86_64/include/cdefs.h +324 -0
  55. package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
  56. package/dist/lib/linux_x86_64/include/libdeflate.h +345 -0
  57. package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
  58. package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
  59. package/dist/lib/linux_x86_64/include/queue.h +627 -0
  60. package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
  61. package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
  62. package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
  63. package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
  64. package/dist/lib/linux_x86_64/include/selva/colvec.h +71 -0
  65. package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
  66. package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
  67. package/dist/lib/linux_x86_64/include/selva/db.h +450 -0
  68. package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
  69. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +27 -0
  70. package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +18 -0
  71. package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
  72. package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
  73. package/dist/lib/linux_x86_64/include/selva/fields.h +341 -0
  74. package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
  75. package/dist/lib/linux_x86_64/include/selva/hll.h +85 -0
  76. package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
  77. package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
  78. package/dist/lib/linux_x86_64/include/selva/membar.h +32 -0
  79. package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
  80. package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
  81. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +49 -0
  82. package/dist/lib/linux_x86_64/include/selva/selva_lang.h +112 -0
  83. package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
  84. package/dist/lib/linux_x86_64/include/selva/selva_string.h +683 -0
  85. package/dist/lib/linux_x86_64/include/selva/sort.h +140 -0
  86. package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
  87. package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
  88. package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
  89. package/dist/lib/linux_x86_64/include/selva/types.h +115 -0
  90. package/dist/lib/linux_x86_64/include/selva/vector.h +35 -0
  91. package/dist/lib/linux_x86_64/include/selva_error.h +140 -0
  92. package/dist/lib/linux_x86_64/include/selva_lang_code.h +160 -0
  93. package/dist/lib/linux_x86_64/include/tree.h +852 -0
  94. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  95. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  96. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  97. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  98. package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
  99. package/dist/lib/linux_x86_64/libnode-v25.node +0 -0
  100. package/dist/lib/linux_x86_64/libselva.so +0 -0
  101. package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
  102. package/package.json +1 -1
@@ -0,0 +1,301 @@
1
+ /*
2
+ * Copyright (c) 2022-2024 SAULX
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ #pragma once
6
+ #ifndef _SELVA_ENDIAN_H_
7
+ #define _SELVA_ENDIAN_H_
8
+
9
+ #include <stddef.h>
10
+ #include <stdint.h>
11
+
12
+ /*
13
+ * NOTICE
14
+ * This header conflicts with `endian.h` on Linux/glibc and gets included at
15
+ * least by `sys/types.h`. This is not a big problem because we implement the
16
+ * same functionality + some extras.
17
+ * The original header could be included with `#include_next`. Isn't it pretty
18
+ * stupid that we can override system headers included by system headers in
19
+ * this way?
20
+ */
21
+
22
+ _Static_assert(sizeof(double) == 8, "Only 64bit doubles are supported");
23
+
24
+ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
25
+
26
+ #ifndef htobe16
27
+ #define htobe16(x) __builtin_bswap16(x)
28
+ #define htole16(x) (x)
29
+ #define be16toh(x) __builtin_bswap16(x)
30
+ #define le16toh(x) (x)
31
+ #endif
32
+
33
+ #ifndef htobe32
34
+ #define htobe32(x) __builtin_bswap32(x)
35
+ #define htole32(x) (x)
36
+ #define be32toh(x) __builtin_bswap32(x)
37
+ #define le32toh(x) (x)
38
+ #endif
39
+
40
+ #ifndef htobe64
41
+ #define htobe64(x) __builtin_bswap64(x)
42
+ #define htole64(x) (x)
43
+ #define be64toh(x) __builtin_bswap64(x)
44
+ #define le64toh(x) (x)
45
+ #endif
46
+
47
+ static inline void htoledouble(char buf[8], double x) {
48
+ #if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__
49
+ /*
50
+ * x: 4 5 6 7 0 1 2 3
51
+ * 0 1 2 3 4 5 6 7
52
+ */
53
+ char s[8];
54
+
55
+ __builtin_memcpy(s, &x, 8);
56
+ buf[0] = s[4];
57
+ buf[1] = s[5];
58
+ buf[2] = s[6];
59
+ buf[3] = s[7];
60
+ buf[4] = s[0];
61
+ buf[5] = s[1];
62
+ buf[6] = s[2];
63
+ buf[7] = s[3];
64
+ #else
65
+ __builtin_memcpy(buf, &x, 8);
66
+ #endif
67
+ }
68
+
69
+ static inline double ledoubletoh(const char buf[8]) {
70
+ #if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__
71
+ char s[8];
72
+ double x;
73
+
74
+ s[0] = buf[4];
75
+ s[1] = buf[5];
76
+ s[2] = buf[6];
77
+ s[3] = buf[7];
78
+ s[4] = buf[0];
79
+ s[5] = buf[1];
80
+ s[6] = buf[2];
81
+ s[7] = buf[3];
82
+
83
+ __builtin_memcpy(&x, s, sizeof(double));
84
+ return x;
85
+ #else
86
+ double x;
87
+
88
+ __builtin_memcpy(&x, buf, sizeof(double));
89
+
90
+ return x;
91
+ #endif
92
+ }
93
+
94
+ #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
95
+
96
+ #ifndef htobe16
97
+ #define htobe16(x) (x)
98
+ #define htole16(x) __builtin_bswap16(x)
99
+ #define be16toh(x) (x)
100
+ #define le16toh(x) __builtin_bswap16(x)
101
+ #endif
102
+
103
+ #ifndef htobe32
104
+ #define htobe32(x) (x)
105
+ #define htole32(x) __builtin_bswap32(x)
106
+ #define be32toh(x) (x)
107
+ #define le32toh(x) __builtin_bswap32(x)
108
+ #endif
109
+
110
+ #ifndef htobe64
111
+ #define htobe64(x) (x)
112
+ #define htole64(x) __builtin_bswap64(x)
113
+ #define be64toh(x) (x)
114
+ #define le64toh(x) __builtin_bswap64(x)
115
+ #endif
116
+
117
+ static inline void htoledouble(char buf[8], double x) {
118
+ #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
119
+ /*
120
+ * x: 3 2 1 0 7 6 5 4
121
+ * s: 0 1 2 3 4 5 6 7
122
+ */
123
+ char s[8];
124
+
125
+ __builtin_memcpy(s, &x, 8);
126
+ buf[0] = s[3];
127
+ buf[1] = s[2];
128
+ buf[2] = s[1];
129
+ buf[3] = s[0];
130
+ buf[4] = s[7];
131
+ buf[5] = s[6];
132
+ buf[6] = s[5];
133
+ buf[7] = s[4];
134
+ #else
135
+ /*
136
+ * x: 7 6 5 4 3 2 1 0
137
+ * s: 0 1 2 3 4 5 6 7
138
+ */
139
+ char s[8];
140
+
141
+ __builtin_memcpy(s, &x, 8);
142
+ buf[0] = s[7];
143
+ buf[1] = s[6];
144
+ buf[2] = s[5];
145
+ buf[3] = s[4];
146
+ buf[4] = s[3];
147
+ buf[5] = s[2];
148
+ buf[6] = s[1];
149
+ buf[7] = s[0];
150
+ #endif
151
+ }
152
+
153
+ static inline double ledoubletoh(const char buf[8]) {
154
+ char s[8];
155
+ double x;
156
+
157
+ #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
158
+ s[0] = buf[3];
159
+ s[1] = buf[2];
160
+ s[2] = buf[1];
161
+ s[3] = buf[0];
162
+ s[4] = buf[7];
163
+ s[5] = buf[6];
164
+ s[6] = buf[5];
165
+ s[7] = buf[4];
166
+ #else
167
+ s[0] = buf[7];
168
+ s[1] = buf[6];
169
+ s[2] = buf[5];
170
+ s[3] = buf[4];
171
+ s[4] = buf[3];
172
+ s[5] = buf[2];
173
+ s[6] = buf[1];
174
+ s[7] = buf[0];
175
+ #endif
176
+
177
+ __builtin_memcpy(&x, s, sizeof(double));
178
+ return x;
179
+ }
180
+
181
+ #else
182
+ #error "Machine byte order not supported"
183
+ #endif
184
+
185
+ #if __linux__
186
+
187
+ /**
188
+ * Type generic Host to BE.
189
+ */
190
+ #define htobe(v) _Generic((v), \
191
+ uint16_t: htobe16(v), \
192
+ int16_t: (int16_t)htobe16(v), \
193
+ uint32_t: htobe32(v), \
194
+ int32_t: (int32_t)htobe32(v), \
195
+ uint64_t: htobe64(v), \
196
+ int64_t: (int64_t)htobe64(v), \
197
+ unsigned long long: (unsigned long long)htobe64(v), \
198
+ long long: (int64_t)htobe64(v))
199
+
200
+ /**
201
+ * Type generic Host to LE.
202
+ */
203
+ #define htole(v) _Generic((v), \
204
+ uint16_t: htole16(v), \
205
+ int16_t: (int16_t)htole16(v), \
206
+ uint32_t: htole32(v), \
207
+ int32_t: (int32_t)htole32(v), \
208
+ uint64_t: htole64(v), \
209
+ int64_t: (int64_t)htole64(v), \
210
+ unsigned long long: (unsigned long long)htole64(v), \
211
+ long long: (int64_t)htole64(v))
212
+
213
+ /**
214
+ * Type generic LE to Host.
215
+ */
216
+ #define letoh(v) _Generic((v), \
217
+ uint16_t: le16toh(v), \
218
+ int16_t: (int16_t)le16toh(v), \
219
+ uint32_t: le32toh(v), \
220
+ int32_t: (int32_t)le32toh(v), \
221
+ uint64_t: le64toh(v), \
222
+ int64_t: (int64_t)le64toh(v), \
223
+ unsigned long long: (unsigned long long)le64toh(v), \
224
+ long long: (int64_t)le64toh(v))
225
+
226
+ /**
227
+ * Type generic BE to Host.
228
+ */
229
+ #define betoh(v) _Generic((v), \
230
+ uint16_t: be16toh(v), \
231
+ int16_t: (int16_t)be16toh(v), \
232
+ uint32_t: be32toh(v), \
233
+ int32_t: (int32_t)be32toh(v), \
234
+ uint64_t: be64toh(v), \
235
+ int64_t: (int64_t)be64toh(v), \
236
+ unsigned long long: (unsigned long long)be64toh(v), \
237
+ long long: (int64_t)be64toh(v))
238
+
239
+ /* 128-bit machines not supported atm. */
240
+ static_assert(sizeof(long long) == sizeof(uint64_t));
241
+
242
+ #else
243
+
244
+ /**
245
+ * Type generic Host to BE.
246
+ */
247
+ #define htobe(v) _Generic((v), \
248
+ uint16_t: htobe16(v), \
249
+ int16_t: (int16_t)htobe16(v), \
250
+ uint32_t: htobe32(v), \
251
+ int32_t: (int32_t)htobe32(v), \
252
+ uint64_t: htobe64(v), \
253
+ size_t: htobe64(v), \
254
+ ssize_t: htobe64(v), \
255
+ int64_t: (int64_t)htobe64(v))
256
+
257
+ /**
258
+ * Type generic Host to LE.
259
+ */
260
+ #define htole(v) _Generic((v), \
261
+ uint16_t: htole16(v), \
262
+ int16_t: (int16_t)htole16(v), \
263
+ uint32_t: htole32(v), \
264
+ int32_t: (int32_t)htole32(v), \
265
+ uint64_t: htole64(v), \
266
+ size_t: htole64(v), \
267
+ ssize_t: htole64(v), \
268
+ int64_t: (int64_t)htole64(v))
269
+
270
+ /**
271
+ * Type generic LE to Host.
272
+ */
273
+ #define letoh(v) _Generic((v), \
274
+ uint16_t: le16toh(v), \
275
+ int16_t: (int16_t)le16toh(v), \
276
+ uint32_t: le32toh(v), \
277
+ int32_t: (int32_t)le32toh(v), \
278
+ uint64_t: le64toh(v), \
279
+ size_t: le64toh(v), \
280
+ ssize_t: le64toh(v), \
281
+ int64_t: (int64_t)le64toh(v))
282
+
283
+ /**
284
+ * Type generic BE to Host.
285
+ */
286
+ #define betoh(v) _Generic((v), \
287
+ uint16_t: be16toh(v), \
288
+ int16_t: (int16_t)be16toh(v), \
289
+ uint32_t: be32toh(v), \
290
+ int32_t: (int32_t)be32toh(v), \
291
+ uint64_t: be64toh(v), \
292
+ size_t: be64toh(v), \
293
+ ssize_t: be64toh(v), \
294
+ int64_t: (int64_t)be64toh(v))
295
+
296
+ #endif
297
+
298
+ /* If this fails then htole and letoh will need some adjustment. */
299
+ static_assert(sizeof(size_t) == sizeof(uint64_t));
300
+
301
+ #endif /* _SELVA_ENDIAN_H_ */
@@ -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,11 @@
1
+ /*
2
+ * Copyright (c) 2024-2025 SAULX
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ #pragma once
6
+
7
+ #include <stddef.h>
8
+ #include "selva/_export.h"
9
+
10
+ SELVA_EXPORT
11
+ void *fast_memmem(const void *h0, size_t k, const void *n0, size_t l);
@@ -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
+ }