@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,683 @@
1
+ /*
2
+ * Copyright (c) 2022-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
+
11
+ struct finalizer;
12
+ struct selva_string;
13
+ struct libdeflate_compressor;
14
+ struct libdeflate_decompressor;
15
+
16
+ /**
17
+ * Selva string flags.
18
+ */
19
+ enum selva_string_flags {
20
+ /**
21
+ * CRC enabled.
22
+ * For compressed string this is for the uncompressed string.
23
+ */
24
+ SELVA_STRING_CRC = 0x01,
25
+ /**
26
+ * Permanently shared string; Shouldn't be freed.
27
+ */
28
+ SELVA_STRING_FREEZE = 0x02,
29
+ /**
30
+ * A mutable string.
31
+ */
32
+ SELVA_STRING_MUTABLE = 0x04,
33
+ /**
34
+ * Fixed size mutable string.
35
+ * Mutable only with selva_string_replace() and selva_string_to_mstr().
36
+ */
37
+ SELVA_STRING_MUTABLE_FIXED = 0x08,
38
+ /**
39
+ * Static string.
40
+ * The selva_string structure is not allocated by selva_string.
41
+ */
42
+ SELVA_STRING_STATIC = 0x10,
43
+ /**
44
+ * Compressed string.
45
+ */
46
+ SELVA_STRING_COMPRESS = 0x20,
47
+ SELVA_STRING_LEN_PARITY = 0x80,
48
+ } __packed;
49
+
50
+ #define INVALID_FLAGS_MASK (~(SELVA_STRING_CRC | SELVA_STRING_FREEZE | SELVA_STRING_MUTABLE | SELVA_STRING_MUTABLE_FIXED | SELVA_STRING_STATIC | SELVA_STRING_COMPRESS | SELVA_STRING_LEN_PARITY))
51
+
52
+ /**
53
+ * Header before compressed string.
54
+ * This is stored just before the actual string.
55
+ * Currently the compression used is raw DEFLATE.
56
+ */
57
+ struct selva_string_compressed_hdr {
58
+ /* TODO uint8_t type header here. */
59
+ /**
60
+ * Uncompressed size of the string.
61
+ */
62
+ uint32_t uncompressed_size;
63
+ } __packed;
64
+
65
+ #define SELVA_STRING_STRUCT_SIZE 16
66
+ #ifndef __zig
67
+ struct selva_string {
68
+ struct {
69
+ uint64_t len: 56;
70
+ enum selva_string_flags flags: 8;
71
+ };
72
+ /* Don't add __counted_by(len) here because it's not the real size. */
73
+ union {
74
+ char *p;
75
+ char emb[sizeof(char *)];
76
+ };
77
+ };
78
+ static_assert(sizeof(struct selva_string) == SELVA_STRING_STRUCT_SIZE);
79
+
80
+ /* RFE is + 1 extra? */
81
+ #define SELVA_STRING_STATIC_BUF_SIZE(len) \
82
+ (((len + 1) < sizeof(char *)) ? 0 : len + 1 - sizeof(char *))
83
+
84
+ /* RFE is + 1 extra? */
85
+ #define SELVA_STRING_STATIC_BUF_SIZE_WCRC(len) \
86
+ (((len + 1 + sizeof(uint32_t)) < sizeof(char *)) ? 0 : len + 1 - sizeof(char *) + sizeof(uint32_t))
87
+
88
+ #define SELVA_STRING_STATIC_S(name, len) \
89
+ struct { \
90
+ struct selva_string name; \
91
+ char name ## buf[SELVA_STRING_STATIC_BUF_SIZE(len)]; \
92
+ }
93
+
94
+ #define SELVA_STRING_STATIC_S_WCRC(name, len) \
95
+ struct { \
96
+ struct selva_string name; \
97
+ char name ## buf[SELVA_STRING_STATIC_BUF_SIZE_WCRC(len)]; \
98
+ }
99
+ #endif
100
+
101
+ void selva_string_init_tls(void);
102
+ void selva_string_deinit_tls(void);
103
+
104
+ /**
105
+ * Initialize a statically allocated selva_string.
106
+ * Note that the string buffer doesn't need to be statically allocated, just the struct.
107
+ * The `SELVA_STRING_STATIC` macro should be used to also allocate the buffer statically
108
+ * with a fixed size.
109
+ * If `SELVA_STRING_MUTABLE_FIXED` is given then the buffer following the string must be large
110
+ * enough.
111
+ * @param str can be NULL if a mutable flag is set.
112
+ */
113
+ SELVA_EXPORT
114
+ int selva_string_init(struct selva_string *s, const char *str, size_t len, enum selva_string_flags flags);
115
+
116
+
117
+ /**
118
+ * Same as selva_string_init() but with a precalculated CRC32-C.
119
+ */
120
+ SELVA_EXPORT
121
+ int selva_string_init_crc(struct selva_string *s, const char *str, size_t len, uint32_t crc, enum selva_string_flags flags);
122
+
123
+ /**
124
+ * Create a new string.
125
+ * @param str can be NULL.
126
+ */
127
+ [[nodiscard]]
128
+ SELVA_EXPORT
129
+ struct selva_string *selva_string_create(const char *str, size_t len, enum selva_string_flags flags)
130
+ __attribute__((access(read_only, 1)));
131
+
132
+ /**
133
+ * Create a new string with a user provided CRC.
134
+ * @param str can be NULL.
135
+ */
136
+ SELVA_EXPORT
137
+ struct selva_string *selva_string_create_crc(const char *str, size_t len, enum selva_string_flags flags, uint32_t crc)
138
+ __attribute__((access(read_only, 1, 2)));
139
+
140
+ /**
141
+ * Create a string using a printf format string.
142
+ */
143
+ [[nodiscard]]
144
+ SELVA_EXPORT
145
+ struct selva_string *selva_string_createf(const char *fmt, ...)
146
+ __attribute__((format(printf, 1, 2)));
147
+
148
+ #if defined(_STDIO_H) || defined(_STDIO_H_)
149
+ /**
150
+ * Read a string from a file directly into a new selva_string.
151
+ * If the resulting string is shorter than `size` an errno is set. Use the
152
+ * ferror() and feof() functions to distinguish between a read error and an
153
+ * end-of-file.
154
+ * @param flags can be SELVA_STRING_CRC | SELVA_STRING_COMPRESS.
155
+ */
156
+ [[nodiscard]]
157
+ SELVA_EXPORT
158
+ struct selva_string *selva_string_fread(FILE *fp, size_t size, enum selva_string_flags flags);
159
+ #endif
160
+
161
+ /**
162
+ * Create a compressed string.
163
+ * Note that most of the selva_string functions don't know how to handle with
164
+ * compressed strings and will just assume it's a regular string.
165
+ * @param flags Compressed strings can't handle most of the flags but notably
166
+ * SELVA_STRING_CRC is supported.
167
+ */
168
+ [[nodiscard]]
169
+ SELVA_EXPORT
170
+ struct selva_string *selva_string_createz(struct libdeflate_compressor *compressor, const char *in_str, size_t in_len, enum selva_string_flags flags)
171
+ __attribute__((access(read_only, 2, 3)));
172
+
173
+ /**
174
+ * Decompress a compressed string.
175
+ * @param s is a pointer to a compressed selva_string.
176
+ * @param buf is the destination where the decompressed string will be copied to.
177
+ * The size of the buffer must be at least selva_string_getz_ulen(s) bytes.
178
+ * @returns 0 if succeeded;
179
+ * SELVA_PROTO_EINTYPE if not a compressed string;
180
+ * SELVA_EINVAL if the string cannot be decompressed.
181
+ */
182
+ SELVA_EXPORT
183
+ int selva_string_decompress(struct libdeflate_decompressor *decompressor, const struct selva_string * restrict s, char * restrict buf)
184
+ __attribute__((access(read_only, 2), access(write_only, 3)));
185
+
186
+ /**
187
+ * Duplicate a string.
188
+ * @param s is a pointer to a selva_string.
189
+ */
190
+ [[nodiscard]]
191
+ SELVA_EXPORT
192
+ struct selva_string *selva_string_dup(const struct selva_string *s, enum selva_string_flags flags)
193
+ __attribute__((access(read_only, 1)));
194
+
195
+ /**
196
+ * Truncate the string s to a new length of newlen.
197
+ * @param s is a pointer to a selva_string. Must be mutable.
198
+ * @param newlen is the new length of the string.
199
+ * @returns 0 if succeeded; Otherwise an error code.
200
+ */
201
+ SELVA_EXPORT
202
+ int selva_string_truncate(struct selva_string *s, size_t newlen)
203
+ __attribute__((access(read_write, 1)));
204
+
205
+ /**
206
+ * Append str of length len to the string s.
207
+ * @param s is a pointer to a selva_string. Must be mutable.
208
+ * @returns 0 if succeeded; Otherwise an error code.
209
+ */
210
+ SELVA_EXPORT
211
+ int selva_string_append(struct selva_string *s, const char *str, size_t len)
212
+ __attribute__((access(read_only, 2)));
213
+
214
+ /**
215
+ * Replace current value of the string s with str.
216
+ * @param s must be mutable.
217
+ * @returns 0 if succeeded; Otherwise an error code.
218
+ */
219
+ SELVA_EXPORT
220
+ int selva_string_replace(struct selva_string *s, const char *str, size_t len)
221
+ __attribute__((access(read_only, 2, 3)));
222
+
223
+ /**
224
+ * Replace current value of the string s with str and an externally computed crc.
225
+ * @param s must be mutable.
226
+ * @returns 0 if succeeded; Otherwise an error code.
227
+ */
228
+ SELVA_EXPORT
229
+ int selva_string_replace_crc(struct selva_string *s, const char *str, size_t len, uint32_t crc)
230
+ __attribute__((access(read_only, 2, 3)));
231
+
232
+ /**
233
+ * Allows selva_string_free() to be passed to finalizer_add() and other similar
234
+ * functions accepting void functions.
235
+ */
236
+ typedef union {
237
+ struct selva_string *__s;
238
+ void *__p;
239
+ } _selva_string_ptr_t __transparent_union;
240
+
241
+
242
+ /**
243
+ * Free the strings s.
244
+ * @param s is a pointer to a selva_string.
245
+ */
246
+ SELVA_EXPORT
247
+ #ifdef __zig
248
+ void selva_string_free(struct selva_string *s);
249
+ #else
250
+ void selva_string_free(_selva_string_ptr_t s);
251
+ #endif
252
+
253
+ /**
254
+ * Add a selva_string to the given finalizer.
255
+ * @param finalizer is a pointer to a finalizer.
256
+ * @param s is a pointer to a selva_string.
257
+ */
258
+ SELVA_EXPORT
259
+ void selva_string_auto_finalize(struct finalizer *finalizer, struct selva_string *s);
260
+
261
+ /**
262
+ * Get the currently set flags of the string s.
263
+ * @param s is a pointer to a selva_string.
264
+ */
265
+ SELVA_EXPORT
266
+ enum selva_string_flags selva_string_get_flags(const struct selva_string *s)
267
+ __attribute__((access(read_only, 1)));
268
+
269
+ /**
270
+ * Get string length.
271
+ * If the string is compressed then the length returned is the compressed
272
+ * length including any metadata related to the compression algorithm.
273
+ */
274
+ SELVA_EXPORT
275
+ size_t selva_string_get_len(const struct selva_string *s)
276
+ __attribute__((access(read_only, 1)));
277
+
278
+ /**
279
+ * Get uncompressed length.
280
+ * The function will return the right size regardless whether the string is
281
+ * actually compressed.
282
+ */
283
+ SELVA_EXPORT
284
+ size_t selva_string_getz_ulen(const struct selva_string *s)
285
+ __attribute__((access(read_only, 1)));
286
+
287
+ /**
288
+ * Get compression ratio.
289
+ */
290
+ SELVA_EXPORT
291
+ double selva_string_getz_cratio(const struct selva_string *s)
292
+ __attribute__((access(read_only, 1)));
293
+
294
+ /**
295
+ * Get the raw buffer including CRC.
296
+ */
297
+ SELVA_EXPORT
298
+ const uint8_t *selva_string_to_buf(const struct selva_string *s, size_t *size)
299
+ __attribute__((access(write_only, 2)));
300
+
301
+ /**
302
+ * Get a pointer to the contained C-string.
303
+ * If the string is compressed then the compressed string is returned.
304
+ * selva_string_decompress() can be used to retrieve the original string.
305
+ * @param s is a pointer to a selva_string.
306
+ * @param[out] len is a pointer to a variable to store the length of s.
307
+ * @retruns Returns a pointer to the C-string.
308
+ */
309
+ SELVA_EXPORT
310
+ const char *selva_string_to_str(const struct selva_string *s, size_t *len)
311
+ __attribute__((access(write_only, 2)));
312
+
313
+ /**
314
+ * Get a pointer to the mutable C-string.
315
+ * @param s is a pointer to a selva_string.
316
+ * @param[out] len is a pointer to a variable to store the length of s.
317
+ * @returns Returns a pointer to the C-string if the string is mutable; Otherwise a NULL pointer is returned.
318
+ */
319
+ SELVA_EXPORT
320
+ char *selva_string_to_mstr(struct selva_string *s, size_t *len)
321
+ __attribute__((access(write_only, 2)));
322
+
323
+ /**
324
+ * Convert a string into a long long integer.
325
+ */
326
+ SELVA_EXPORT
327
+ int selva_string_to_ll(const struct selva_string *s, long long *ll)
328
+ __attribute__((access(write_only, 2)));
329
+
330
+ /**
331
+ * Convert a string into an unsigned long long integer.
332
+ */
333
+ SELVA_EXPORT
334
+ int selva_string_to_ull(const struct selva_string *s, unsigned long long *ull)
335
+ __attribute__((access(write_only, 2)));
336
+
337
+ /**
338
+ * Convert a string into a float.
339
+ */
340
+ SELVA_EXPORT
341
+ int selva_string_to_float(const struct selva_string *s, float *f)
342
+ __attribute__((access(write_only, 2)));
343
+
344
+ /**
345
+ * Convert a string into a double.
346
+ */
347
+ SELVA_EXPORT
348
+ int selva_string_to_double(const struct selva_string *s, double *d)
349
+ __attribute__((access(write_only, 2)));
350
+
351
+ /**
352
+ * Convert a string into a long double.
353
+ */
354
+ SELVA_EXPORT
355
+ int selva_string_to_ldouble(const struct selva_string *s, long double *ld)
356
+ __attribute__((access(write_only, 2)));
357
+
358
+ /**
359
+ * Freeze the string s in memory.
360
+ * Freezing a string allows sharing it in memory between multiple users and
361
+ * disallows freeing it until the program exits.
362
+ * This function can be called even if the string is immutable.
363
+ * @param s is a pointer to a selva_string.
364
+ */
365
+ SELVA_EXPORT
366
+ void selva_string_freeze(struct selva_string *s)
367
+ __attribute((access(read_write, 1)));
368
+
369
+ /**
370
+ * Verify the CRC of the string s.
371
+ * If the string is compressed the CRC is computed from the compressed data.
372
+ * @param s is a pointer to a selva_string.
373
+ */
374
+ SELVA_EXPORT
375
+ int selva_string_verify_crc(const struct selva_string *s)
376
+ __attribute((access(read_only, 1)));
377
+
378
+ /**
379
+ * Get the CRC of the string s.
380
+ */
381
+ SELVA_EXPORT
382
+ uint32_t selva_string_get_crc(const struct selva_string *s)
383
+ __attribute((access(read_only, 1)));
384
+
385
+ SELVA_EXPORT
386
+ void selva_string_set_crc(struct selva_string *s, uint32_t csum);
387
+
388
+ /**
389
+ * Set SELVA_STRING_COMPRESS flag on an existing string.
390
+ * Setting the flag won't compress the string but mark it as compressed;
391
+ * i.e. it's only a metadata update.
392
+ * This function should be used if you know that you have a selva_string
393
+ * that has been marked as uncompressed but it actually contains data that
394
+ * the selva_string compression utility will recognize properly. Usually
395
+ * meaning that the data was originally compressed using selva_string.
396
+ */
397
+ SELVA_EXPORT
398
+ void selva_string_set_compress(struct selva_string *s)
399
+ __attribute__((access(read_write, 1)));
400
+
401
+ /**
402
+ * Compare two strings.
403
+ * This function works correctly with compressed strings.
404
+ * @param decompress can be nullptr if strings are not compressed.
405
+ * @param a is a pointer to the first string to be compared.
406
+ * @param b is a pointer to the second strings to be compared.
407
+ * @returns < 0 if the first character that does not match has a lower value in ptr1 than in ptr2;
408
+ * 0 if the contents of both strings are equal;
409
+ * > 0 if the first character that does not match has a greater value in ptr1 than in ptr2.
410
+ */
411
+ SELVA_EXPORT
412
+ int selva_string_cmp(struct libdeflate_decompressor *decompressor, const struct selva_string *a, const struct selva_string *b)
413
+ __attribute__((access(read_only, 1), access(read_only, 2)));
414
+
415
+ /**
416
+ * Test if a string ends with suffix.
417
+ * This function works correctly with compressed strings.
418
+ */
419
+ SELVA_EXPORT
420
+ int selva_string_endswith(const struct selva_string *s, const char *suffix)
421
+ __attribute__((access(read_only, 1), access(read_only, 2)));
422
+
423
+ #define TO_STR_1(_var) \
424
+ size_t _var##_len; \
425
+ const char * _var##_str = selva_string_to_str(_var, & _var##_len);
426
+
427
+ #define TO_STR_2(_var, ...) \
428
+ TO_STR_1(_var) \
429
+ TO_STR_1(__VA_ARGS__)
430
+
431
+ #define TO_STR_3(_var, ...) \
432
+ TO_STR_1(_var) \
433
+ TO_STR_2(__VA_ARGS__)
434
+
435
+ #define TO_STR_4(_var, ...) \
436
+ TO_STR_1(_var) \
437
+ TO_STR_3(__VA_ARGS__)
438
+
439
+ #define TO_STR_5(_var, ...) \
440
+ TO_STR_1(_var) \
441
+ TO_STR_4(__VA_ARGS__)
442
+
443
+ #define TO_STR_6(_var, ...) \
444
+ TO_STR_1(_var) \
445
+ TO_STR_5(__VA_ARGS__)
446
+
447
+ #define TO_STR_7(_var, ...) \
448
+ TO_STR_1(_var) \
449
+ TO_STR_6(__VA_ARGS__)
450
+
451
+ #define TO_STR_8(_var, ...) \
452
+ TO_STR_1(_var) \
453
+ TO_STR_7(__VA_ARGS__)
454
+
455
+ #define TO_STR_9(_var, ...) \
456
+ TO_STR_1(_var) \
457
+ TO_STR_7(__VA_ARGS__)
458
+
459
+ #define TO_STR_10(_var, ...) \
460
+ TO_STR_1(_var) \
461
+ TO_STR_9(__VA_ARGS__)
462
+
463
+ #define TO_STR_11(_var, ...) \
464
+ TO_STR_1(_var) \
465
+ TO_STR_10(__VA_ARGS__)
466
+
467
+ #define TO_STR_12(_var, ...) \
468
+ TO_STR_1(_var) \
469
+ TO_STR_11(__VA_ARGS__)
470
+
471
+ #define TO_STR_13(_var, ...) \
472
+ TO_STR_1(_var) \
473
+ TO_STR_12(__VA_ARGS__)
474
+
475
+ #define TO_STR_14(_var, ...) \
476
+ TO_STR_1(_var) \
477
+ TO_STR_13(__VA_ARGS__)
478
+
479
+ #define TO_STR_15(_var, ...) \
480
+ TO_STR_1(_var) \
481
+ TO_STR_14(__VA_ARGS__)
482
+
483
+ #define TO_STR_16(_var, ...) \
484
+ TO_STR_1(_var) \
485
+ TO_STR_15(__VA_ARGS__)
486
+
487
+ #define TO_STR_17(_var, ...) \
488
+ TO_STR_1(_var) \
489
+ TO_STR_16(__VA_ARGS__)
490
+
491
+ #define TO_STR_18(_var, ...) \
492
+ TO_STR_1(_var) \
493
+ TO_STR_17(__VA_ARGS__)
494
+
495
+ #define TO_STR_19(_var, ...) \
496
+ TO_STR_1(_var) \
497
+ TO_STR_18(__VA_ARGS__)
498
+
499
+ #define TO_STR_20(_var, ...) \
500
+ TO_STR_1(_var) \
501
+ TO_STR_19(__VA_ARGS__)
502
+
503
+ #define TO_STR_21(_var, ...) \
504
+ TO_STR_1(_var) \
505
+ TO_STR_20(__VA_ARGS__)
506
+
507
+ #define TO_STR_22(_var, ...) \
508
+ TO_STR_1(_var) \
509
+ TO_STR_21(__VA_ARGS__)
510
+
511
+ #define TO_STR_23(_var, ...) \
512
+ TO_STR_1(_var) \
513
+ TO_STR_22(__VA_ARGS__)
514
+
515
+ #define TO_STR_24(_var, ...) \
516
+ TO_STR_1(_var) \
517
+ TO_STR_23(__VA_ARGS__)
518
+
519
+ #define TO_STR_25(_var, ...) \
520
+ TO_STR_1(_var) \
521
+ TO_STR_24(__VA_ARGS__)
522
+
523
+ #define TO_STR_26(_var, ...) \
524
+ TO_STR_1(_var) \
525
+ TO_STR_25(__VA_ARGS__)
526
+
527
+ #define TO_STR_27(_var, ...) \
528
+ TO_STR_1(_var) \
529
+ TO_STR_26(__VA_ARGS__)
530
+
531
+ #define TO_STR_28(_var, ...) \
532
+ TO_STR_1(_var) \
533
+ TO_STR_27(__VA_ARGS__)
534
+
535
+ #define TO_STR_29(_var, ...) \
536
+ TO_STR_1(_var) \
537
+ TO_STR_28(__VA_ARGS__)
538
+
539
+ #define TO_STR_30(_var, ...) \
540
+ TO_STR_1(_var) \
541
+ TO_STR_29(__VA_ARGS__)
542
+
543
+ #define TO_STR_31(_var, ...) \
544
+ TO_STR_1(_var) \
545
+ TO_STR_30(__VA_ARGS__)
546
+
547
+ #define TO_STR_32(_var, ...) \
548
+ TO_STR_1(_var) \
549
+ TO_STR_31(__VA_ARGS__)
550
+
551
+ #define TO_STR_33(_var, ...) \
552
+ TO_STR_1(_var) \
553
+ TO_STR_32(__VA_ARGS__)
554
+
555
+ #define TO_STR_34(_var, ...) \
556
+ TO_STR_1(_var) \
557
+ TO_STR_33(__VA_ARGS__)
558
+
559
+ #define TO_STR_35(_var, ...) \
560
+ TO_STR_1(_var) \
561
+ TO_STR_34(__VA_ARGS__)
562
+
563
+ #define TO_STR_36(_var, ...) \
564
+ TO_STR_1(_var) \
565
+ TO_STR_35(__VA_ARGS__)
566
+
567
+ #define TO_STR_37(_var, ...) \
568
+ TO_STR_1(_var) \
569
+ TO_STR_36(__VA_ARGS__)
570
+
571
+ #define TO_STR_38(_var, ...) \
572
+ TO_STR_1(_var) \
573
+ TO_STR_37(__VA_ARGS__)
574
+
575
+ #define TO_STR_39(_var, ...) \
576
+ TO_STR_1(_var) \
577
+ TO_STR_38(__VA_ARGS__)
578
+
579
+ #define TO_STR_40(_var, ...) \
580
+ TO_STR_1(_var) \
581
+ TO_STR_39(__VA_ARGS__)
582
+
583
+ #define TO_STR_41(_var, ...) \
584
+ TO_STR_1(_var) \
585
+ TO_STR_40(__VA_ARGS__)
586
+
587
+ #define TO_STR_42(_var, ...) \
588
+ TO_STR_1(_var) \
589
+ TO_STR_41(__VA_ARGS__)
590
+
591
+ #define TO_STR_43(_var, ...) \
592
+ TO_STR_1(_var) \
593
+ TO_STR_42(__VA_ARGS__)
594
+
595
+ #define TO_STR_44(_var, ...) \
596
+ TO_STR_1(_var) \
597
+ TO_STR_43(__VA_ARGS__)
598
+
599
+ #define TO_STR_45(_var, ...) \
600
+ TO_STR_1(_var) \
601
+ TO_STR_44(__VA_ARGS__)
602
+
603
+ #define TO_STR_46(_var, ...) \
604
+ TO_STR_1(_var) \
605
+ TO_STR_45(__VA_ARGS__)
606
+
607
+ #define TO_STR_47(_var, ...) \
608
+ TO_STR_1(_var) \
609
+ TO_STR_46(__VA_ARGS__)
610
+
611
+ #define TO_STR_48(_var, ...) \
612
+ TO_STR_1(_var) \
613
+ TO_STR_47(__VA_ARGS__)
614
+
615
+ #define TO_STR_49(_var, ...) \
616
+ TO_STR_1(_var) \
617
+ TO_STR_48(__VA_ARGS__)
618
+
619
+ #define TO_STR_50(_var, ...) \
620
+ TO_STR_1(_var) \
621
+ TO_STR_49(__VA_ARGS__)
622
+
623
+ #define TO_STR_51(_var, ...) \
624
+ TO_STR_1(_var) \
625
+ TO_STR_50(__VA_ARGS__)
626
+
627
+ #define TO_STR_52(_var, ...) \
628
+ TO_STR_1(_var) \
629
+ TO_STR_51(__VA_ARGS__)
630
+
631
+ #define TO_STR_53(_var, ...) \
632
+ TO_STR_1(_var) \
633
+ TO_STR_52(__VA_ARGS__)
634
+
635
+ #define TO_STR_54(_var, ...) \
636
+ TO_STR_1(_var) \
637
+ TO_STR_53(__VA_ARGS__)
638
+
639
+ #define TO_STR_55(_var, ...) \
640
+ TO_STR_1(_var) \
641
+ TO_STR_54(__VA_ARGS__)
642
+
643
+ #define TO_STR_56(_var, ...) \
644
+ TO_STR_1(_var) \
645
+ TO_STR_55(__VA_ARGS__)
646
+
647
+ #define TO_STR_57(_var, ...) \
648
+ TO_STR_1(_var) \
649
+ TO_STR_56(__VA_ARGS__)
650
+
651
+ #define TO_STR_58(_var, ...) \
652
+ TO_STR_1(_var) \
653
+ TO_STR_57(__VA_ARGS__)
654
+
655
+ #define TO_STR_59(_var, ...) \
656
+ TO_STR_1(_var) \
657
+ TO_STR_58(__VA_ARGS__)
658
+
659
+ #define TO_STR_60(_var, ...) \
660
+ TO_STR_1(_var) \
661
+ TO_STR_59(__VA_ARGS__)
662
+
663
+ #define TO_STR_61(_var, ...) \
664
+ TO_STR_1(_var) \
665
+ TO_STR_60(__VA_ARGS__)
666
+
667
+ #define TO_STR_62(_var, ...) \
668
+ TO_STR_1(_var) \
669
+ TO_STR_61(__VA_ARGS__)
670
+
671
+ #define TO_STR_63(_var, ...) \
672
+ TO_STR_1(_var) \
673
+ TO_STR_62(__VA_ARGS__)
674
+
675
+ /**
676
+ * Create C-string pointer variable(s) from `RedisModuleString` pointer(s).
677
+ * If `name` is a pointer to `RedisModuleString` then this macro will define
678
+ * symbols `name_str` and `name_len`. `name_str` is a `const char` pointer to
679
+ * the C-string representation of `name` and `name_len` is a `size_t` variable
680
+ * containing the the length of `name`.
681
+ */
682
+ #define TO_STR(...) \
683
+ CONCATENATE(TO_STR_, UTIL_NARG(__VA_ARGS__))(__VA_ARGS__)