@based/db 0.0.2 → 0.0.3
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/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/darwin_aarch64/{libnode-v22.13.1.node → libnode-v20.18.1.node} +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.8.0.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +317 -0
- package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +322 -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/base64.h +59 -0
- package/dist/lib/linux_aarch64/include/selva/base64url.h +59 -0
- package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -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 +284 -0
- package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +23 -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 +338 -0
- package/dist/lib/linux_aarch64/include/selva/find.h +47 -0
- package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -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/queue_r.h +190 -0
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +39 -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 +674 -0
- package/dist/lib/linux_aarch64/include/selva/sort.h +119 -0
- package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_aarch64/include/selva/traverse.h +65 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +110 -0
- package/dist/lib/linux_aarch64/include/selva/vector.h +14 -0
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/linux_aarch64/include/selva_error.h +137 -0
- package/dist/lib/linux_aarch64/include/selva_lang_code.h +157 -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-v20.11.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0.8.2 +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +317 -0
- package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +322 -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/base64.h +59 -0
- package/dist/lib/linux_x86_64/include/selva/base64url.h +59 -0
- package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -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 +284 -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 +23 -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 +338 -0
- package/dist/lib/linux_x86_64/include/selva/find.h +47 -0
- package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -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/queue_r.h +190 -0
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +39 -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 +674 -0
- package/dist/lib/linux_x86_64/include/selva/sort.h +119 -0
- package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_x86_64/include/selva/traverse.h +65 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +110 -0
- package/dist/lib/linux_x86_64/include/selva/vector.h +14 -0
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/linux_x86_64/include/selva_error.h +137 -0
- package/dist/lib/linux_x86_64/include/selva_lang_code.h +157 -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-v20.11.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0.8.2 +0 -0
- package/package.json +4 -4
- package/dist/src/client/bitWise.js.map +0 -1
- package/dist/src/client/crc32.js.map +0 -1
- package/dist/src/client/index.js.map +0 -1
- package/dist/src/client/modify/ModifyRes.js.map +0 -1
- package/dist/src/client/modify/alias.js.map +0 -1
- package/dist/src/client/modify/binary.js.map +0 -1
- package/dist/src/client/modify/create.js.map +0 -1
- package/dist/src/client/modify/fixed.js.map +0 -1
- package/dist/src/client/modify/hll.js.map +0 -1
- package/dist/src/client/modify/index.js.map +0 -1
- package/dist/src/client/modify/modify.js.map +0 -1
- package/dist/src/client/modify/references/edge.js.map +0 -1
- package/dist/src/client/modify/references/reference.js.map +0 -1
- package/dist/src/client/modify/references/references.js.map +0 -1
- package/dist/src/client/modify/remove.js.map +0 -1
- package/dist/src/client/modify/setCursor.js.map +0 -1
- package/dist/src/client/modify/string.js.map +0 -1
- package/dist/src/client/modify/text.js.map +0 -1
- package/dist/src/client/modify/types.js.map +0 -1
- package/dist/src/client/modify/update.js.map +0 -1
- package/dist/src/client/modify/upsert.js.map +0 -1
- package/dist/src/client/modify/vector.js.map +0 -1
- package/dist/src/client/operations.js.map +0 -1
- package/dist/src/client/query/BasedDbQuery.js.map +0 -1
- package/dist/src/client/query/BasedIterable.js.map +0 -1
- package/dist/src/client/query/debug.js.map +0 -1
- package/dist/src/client/query/display.js.map +0 -1
- package/dist/src/client/query/filter/FilterBranch.js.map +0 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js.map +0 -1
- package/dist/src/client/query/filter/createReferenceFilter.js.map +0 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js.map +0 -1
- package/dist/src/client/query/filter/filter.js.map +0 -1
- package/dist/src/client/query/filter/operators.js.map +0 -1
- package/dist/src/client/query/filter/parseFilterValue.js.map +0 -1
- package/dist/src/client/query/filter/primitiveFilter.js.map +0 -1
- package/dist/src/client/query/filter/toBuffer.js.map +0 -1
- package/dist/src/client/query/filter/types.js.map +0 -1
- package/dist/src/client/query/include/props.js.map +0 -1
- package/dist/src/client/query/include/toBuffer.js.map +0 -1
- package/dist/src/client/query/include/utils.js.map +0 -1
- package/dist/src/client/query/include/walk.js.map +0 -1
- package/dist/src/client/query/query.js.map +0 -1
- package/dist/src/client/query/queryDef.js.map +0 -1
- package/dist/src/client/query/read/read.js.map +0 -1
- package/dist/src/client/query/registerQuery.js.map +0 -1
- package/dist/src/client/query/search/index.js.map +0 -1
- package/dist/src/client/query/sort.js.map +0 -1
- package/dist/src/client/query/subscription/index.js.map +0 -1
- package/dist/src/client/query/subscription/markers.js.map +0 -1
- package/dist/src/client/query/subscription/run.js.map +0 -1
- package/dist/src/client/query/subscription/types.js.map +0 -1
- package/dist/src/client/query/thresholds.js.map +0 -1
- package/dist/src/client/query/toBuffer.js.map +0 -1
- package/dist/src/client/query/types.js.map +0 -1
- package/dist/src/client/query/validation.js.map +0 -1
- package/dist/src/client/string.js.map +0 -1
- package/dist/src/client/tree.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/native.js.map +0 -1
- package/dist/src/server/csmt/draw-dot.js.map +0 -1
- package/dist/src/server/csmt/index.js.map +0 -1
- package/dist/src/server/csmt/match.js.map +0 -1
- package/dist/src/server/csmt/memebership-proof.js.map +0 -1
- package/dist/src/server/csmt/tree-utils.js.map +0 -1
- package/dist/src/server/csmt/tree.js.map +0 -1
- package/dist/src/server/csmt/types.js.map +0 -1
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/migrate/index.js.map +0 -1
- package/dist/src/server/migrate/worker.js.map +0 -1
- package/dist/src/server/save.js.map +0 -1
- package/dist/src/server/schema/schema.js.map +0 -1
- package/dist/src/server/schema/selvaBuffer.js.map +0 -1
- package/dist/src/server/schema/typeDef.js.map +0 -1
- package/dist/src/server/schema/types.js.map +0 -1
- package/dist/src/server/schema/utils.js.map +0 -1
- package/dist/src/server/start.js.map +0 -1
- package/dist/src/server/tree.js.map +0 -1
- package/dist/src/server/worker.js.map +0 -1
- package/dist/test/alias.d.ts +0 -1
- package/dist/test/alias.js +0 -232
- package/dist/test/alias.js.map +0 -1
- package/dist/test/binary.d.ts +0 -1
- package/dist/test/binary.js +0 -45
- package/dist/test/binary.js.map +0 -1
- package/dist/test/boolean.d.ts +0 -1
- package/dist/test/boolean.js +0 -43
- package/dist/test/boolean.js.map +0 -1
- package/dist/test/clientServer.d.ts +0 -1
- package/dist/test/clientServer.js +0 -64
- package/dist/test/clientServer.js.map +0 -1
- package/dist/test/concurrency.d.ts +0 -1
- package/dist/test/concurrency.js +0 -61
- package/dist/test/concurrency.js.map +0 -1
- package/dist/test/csmt.d.ts +0 -1
- package/dist/test/csmt.js +0 -365
- package/dist/test/csmt.js.map +0 -1
- package/dist/test/edges.d.ts +0 -1
- package/dist/test/edges.js +0 -295
- package/dist/test/edges.js.map +0 -1
- package/dist/test/edgesReference.d.ts +0 -1
- package/dist/test/edgesReference.js +0 -179
- package/dist/test/edgesReference.js.map +0 -1
- package/dist/test/edgesReferences.d.ts +0 -1
- package/dist/test/edgesReferences.js +0 -472
- package/dist/test/edgesReferences.js.map +0 -1
- package/dist/test/enum.d.ts +0 -1
- package/dist/test/enum.js +0 -44
- package/dist/test/enum.js.map +0 -1
- package/dist/test/filter.d.ts +0 -1
- package/dist/test/filter.js +0 -512
- package/dist/test/filter.js.map +0 -1
- package/dist/test/filterString.d.ts +0 -1
- package/dist/test/filterString.js +0 -482
- package/dist/test/filterString.js.map +0 -1
- package/dist/test/flush.d.ts +0 -1
- package/dist/test/flush.js +0 -44
- package/dist/test/flush.js.map +0 -1
- package/dist/test/hll.d.ts +0 -1
- package/dist/test/hll.js +0 -32
- package/dist/test/hll.js.map +0 -1
- package/dist/test/migration.d.ts +0 -1
- package/dist/test/migration.js +0 -112
- package/dist/test/migration.js.map +0 -1
- package/dist/test/number.d.ts +0 -1
- package/dist/test/number.js +0 -172
- package/dist/test/number.js.map +0 -1
- package/dist/test/range.d.ts +0 -1
- package/dist/test/range.js +0 -70
- package/dist/test/range.js.map +0 -1
- package/dist/test/references.d.ts +0 -1
- package/dist/test/references.js +0 -350
- package/dist/test/references.js.map +0 -1
- package/dist/test/referencesIndex.d.ts +0 -1
- package/dist/test/referencesIndex.js +0 -151
- package/dist/test/referencesIndex.js.map +0 -1
- package/dist/test/referencesModify.d.ts +0 -1
- package/dist/test/referencesModify.js +0 -79
- package/dist/test/referencesModify.js.map +0 -1
- package/dist/test/remove.d.ts +0 -1
- package/dist/test/remove.js +0 -61
- package/dist/test/remove.js.map +0 -1
- package/dist/test/rootProps.d.ts +0 -1
- package/dist/test/rootProps.js +0 -53
- package/dist/test/rootProps.js.map +0 -1
- package/dist/test/save.d.ts +0 -1
- package/dist/test/save.js +0 -43
- package/dist/test/save.js.map +0 -1
- package/dist/test/saveRange.d.ts +0 -1
- package/dist/test/saveRange.js +0 -230
- package/dist/test/saveRange.js.map +0 -1
- package/dist/test/search.d.ts +0 -1
- package/dist/test/search.js +0 -322
- package/dist/test/search.js.map +0 -1
- package/dist/test/shared/assert.d.ts +0 -5
- package/dist/test/shared/assert.js +0 -75
- package/dist/test/shared/assert.js.map +0 -1
- package/dist/test/shared/examples.d.ts +0 -6
- package/dist/test/shared/examples.js +0 -1323
- package/dist/test/shared/examples.js.map +0 -1
- package/dist/test/shared/playground.d.ts +0 -1
- package/dist/test/shared/playground.js +0 -250
- package/dist/test/shared/playground.js.map +0 -1
- package/dist/test/shared/test.d.ts +0 -11
- package/dist/test/shared/test.js +0 -112
- package/dist/test/shared/test.js.map +0 -1
- package/dist/test/shared/worker.d.ts +0 -1
- package/dist/test/shared/worker.js +0 -127
- package/dist/test/shared/worker.js.map +0 -1
- package/dist/test/simpleQuery.d.ts +0 -1
- package/dist/test/simpleQuery.js +0 -43
- package/dist/test/simpleQuery.js.map +0 -1
- package/dist/test/singleRef.d.ts +0 -1
- package/dist/test/singleRef.js +0 -572
- package/dist/test/singleRef.js.map +0 -1
- package/dist/test/singleRefQuery.d.ts +0 -1
- package/dist/test/singleRefQuery.js +0 -136
- package/dist/test/singleRefQuery.js.map +0 -1
- package/dist/test/sort.d.ts +0 -1
- package/dist/test/sort.js +0 -401
- package/dist/test/sort.js.map +0 -1
- package/dist/test/sortIds.d.ts +0 -1
- package/dist/test/sortIds.js +0 -104
- package/dist/test/sortIds.js.map +0 -1
- package/dist/test/sortNumber.d.ts +0 -1
- package/dist/test/sortNumber.js +0 -76
- package/dist/test/sortNumber.js.map +0 -1
- package/dist/test/sortString.d.ts +0 -1
- package/dist/test/sortString.js +0 -118
- package/dist/test/sortString.js.map +0 -1
- package/dist/test/string.d.ts +0 -1
- package/dist/test/string.js +0 -310
- package/dist/test/string.js.map +0 -1
- package/dist/test/subscription.d.ts +0 -1
- package/dist/test/subscription.js +0 -336
- package/dist/test/subscription.js.map +0 -1
- package/dist/test/text.d.ts +0 -1
- package/dist/test/text.js +0 -87
- package/dist/test/text.js.map +0 -1
- package/dist/test/timestamp.d.ts +0 -1
- package/dist/test/timestamp.js +0 -50
- package/dist/test/timestamp.js.map +0 -1
- package/dist/test/update.d.ts +0 -1
- package/dist/test/update.js +0 -223
- package/dist/test/update.js.map +0 -1
- package/dist/test/validation.d.ts +0 -1
- package/dist/test/validation.js +0 -90
- package/dist/test/validation.js.map +0 -1
- package/dist/test/vector.d.ts +0 -1
- package/dist/test/vector.js +0 -47
- package/dist/test/vector.js.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "selva/_export.h"
|
|
8
|
+
#include "selva/types.h"
|
|
9
|
+
#include "selva/traverse.h"
|
|
10
|
+
|
|
11
|
+
struct SelvaFindParam {
|
|
12
|
+
SelvaTraversalNodeCallback node_cb;
|
|
13
|
+
void *node_arg;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Traverse field selector.
|
|
17
|
+
*/
|
|
18
|
+
const struct FindFields {
|
|
19
|
+
uint8_t len;
|
|
20
|
+
struct {
|
|
21
|
+
node_type_t type;
|
|
22
|
+
field_t field;
|
|
23
|
+
} __packed data[];
|
|
24
|
+
} __packed *fields;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Skip the first n nodes in the traversal.
|
|
28
|
+
* This happens before filtering.
|
|
29
|
+
*/
|
|
30
|
+
ssize_t skip;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Skip the first n - 1 results.
|
|
34
|
+
* This skipping is executed on the final result set.
|
|
35
|
+
* 0 for no offset.
|
|
36
|
+
*/
|
|
37
|
+
ssize_t offset;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Limit the number of results.
|
|
41
|
+
* -1 for no limit (inf).
|
|
42
|
+
*/
|
|
43
|
+
ssize_t limit;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
SELVA_EXPORT
|
|
47
|
+
int selva_find(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFindParam *param);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2022 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
#ifndef _UTIL_LPF_H_
|
|
7
|
+
#define _UTIL_LPF_H_
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calculate the alpha coefficient for the lpf.
|
|
11
|
+
*/
|
|
12
|
+
__constfn static inline float lpf_geta(float period, float sample_interval);
|
|
13
|
+
static inline float lpf_geta(float period, float sample_interval) {
|
|
14
|
+
return __builtin_expf(-(sample_interval / period));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Calculate the next output value of the lpf.
|
|
19
|
+
* @param prev is the previous output of this function.
|
|
20
|
+
* @param a is the coefficient calculated by lpf_geta().
|
|
21
|
+
* @param sample is the current sample.
|
|
22
|
+
*/
|
|
23
|
+
__constfn static inline float lpf_calc_next(float a, float prev, float sample);
|
|
24
|
+
static inline float lpf_calc_next(float a, float prev, float sample) {
|
|
25
|
+
return a * prev + (1.0f - a) * sample;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#endif /* _UTIL_LPF_H_ */
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include <sys/types.h>
|
|
9
|
+
#include "selva/types.h"
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* node_id set is an array that is always sorted for fast lookups.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Search from a node_id set.
|
|
17
|
+
*/
|
|
18
|
+
SELVA_EXPORT
|
|
19
|
+
ssize_t node_id_set_bsearch(const node_id_t *a, size_t n, node_id_t x)
|
|
20
|
+
__attribute__((access(read_only, 1, 2)));
|
|
21
|
+
|
|
22
|
+
static inline bool node_id_set_has(const node_id_t *set, size_t len, node_id_t id)
|
|
23
|
+
{
|
|
24
|
+
if (len == 0) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return node_id_set_bsearch(set, len, id) >= 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sorted insert to a node_id set.
|
|
33
|
+
* @param set_p is an array allocated with jemalloc_selva.
|
|
34
|
+
*/
|
|
35
|
+
SELVA_EXPORT
|
|
36
|
+
bool node_id_set_add(node_id_t **set_p, size_t *len, node_id_t id);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Remove from a node_id set.
|
|
40
|
+
* @param set_p is an array allocated with jemalloc_selva.
|
|
41
|
+
*/
|
|
42
|
+
SELVA_EXPORT
|
|
43
|
+
bool node_id_set_remove(node_id_t **set_p, size_t *len, node_id_t id);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2022, 2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "selva/_export.h"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An element in the poptop list.
|
|
11
|
+
*/
|
|
12
|
+
struct poptop_list_el {
|
|
13
|
+
float score;
|
|
14
|
+
void *p;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A poptop structure.
|
|
19
|
+
* Poptop is a data structure that attempts to keep a list of the most popular
|
|
20
|
+
* entries based on a score seen on each insert. The list is kept at least
|
|
21
|
+
* half-full at all times.
|
|
22
|
+
*
|
|
23
|
+
* The data structure has a maximum size of `max_size` and a cutoff limit that's
|
|
24
|
+
* the median of the score of elements currently on the list. A new cutoff is
|
|
25
|
+
* calculated when `poptop_maintenance()` is called and each call to
|
|
26
|
+
* `poptop_maintenance_drop()` removes one element falling under the cutoff
|
|
27
|
+
* limit until every element of the list has no more elements with score under
|
|
28
|
+
* the cutoff limit.
|
|
29
|
+
*
|
|
30
|
+
* The list can be iterated using the `POPTOP_FOREACH()` macro.
|
|
31
|
+
*
|
|
32
|
+
* The list is not guaranteed to be ordered, in fact, it's typically unordered
|
|
33
|
+
* unless `poptop_maintenance()` was called and no new inserts have been made
|
|
34
|
+
* since that call.
|
|
35
|
+
*/
|
|
36
|
+
struct poptop {
|
|
37
|
+
/**
|
|
38
|
+
* Maximum size of the top list.
|
|
39
|
+
*/
|
|
40
|
+
unsigned int max_size;
|
|
41
|
+
/**
|
|
42
|
+
* Current number of elements on the top list.
|
|
43
|
+
*/
|
|
44
|
+
unsigned int current_size;
|
|
45
|
+
/**
|
|
46
|
+
* Minimum score.
|
|
47
|
+
* A long term minimum score for an element to get into and remain in the
|
|
48
|
+
* data structure. This is updated when poptop_maintenance() is called.
|
|
49
|
+
*/
|
|
50
|
+
float cut_limit;
|
|
51
|
+
struct poptop_list_el *list;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* An iterator for `struct poptop`.
|
|
56
|
+
* Note that the elements in the poptop list are not returned in any
|
|
57
|
+
* particular order.
|
|
58
|
+
* @param[out] _el_ is a pointer to a `poptop_list_el` structure. Can be NULL.
|
|
59
|
+
* @param _l_ is a pointer to the poptop instance to be iterated over.
|
|
60
|
+
*/
|
|
61
|
+
#define POPTOP_FOREACH(_el_, _l_) \
|
|
62
|
+
_el_ = (_l_)->list - 1; \
|
|
63
|
+
while (++_el_ != ((_l_)->list + (_l_)->max_size))
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Initialize a poptop structure.
|
|
67
|
+
* @param l is a pointer to an uninitalized poptop structure.
|
|
68
|
+
* @param max_size is the maximum number of elements allowed in the data
|
|
69
|
+
* structure. Poptop will attempt to maintain a list of about half of the
|
|
70
|
+
* maximum size.
|
|
71
|
+
* @param initial_cut is an initial value for the cut limit.
|
|
72
|
+
* @returns 0 if succeed; Otherwise a non-zero value is returned.
|
|
73
|
+
*/
|
|
74
|
+
SELVA_EXPORT
|
|
75
|
+
int poptop_init(struct poptop *l, unsigned int max_size, float initial_cut);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Deinit a poptop structure.
|
|
79
|
+
* @param l is a pointer to an initialized poptop structure.
|
|
80
|
+
*/
|
|
81
|
+
SELVA_EXPORT
|
|
82
|
+
void poptop_deinit(struct poptop *l);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Add an element to the top list if it's above the self-determined score limit.
|
|
86
|
+
* If the element already exists the score is updated.
|
|
87
|
+
* @param l is a pointer to the poptop structure.
|
|
88
|
+
*/
|
|
89
|
+
SELVA_EXPORT
|
|
90
|
+
void poptop_maybe_add(struct poptop * restrict l, float score, void * restrict p);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Remove an element from the top list.
|
|
94
|
+
* @param l is a pointer to the poptop structure.
|
|
95
|
+
*/
|
|
96
|
+
SELVA_EXPORT
|
|
97
|
+
void poptop_remove(struct poptop * restrict l, const void * restrict p);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Periodic maintenance.
|
|
101
|
+
* Find the median score and establish a new cut limit.
|
|
102
|
+
* @param l is a pointer to the poptop structure.
|
|
103
|
+
*/
|
|
104
|
+
SELVA_EXPORT
|
|
105
|
+
int poptop_maintenance(struct poptop *l);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Drop an element that has a score below the cut limit.
|
|
109
|
+
* This function should be called repeatedly until no entry is returned.
|
|
110
|
+
* @param l is a pointer to the poptop structure.
|
|
111
|
+
* @returns a pointer to the element that was removed from the data structure l.
|
|
112
|
+
*/
|
|
113
|
+
SELVA_EXPORT
|
|
114
|
+
void *poptop_maintenance_drop(struct poptop *l);
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*******************************************************************************
|
|
3
|
+
* @file queue_r.h
|
|
4
|
+
* @author Olli Vanhoja
|
|
5
|
+
* @brief Thread-safe queue
|
|
6
|
+
* @section LICENSE
|
|
7
|
+
* Copyright (c) 2020-2021, 2023, 2025 SAULX
|
|
8
|
+
* Copyright (c) 2013, 2015, 2016 Olli Vanhoja <olli.vanhoja@cs.helsinki.fi>
|
|
9
|
+
* Copyright (c) 2012, 2013 Ninjaware Oy,
|
|
10
|
+
* Olli Vanhoja <olli.vanhoja@ninjaware.fi>
|
|
11
|
+
* All rights reserved.
|
|
12
|
+
*
|
|
13
|
+
* Redistribution and use in source and binary forms, with or without
|
|
14
|
+
* modification, are permitted provided that the following conditions are met:
|
|
15
|
+
*
|
|
16
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
17
|
+
* this list of conditions and the following disclaimer.
|
|
18
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
19
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
20
|
+
* and/or other materials provided with the distribution.
|
|
21
|
+
*
|
|
22
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
23
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
24
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
25
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
26
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
27
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
28
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
29
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
30
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
31
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
32
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
+
*
|
|
34
|
+
* SPDX-License-Identifier: BSD-2-Clause
|
|
35
|
+
*******************************************************************************
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @addtogroup queue_r
|
|
40
|
+
* @{
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
#pragma once
|
|
44
|
+
|
|
45
|
+
#include <stddef.h>
|
|
46
|
+
#include "selva/_export.h"
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Queue control block.
|
|
50
|
+
*/
|
|
51
|
+
typedef struct queue_cb {
|
|
52
|
+
void * data; /*!< Pointer to the data array used for queue. */
|
|
53
|
+
size_t b_size; /*!< Block size in bytes. */
|
|
54
|
+
size_t a_len; /*!< Array length. */
|
|
55
|
+
size_t m_write; /*!< Write index. */
|
|
56
|
+
size_t m_read; /*!< Read index. */
|
|
57
|
+
} queue_cb_t;
|
|
58
|
+
|
|
59
|
+
#define QUEUE_INITIALIZER(data_array, block_size, array_size) \
|
|
60
|
+
(struct queue_cb){ \
|
|
61
|
+
.data = (data_array), \
|
|
62
|
+
.b_size = (block_size), \
|
|
63
|
+
.a_len = (array_size / block_size), \
|
|
64
|
+
.m_write = 0, \
|
|
65
|
+
.m_read = 0, \
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Create a new queue control block.
|
|
70
|
+
* Initializes a new queue control block and returns it as a value.
|
|
71
|
+
* @param data_array an array where the actual queue data is stored.
|
|
72
|
+
* @param block_size the size of single data block/struct/data type in
|
|
73
|
+
* data_array in bytes.
|
|
74
|
+
* @param array_size the size of the data_array in bytes.
|
|
75
|
+
* @return a new queue_cb_t queue control block structure.
|
|
76
|
+
*/
|
|
77
|
+
SELVA_EXPORT
|
|
78
|
+
queue_cb_t queue_create(void * data_array, size_t block_size,
|
|
79
|
+
size_t array_size)
|
|
80
|
+
__attribute__((pure, access(read_only, 1, 3)));
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Push an element to the queue.
|
|
84
|
+
* @param cb is a pointer to the queue control block.
|
|
85
|
+
* @param element the new element to be copied.
|
|
86
|
+
* @return 0 if queue is already full; otherwise operation was succeed.
|
|
87
|
+
* @note element is always copied to the queue, so it is safe to remove the
|
|
88
|
+
* original data after a push.
|
|
89
|
+
*/
|
|
90
|
+
SELVA_EXPORT
|
|
91
|
+
int queue_push(queue_cb_t * cb, const void * element)
|
|
92
|
+
__attribute__((access(read_write, 1)));
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Allocate an element from the queue.
|
|
96
|
+
* @param cb is a pointer to the queue control block.
|
|
97
|
+
* @return A pointer to the element in the queue.
|
|
98
|
+
*/
|
|
99
|
+
SELVA_EXPORT
|
|
100
|
+
void * queue_alloc_get(queue_cb_t * cb)
|
|
101
|
+
__attribute__((access(read_write, 1)));
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Commit previous allocation from the queue.
|
|
105
|
+
* @note queue_push() should not be called between calls to queue_alloc_get()
|
|
106
|
+
* and queue_alloc_commit().
|
|
107
|
+
*/
|
|
108
|
+
SELVA_EXPORT
|
|
109
|
+
void queue_alloc_commit(queue_cb_t * cb)
|
|
110
|
+
__attribute__((access(read_write, 1)));
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Pop an element from the queue.
|
|
114
|
+
* @param cb is a pointer to the queue control block.
|
|
115
|
+
* @param element is the location where element is copied to from the queue.
|
|
116
|
+
* @return 0 if queue is empty; otherwise operation was succeed.
|
|
117
|
+
*/
|
|
118
|
+
SELVA_EXPORT
|
|
119
|
+
int queue_pop(queue_cb_t * cb, void * element)
|
|
120
|
+
__attribute__((access(read_write, 1)));
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Peek an element from the queue.
|
|
124
|
+
* @param cb is a pointer to the queue control block.
|
|
125
|
+
* @param element is the location where element is copied to from the queue.
|
|
126
|
+
* @return 0 if queue is empty; otherwise operation was succeed.
|
|
127
|
+
*/
|
|
128
|
+
SELVA_EXPORT
|
|
129
|
+
int queue_peek(queue_cb_t * cb, void ** element)
|
|
130
|
+
__attribute__((access(read_only, 1), access(write_only, 2)));
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Skip n number of elements in the queue.
|
|
134
|
+
* @param cb is a pointer to the queue control block.
|
|
135
|
+
* @return Returns the number of elements skipped.
|
|
136
|
+
*/
|
|
137
|
+
SELVA_EXPORT
|
|
138
|
+
int queue_skip(queue_cb_t * cb, size_t n)
|
|
139
|
+
__attribute__((access(read_write, 1)));
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Clear the queue.
|
|
143
|
+
* This operation is considered safe when committed from the push end thread.
|
|
144
|
+
* @param cb is a pointer to the queue control block.
|
|
145
|
+
*/
|
|
146
|
+
SELVA_EXPORT
|
|
147
|
+
void queue_clear_from_push_end(queue_cb_t * cb)
|
|
148
|
+
__attribute__((access(read_write, 1)));
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Clear the queue.
|
|
152
|
+
* This operation is considered safe when committed from the pop end thread.
|
|
153
|
+
* @param cb is a pointer to the queue control block.
|
|
154
|
+
*/
|
|
155
|
+
SELVA_EXPORT
|
|
156
|
+
void queue_clear_from_pop_end(queue_cb_t * cb)
|
|
157
|
+
__attribute__((access(read_write, 1)));
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Check if the queue is empty.
|
|
161
|
+
* @param cb is a pointer to the queue control block.
|
|
162
|
+
* @return 0 if the queue is not empty.
|
|
163
|
+
*/
|
|
164
|
+
SELVA_EXPORT
|
|
165
|
+
int queue_isempty(const queue_cb_t * cb)
|
|
166
|
+
__attribute__((access(read_only, 1)));
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Check if the queue is full.
|
|
170
|
+
* @param cb is a pointer to the queue control block.
|
|
171
|
+
* @return 0 if the queue is not full.
|
|
172
|
+
*/
|
|
173
|
+
SELVA_EXPORT
|
|
174
|
+
int queue_isfull(const queue_cb_t * cb)
|
|
175
|
+
__attribute__((access(read_only, 1)));
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Seek queue.
|
|
179
|
+
* @param cb is a pointer to the queue control block.
|
|
180
|
+
* @param i index.
|
|
181
|
+
* @param[in] element returned element.
|
|
182
|
+
* @return 0 if failed; otherwise succeed.
|
|
183
|
+
*/
|
|
184
|
+
SELVA_EXPORT
|
|
185
|
+
int seek(const queue_cb_t * cb, size_t i, void * element)
|
|
186
|
+
__attribute__((access(read_only, 1), access(write_only, 3)));
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @}
|
|
190
|
+
*/
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
#include "xxhash.h"
|
|
7
|
+
#include "selva/types.h"
|
|
8
|
+
|
|
9
|
+
typedef struct XXH3_state_s selva_hash_state_t;
|
|
10
|
+
|
|
11
|
+
#define selva_hash_create_state XXH3_createState
|
|
12
|
+
#define selva_hash_reset XXH3_128bits_reset
|
|
13
|
+
#define selva_hash_free_state XXH3_freeState
|
|
14
|
+
#define selva_hash_update XXH3_128bits_update
|
|
15
|
+
|
|
16
|
+
SELVA_EXPORT
|
|
17
|
+
selva_hash128_t selva_hash_digest_zig(selva_hash_state_t *hash_state);
|
|
18
|
+
|
|
19
|
+
#ifdef __zig
|
|
20
|
+
#define selva_hash_digest selva_hash_digest_zig
|
|
21
|
+
#else
|
|
22
|
+
static inline selva_hash128_t selva_hash_digest(selva_hash_state_t *hash_state)
|
|
23
|
+
{
|
|
24
|
+
XXH128_hash_t res;
|
|
25
|
+
|
|
26
|
+
retry:
|
|
27
|
+
res = XXH3_128bits_digest(hash_state);
|
|
28
|
+
if (res.low64 == 0 && res.high64 == 0) {
|
|
29
|
+
/*
|
|
30
|
+
* We don't allow zero hash.
|
|
31
|
+
* RFE Is this a good approach?
|
|
32
|
+
*/
|
|
33
|
+
XXH3_128bits_update(hash_state, &(int64_t){ 1 }, sizeof(int64_t));
|
|
34
|
+
goto retry;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (selva_hash128_t)res.low64 | (selva_hash128_t)res.high64 << 64;
|
|
38
|
+
}
|
|
39
|
+
#endif
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, 2024-2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#if defined(__APPLE__) && __MACH__
|
|
8
|
+
#include <xlocale.h>
|
|
9
|
+
#endif
|
|
10
|
+
#include <locale.h>
|
|
11
|
+
#include <wchar.h>
|
|
12
|
+
#include <wctype.h>
|
|
13
|
+
#include "selva/_export.h"
|
|
14
|
+
#include "selva_lang_code.h"
|
|
15
|
+
|
|
16
|
+
#define SELVA_LANG_NAME_MAX 4ul
|
|
17
|
+
|
|
18
|
+
struct libdeflate_decompressor;
|
|
19
|
+
struct libdeflate_block_state;
|
|
20
|
+
|
|
21
|
+
int selva_lang_set_fallback(const char *lang_str, size_t lang_len);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get locale for a lang string.
|
|
25
|
+
* @param lang_str is a pointer to the language name.
|
|
26
|
+
* @param lang_len is the length of lang_str excluding any possible nul-character(s).
|
|
27
|
+
* @returns a POSIX locale.
|
|
28
|
+
*/
|
|
29
|
+
SELVA_EXPORT
|
|
30
|
+
locale_t selva_lang_getlocale(const char *lang_str, size_t lang_len);
|
|
31
|
+
|
|
32
|
+
SELVA_EXPORT
|
|
33
|
+
locale_t selva_lang_getlocale2(enum selva_lang_code lang);
|
|
34
|
+
|
|
35
|
+
/* TODO rename these */
|
|
36
|
+
enum selva_langs_trans {
|
|
37
|
+
SELVA_LANGS_TRANS_NONE = 0,
|
|
38
|
+
SELVA_LANGS_TRANS_TOUPPER,
|
|
39
|
+
SELVA_LANGS_TRANS_TOLOWER,
|
|
40
|
+
SELVA_LANGS_TRANS_TOJHIRA, /*!< When lang is selva_lang_ja. */
|
|
41
|
+
SELVA_LANGS_TRANS_TOJKATA, /*!< When lang is selva_lang_ja. */
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
SELVA_EXPORT
|
|
45
|
+
wctrans_t selva_lang_wctrans(enum selva_lang_code lang, enum selva_langs_trans trans);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Transform a multibyte string.
|
|
49
|
+
* @returns a selva_malloc'd c-string.
|
|
50
|
+
*/
|
|
51
|
+
SELVA_EXPORT
|
|
52
|
+
char *selva_mbstrans(locale_t loc, const char *src, size_t len, wctrans_t trans);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Read a symbol from a multibyte string.
|
|
56
|
+
* @param wc symbol read from mbs_str.
|
|
57
|
+
* @returns bytes consumed from mbs_str.
|
|
58
|
+
*/
|
|
59
|
+
SELVA_EXPORT
|
|
60
|
+
size_t selva_mbstowc(wchar_t *wc, const char *mbs_str, size_t mbs_len, mbstate_t *ps, wctrans_t trans, locale_t loc);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Compare two multibyte strings by transforming each character.
|
|
64
|
+
* Unicode normalization and flattening is not supported.
|
|
65
|
+
*/
|
|
66
|
+
SELVA_EXPORT
|
|
67
|
+
int selva_mbscmp(const char *mbs1_str, size_t mbs1_len, const char *mbs2_str, size_t mbs2_len, wctrans_t trans, locale_t loc);
|
|
68
|
+
|
|
69
|
+
SELVA_EXPORT
|
|
70
|
+
int selva_deflate_mbscmp(
|
|
71
|
+
struct libdeflate_decompressor *decompressor,
|
|
72
|
+
struct libdeflate_block_state *state,
|
|
73
|
+
const char *in_buf, size_t in_len,
|
|
74
|
+
const char *mbs2_str, size_t mbs2_len,
|
|
75
|
+
wctrans_t trans, locale_t loc);
|
|
76
|
+
|
|
77
|
+
SELVA_EXPORT
|
|
78
|
+
const char *selva_mbsstrstr(const char *mbs1_str, size_t mbs1_len, const char *mbs2_str, size_t mbs2_len, wctrans_t trans, locale_t loc);
|
|
79
|
+
|
|
80
|
+
SELVA_EXPORT
|
|
81
|
+
bool selva_deflate_mbsstrstr(
|
|
82
|
+
struct libdeflate_decompressor *decompressor,
|
|
83
|
+
struct libdeflate_block_state *state,
|
|
84
|
+
const char *in_buf, size_t in_len,
|
|
85
|
+
const void *needle_buf, size_t needle_len,
|
|
86
|
+
wctrans_t trans, locale_t loc);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Constructs a value of type wctrans_t that describes a LC_CTYPE category of wide character mapping.
|
|
90
|
+
* - "" none
|
|
91
|
+
* - "toupper"
|
|
92
|
+
* - "tolower"
|
|
93
|
+
* - "tojhira" when lang is "jp"
|
|
94
|
+
* - "tojkata" when lang is "jp"
|
|
95
|
+
*/
|
|
96
|
+
static inline wctrans_t selva_wctrans(const char *class_str, size_t class_len, locale_t loc)
|
|
97
|
+
{
|
|
98
|
+
char charclass[16] = {};
|
|
99
|
+
|
|
100
|
+
if (likely(class_len < sizeof(charclass))) {
|
|
101
|
+
__builtin_memcpy(charclass, class_str, class_len);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return wctrans_l(charclass, loc);
|
|
105
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2024 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
#include <math.h>
|
|
7
|
+
|
|
8
|
+
static inline double nan_undefined(void)
|
|
9
|
+
{
|
|
10
|
+
return nan("1");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static inline int isnan_undefined(double x)
|
|
14
|
+
{
|
|
15
|
+
long long i;
|
|
16
|
+
|
|
17
|
+
if (!isnan(x)) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
__builtin_memcpy(&i, &x, sizeof(i));
|
|
22
|
+
|
|
23
|
+
return i & 1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Mod (%) like it is in JS.
|
|
28
|
+
*/
|
|
29
|
+
static inline double js_fmod(double x, double y)
|
|
30
|
+
{
|
|
31
|
+
double result = remainder(fabs(x), (y = fabs(y)));
|
|
32
|
+
if (signbit(result)) {
|
|
33
|
+
result += y;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return copysign(result, x);
|
|
37
|
+
}
|