functionalscript 0.1.608 → 0.2.0
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/CHANGELOG.md +10 -0
- package/Cargo.lock +4 -0
- package/Cargo.toml +4 -2
- package/README.md +1 -1
- package/com/cpp/module.f.d.mts +4 -8
- package/com/cpp/module.f.mjs +20 -25
- package/com/cpp/testlib.f.mjs +3 -4
- package/com/cs/module.f.d.mts +4 -8
- package/com/cs/module.f.mjs +18 -23
- package/com/cs/testlib.f.mjs +3 -5
- package/com/rust/module.f.d.mts +3 -7
- package/com/rust/module.f.mjs +25 -30
- package/com/rust/nanocom/src/cobject.rs +1 -1
- package/com/rust/testlib.f.mjs +3 -5
- package/com/test/build.f.d.mts +2 -2
- package/com/test/build.f.mjs +2 -2
- package/com/test/build.mjs +4 -4
- package/com/test/rust/src/lib.rs +4 -4
- package/com/types/module.f.d.mts +5 -10
- package/com/types/module.f.mjs +5 -12
- package/commonjs/build/module.f.d.mts +13 -17
- package/commonjs/build/module.f.mjs +23 -28
- package/commonjs/build/test.f.mjs +4 -4
- package/commonjs/module/function/module.f.d.mts +0 -2
- package/commonjs/module/function/module.f.mjs +0 -2
- package/commonjs/module/module.f.d.mts +16 -21
- package/commonjs/module/module.f.mjs +2 -9
- package/commonjs/module.d.mts +1 -5
- package/commonjs/module.f.d.mts +0 -2
- package/commonjs/module.f.mjs +0 -2
- package/commonjs/module.mjs +2 -7
- package/commonjs/package/dependencies/module.f.d.mts +3 -7
- package/commonjs/package/dependencies/module.f.mjs +5 -10
- package/commonjs/package/dependencies/test.f.mjs +1 -1
- package/commonjs/package/module.f.d.mts +12 -18
- package/commonjs/package/module.f.mjs +6 -13
- package/commonjs/package/test.f.mjs +1 -1
- package/commonjs/path/module.f.d.mts +25 -32
- package/commonjs/path/module.f.mjs +12 -23
- package/commonjs/path/test.f.mjs +11 -11
- package/commonjs/test.mjs +1 -1
- package/dev/module.f.d.mts +1 -4
- package/dev/module.f.mjs +1 -4
- package/dev/module.mjs +1 -1
- package/dev/test/module.f.d.mts +2 -3
- package/dev/test/module.f.mjs +5 -7
- package/djs/module.f.d.mts +13 -18
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.d.mts +53 -37
- package/djs/parser/module.f.mjs +278 -131
- package/djs/parser/test.f.d.mts +4 -0
- package/djs/parser/test.f.mjs +186 -70
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.d.mts +6 -10
- package/djs/tokenizer/module.f.mjs +19 -22
- package/djs/tokenizer/test.f.mjs +7 -7
- package/doc/LANGUAGE.md +17 -16
- package/doc/README.md +14 -50
- package/fsc/README.md +0 -3
- package/fsc/module.f.d.mts +4 -9
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/README.md +1 -1
- package/fsm/module.f.d.mts +13 -20
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/README.md +24 -0
- package/html/module.f.d.mts +7 -12
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/issues/01-test-debug.md +3 -0
- package/issues/{publish.md → 05-publish.md} +8 -8
- package/issues/17-djs-extension.md +6 -0
- package/issues/README.md +20 -13
- package/issues/lang/1000-json.md +38 -0
- package/issues/lang/2110-default-export.md +2 -2
- package/issues/lang/2310-undefined.md +1 -1
- package/issues/lang/2330-property-accessor.md +225 -0
- package/issues/lang/2360-built-in.md +54 -47
- package/issues/lang/3240-export.md +44 -0
- package/issues/lang/README.md +64 -22
- package/issues/test.f.d.mts +16 -0
- package/issues/test.f.mjs +57 -0
- package/js/tokenizer/module.f.d.mts +18 -17
- package/js/tokenizer/module.f.mjs +80 -61
- package/js/tokenizer/test.f.mjs +15 -12
- package/json/module.f.d.mts +18 -26
- package/json/module.f.mjs +18 -31
- package/json/parser/module.f.d.mts +9 -13
- package/json/parser/module.f.mjs +9 -14
- package/json/parser/test.f.mjs +7 -7
- package/json/serializer/module.f.d.mts +11 -20
- package/json/serializer/module.f.mjs +14 -29
- package/json/serializer/test.f.mjs +2 -2
- package/json/test.f.mjs +3 -3
- package/json/tokenizer/module.f.d.mts +6 -10
- package/json/tokenizer/module.f.mjs +16 -20
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +1 -1
- package/nanvm-lib/Cargo.toml +6 -0
- package/nanvm-lib/src/extension.rs +119 -0
- package/nanvm-lib/src/interface.rs +136 -0
- package/nanvm-lib/src/lib.rs +7 -0
- package/nanvm-lib/src/naive.rs +229 -0
- package/nanvm-lib/src/nanenum.rs +230 -0
- package/nanvm-lib/src/nullish.rs +7 -0
- package/nanvm-lib/src/sign.rs +5 -0
- package/nanvm-lib/src/simple.rs +32 -0
- package/nanvm-lib/tests/test.f.d.mts +36 -0
- package/nanvm-lib/tests/test.f.mjs +79 -0
- package/nanvm-lib/tests/test.rs +108 -0
- package/nodejs/version/main.mjs +1 -1
- package/nodejs/version/module.f.d.mts +4 -9
- package/nodejs/version/module.f.mjs +2 -7
- package/nodejs/version/test.f.mjs +3 -3
- package/package.json +1 -1
- package/prime_field/module.f.d.mts +20 -23
- package/prime_field/module.f.mjs +9 -12
- package/prime_field/test.f.mjs +1 -1
- package/secp/module.f.d.mts +27 -28
- package/secp/module.f.mjs +38 -39
- package/secp/test.f.mjs +4 -4
- package/sha2/module.f.d.mts +8 -16
- package/sha2/module.f.mjs +7 -20
- package/sha2/test.f.mjs +4 -4
- package/text/README.md +2 -2
- package/text/ascii/module.f.d.mts +69 -72
- package/text/ascii/module.f.mjs +5 -10
- package/text/ascii/test.f.mjs +3 -3
- package/text/module.f.d.mts +9 -14
- package/text/module.f.mjs +7 -14
- package/text/sgr/module.f.d.mts +7 -9
- package/text/sgr/module.f.mjs +2 -4
- package/text/test.f.mjs +3 -3
- package/text/utf16/module.f.d.mts +8 -15
- package/text/utf16/module.f.mjs +17 -28
- package/text/utf16/test.f.mjs +5 -5
- package/text/utf8/module.f.d.mts +4 -9
- package/text/utf8/module.f.mjs +9 -16
- package/text/utf8/test.f.mjs +4 -4
- package/types/array/module.f.d.mts +14 -24
- package/types/array/module.f.mjs +8 -25
- package/types/array/test.f.mjs +3 -3
- package/types/bigfloat/module.f.d.mts +4 -9
- package/types/bigfloat/module.f.mjs +3 -10
- package/types/bigfloat/test.f.mjs +1 -1
- package/types/bigint/module.f.d.mts +16 -64
- package/types/bigint/module.f.mjs +11 -30
- package/types/bigint/test.f.mjs +1 -1
- package/types/btree/find/module.f.d.mts +20 -26
- package/types/btree/find/module.f.mjs +8 -17
- package/types/btree/find/test.f.mjs +7 -7
- package/types/btree/module.f.d.mts +4 -8
- package/types/btree/module.f.mjs +6 -11
- package/types/btree/remove/module.f.d.mts +7 -12
- package/types/btree/remove/module.f.mjs +10 -17
- package/types/btree/remove/test.f.mjs +5 -5
- package/types/btree/set/module.f.d.mts +3 -7
- package/types/btree/set/module.f.mjs +4 -9
- package/types/btree/set/test.f.mjs +4 -4
- package/types/btree/test.f.mjs +9 -9
- package/types/btree/types/module.f.d.mts +0 -2
- package/types/btree/types/module.f.mjs +0 -2
- package/types/byte_set/module.f.d.mts +16 -29
- package/types/byte_set/module.f.mjs +14 -39
- package/types/byte_set/test.f.mjs +5 -5
- package/types/function/compare/module.f.d.mts +9 -15
- package/types/function/compare/module.f.mjs +3 -12
- package/types/function/compare/test.f.mjs +1 -1
- package/types/function/module.f.d.mts +20 -27
- package/types/function/module.f.mjs +4 -15
- package/types/function/operator/module.f.d.mts +28 -43
- package/types/function/operator/module.f.mjs +14 -41
- package/types/function/test.f.mjs +1 -1
- package/types/list/module.f.d.mts +56 -91
- package/types/list/module.f.mjs +45 -114
- package/types/list/test.f.mjs +10 -10
- package/types/map/module.f.d.mts +15 -24
- package/types/map/module.f.mjs +15 -30
- package/types/map/test.f.mjs +2 -2
- package/types/nibble_set/module.f.d.mts +10 -20
- package/types/nibble_set/module.f.mjs +7 -24
- package/types/nibble_set/test.f.mjs +2 -2
- package/types/nullable/module.f.d.mts +3 -8
- package/types/nullable/module.f.mjs +2 -9
- package/types/nullable/test.f.mjs +1 -1
- package/types/number/module.f.d.mts +7 -13
- package/types/number/module.f.mjs +8 -19
- package/types/number/test.f.mjs +1 -1
- package/types/object/module.f.d.mts +11 -18
- package/types/object/module.f.mjs +9 -20
- package/types/object/test.f.mjs +1 -1
- package/types/range/module.f.d.mts +3 -8
- package/types/range/module.f.mjs +2 -9
- package/types/range/test.f.mjs +1 -1
- package/types/range_map/module.f.d.mts +9 -15
- package/types/range_map/module.f.mjs +9 -18
- package/types/range_map/test.f.mjs +32 -32
- package/types/result/module.d.mts +3 -3
- package/types/result/module.f.d.mts +6 -12
- package/types/result/module.f.mjs +3 -12
- package/types/result/module.mjs +2 -2
- package/types/sorted_list/module.f.d.mts +22 -28
- package/types/sorted_list/module.f.mjs +10 -19
- package/types/sorted_list/test.f.mjs +7 -7
- package/types/sorted_set/module.f.d.mts +6 -12
- package/types/sorted_set/module.f.mjs +7 -16
- package/types/sorted_set/test.f.mjs +7 -7
- package/types/string/module.f.d.mts +8 -14
- package/types/string/module.f.mjs +10 -21
- package/types/string/test.f.mjs +2 -2
- package/types/string_set/module.f.d.mts +8 -16
- package/types/string_set/module.f.mjs +12 -27
- package/types/string_set/test.f.mjs +1 -1
- package/issues/lang/2351-property-accessor.md +0 -44
- package/issues/lang/2352-property-call.md +0 -43
- package/issues/lang/2353-property-at.md +0 -19
- package/issues/test-debug.md +0 -12
- /package/issues/{esm.md → 02-esm.md} +0 -0
- /package/issues/{djs.md → 03-djs.md} +0 -0
- /package/issues/{fs-load.md → 11-fs-load.md} +0 -0
- /package/issues/lang/{2330-grouping.md → 2350-grouping.md} +0 -0
package/types/array/module.f.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import option from '../nullable/module.f.mjs'
|
|
2
|
+
import * as option from '../nullable/module.f.mjs'
|
|
3
3
|
const { map } = option
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -86,22 +86,22 @@ const uncheckTail = a => a.slice(1)
|
|
|
86
86
|
const uncheckHead = a => a.slice(0, -1)
|
|
87
87
|
|
|
88
88
|
/** @type {(index: number) => <T>(a: readonly T[]) => T|null} */
|
|
89
|
-
const at = i => a => {
|
|
89
|
+
export const at = i => a => {
|
|
90
90
|
const r = a[i]
|
|
91
91
|
return r === void 0 ? null : r
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
95
|
-
const first = at(0)
|
|
95
|
+
export const first = at(0)
|
|
96
96
|
|
|
97
97
|
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
98
|
-
const last = a => at(a.length - 1)(a)
|
|
98
|
+
export const last = a => at(a.length - 1)(a)
|
|
99
99
|
|
|
100
100
|
/** @type {<T>(_: readonly T[]) => readonly T[] | null} */
|
|
101
|
-
const tail = a => a.length === 0 ? null : uncheckTail(a)
|
|
101
|
+
export const tail = a => a.length === 0 ? null : uncheckTail(a)
|
|
102
102
|
|
|
103
103
|
/** @type {<T>(_: readonly T[]) => readonly[T, readonly T[]]|null} */
|
|
104
|
-
const splitFirst = a => {
|
|
104
|
+
export const splitFirst = a => {
|
|
105
105
|
/** @typedef {typeof a[0]} T*/
|
|
106
106
|
/** @type {(_: T) => readonly[T, readonly T[]]} */
|
|
107
107
|
const split = first => [first, uncheckTail(a)]
|
|
@@ -109,28 +109,11 @@ const splitFirst = a => {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/** @type {<T>(_: readonly T[]) => readonly T[]|null} */
|
|
112
|
-
const head = a => a.length === 0 ? null : uncheckHead(a)
|
|
112
|
+
export const head = a => a.length === 0 ? null : uncheckHead(a)
|
|
113
113
|
|
|
114
114
|
/** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|null} */
|
|
115
|
-
const splitLast = a => {
|
|
115
|
+
export const splitLast = a => {
|
|
116
116
|
const lastA = last(a)
|
|
117
117
|
if (lastA === null) { return null }
|
|
118
118
|
return [uncheckHead(a), lastA]
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
export default {
|
|
122
|
-
/** @readonly */
|
|
123
|
-
at,
|
|
124
|
-
/** @readnly */
|
|
125
|
-
first,
|
|
126
|
-
/** @readonly */
|
|
127
|
-
last,
|
|
128
|
-
/** @readonly */
|
|
129
|
-
head,
|
|
130
|
-
/** @readonly */
|
|
131
|
-
tail,
|
|
132
|
-
/** @readonly */
|
|
133
|
-
splitFirst,
|
|
134
|
-
/** @readonly */
|
|
135
|
-
splitLast,
|
|
136
|
-
}
|
package/types/array/test.f.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import _ from './module.f.mjs'
|
|
2
|
-
import json from '../../json/module.f.mjs'
|
|
3
|
-
import o from '../object/module.f.mjs'
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
|
+
import * as json from '../../json/module.f.mjs'
|
|
3
|
+
import * as o from '../object/module.f.mjs'
|
|
4
4
|
const { sort } = o
|
|
5
5
|
|
|
6
6
|
const stringify = json.stringify(sort)
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default _default;
|
|
1
|
+
/** @type {(b: BigFloat) => (mul: bigint) => BigFloat} */
|
|
2
|
+
export const multiply: (b: BigFloat) => (mul: bigint) => BigFloat;
|
|
3
|
+
/** @type {(dec: BigFloat) => BigFloat} */
|
|
4
|
+
export const decToBin: (dec: BigFloat) => BigFloat;
|
|
6
5
|
export type BigFloat = readonly [bigint, number];
|
|
7
6
|
export type BigFloatWithRemainder = readonly [BigFloat, bigint];
|
|
8
|
-
/** @type {(dec: BigFloat) => BigFloat} */
|
|
9
|
-
declare const decToBin: (dec: BigFloat) => BigFloat;
|
|
10
|
-
/** @type {(b: BigFloat) => (mul: bigint) => BigFloat} */
|
|
11
|
-
declare const multiply: (b: BigFloat) => (mul: bigint) => BigFloat;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import bi from '../bigint/module.f.mjs'
|
|
2
|
+
import * as bi from '../bigint/module.f.mjs'
|
|
3
3
|
const { abs, sign } = bi
|
|
4
4
|
|
|
5
5
|
/** @typedef {readonly[bigint,number]} BigFloat */
|
|
@@ -47,7 +47,7 @@ const pow = base => exp => base ** BigInt(exp)
|
|
|
47
47
|
const pow5 = pow(5n)
|
|
48
48
|
|
|
49
49
|
/** @type {(b: BigFloat) => (mul: bigint) => BigFloat} */
|
|
50
|
-
const multiply = ([m, e]) => mul => [m * mul, e]
|
|
50
|
+
export const multiply = ([m, e]) => mul => [m * mul, e]
|
|
51
51
|
|
|
52
52
|
/** @type {(b: BigFloat) => (div: bigint) => BigFloatWithRemainder} */
|
|
53
53
|
const divide = ([m, e]) => div => [[m / div, e], m % div]
|
|
@@ -68,7 +68,7 @@ const round53 = ([[m, e], r]) => {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/** @type {(dec: BigFloat) => BigFloat} */
|
|
71
|
-
const decToBin = dec => {
|
|
71
|
+
export const decToBin = dec => {
|
|
72
72
|
if (dec[0] === 0n) {
|
|
73
73
|
return [0n, 0]
|
|
74
74
|
}
|
|
@@ -86,10 +86,3 @@ const decToBin = dec => {
|
|
|
86
86
|
const r53 = round53(qr)
|
|
87
87
|
return multiply(r53)(s)
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
export default {
|
|
91
|
-
/** @readonly */
|
|
92
|
-
decToBin,
|
|
93
|
-
/** @readonly */
|
|
94
|
-
multiply
|
|
95
|
-
}
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { addition };
|
|
3
|
-
export { sum };
|
|
4
|
-
export { abs };
|
|
5
|
-
export { sign };
|
|
6
|
-
export { serialize };
|
|
7
|
-
export { scalar_mul };
|
|
8
|
-
export { log2 };
|
|
9
|
-
export { bitLength };
|
|
10
|
-
}
|
|
11
|
-
export default _default;
|
|
12
|
-
export type Unary = Operator.Unary<bigint, bigint>;
|
|
13
|
-
export type Additive<T> = {
|
|
14
|
-
readonly 0: T;
|
|
15
|
-
readonly add: Operator.Reduce<T>;
|
|
16
|
-
};
|
|
17
1
|
/** @typedef {Operator.Unary<bigint, bigint>} Unary*/
|
|
18
2
|
/** @type {(a: bigint) => (b: bigint) => bigint} */
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
export const addition: (a: bigint) => (b: bigint) => bigint;
|
|
4
|
+
export const sum: (input: list.List<bigint>) => bigint;
|
|
21
5
|
/** @type {(a: bigint) => bigint} */
|
|
22
|
-
|
|
23
|
-
/** @type {(a: bigint) =>
|
|
24
|
-
|
|
6
|
+
export const abs: (a: bigint) => bigint;
|
|
7
|
+
/** @type {(a: bigint) => compare.Sign} */
|
|
8
|
+
export const sign: (a: bigint) => compare.Sign;
|
|
25
9
|
/** @type {(a: bigint) => string} */
|
|
26
|
-
|
|
10
|
+
export const serialize: (a: bigint) => string;
|
|
27
11
|
/**
|
|
28
12
|
* @template T
|
|
29
13
|
* @typedef {{
|
|
@@ -32,46 +16,14 @@ declare const serialize: (a: bigint) => string;
|
|
|
32
16
|
* }} Additive
|
|
33
17
|
*/
|
|
34
18
|
/** @type {<T>(a: Additive<T>) => (a: T) => (n: bigint) => T} */
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @returns {bigint} The base-2 logarithm (floor) of the input BigInt, or `-1n` if the input is less than or equal to 0.
|
|
46
|
-
*
|
|
47
|
-
* @remarks
|
|
48
|
-
* The function operates in two phases:
|
|
49
|
-
* 1. **Fast Doubling Phase:** Uses exponential steps to quickly narrow down the range
|
|
50
|
-
* of the most significant bit.
|
|
51
|
-
* 2. **Binary Search Phase:** Refines the result by halving the step size and incrementally
|
|
52
|
-
* determining the exact value of the logarithm.
|
|
53
|
-
*/
|
|
54
|
-
declare function log2(v: bigint): bigint;
|
|
55
|
-
/**
|
|
56
|
-
* Calculates the bit length of a given BigInt.
|
|
57
|
-
*
|
|
58
|
-
* The bit length of a number is the number of bits required to represent its absolute value in binary,
|
|
59
|
-
* excluding leading zeros. For example:
|
|
60
|
-
* - `0n` has a bit length of 0 (it has no bits).
|
|
61
|
-
* - `1n` (binary `1`) has a bit length of 1.
|
|
62
|
-
* - `255n` (binary `11111111`) has a bit length of 8.
|
|
63
|
-
* - `-255n` (absolute value `255`, binary `11111111`) also has a bit length of 8.
|
|
64
|
-
*
|
|
65
|
-
* The function handles both positive and negative numbers. For negative inputs, the bit length is calculated
|
|
66
|
-
* based on the absolute value of the number. Zero has a bit length of 0.
|
|
67
|
-
*
|
|
68
|
-
* @param {bigint} v - The input BigInt.
|
|
69
|
-
* @returns {bigint} The bit length of the input BigInt.
|
|
70
|
-
*
|
|
71
|
-
* @remark
|
|
72
|
-
* The function uses the `log2` function to calculate the position of the most significant bit(MSB)
|
|
73
|
-
* and adds `1n` to account for the MSB itself.For negative numbers, the absolute value is used.
|
|
74
|
-
*/
|
|
75
|
-
declare function bitLength(v: bigint): bigint;
|
|
19
|
+
export const scalar_mul: <T>(a: Additive<T>) => (a: T) => (n: bigint) => T;
|
|
20
|
+
export function log2(v: bigint): bigint;
|
|
21
|
+
export function bitLength(v: bigint): bigint;
|
|
22
|
+
export type Unary = Operator.Unary<bigint, bigint>;
|
|
23
|
+
export type Additive<T> = {
|
|
24
|
+
readonly 0: T;
|
|
25
|
+
readonly add: Operator.Reduce<T>;
|
|
26
|
+
};
|
|
27
|
+
import * as list from '../list/module.f.mjs';
|
|
28
|
+
import * as compare from '../function/compare/module.f.mjs';
|
|
76
29
|
import * as Operator from '../function/operator/module.f.mjs';
|
|
77
|
-
import * as Compare from '../function/compare/module.f.mjs';
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import
|
|
2
|
+
import * as compare from '../function/compare/module.f.mjs'
|
|
3
3
|
import * as Operator from '../function/operator/module.f.mjs'
|
|
4
4
|
const { unsafeCmp } = compare
|
|
5
|
-
import list from '../list/module.f.mjs'
|
|
5
|
+
import * as list from '../list/module.f.mjs'
|
|
6
6
|
const { reduce } = list
|
|
7
7
|
|
|
8
8
|
/** @typedef {Operator.Unary<bigint, bigint>} Unary*/
|
|
9
9
|
|
|
10
10
|
/** @type {(a: bigint) => (b: bigint) => bigint} */
|
|
11
|
-
const addition = a => b => a + b
|
|
11
|
+
export const addition = a => b => a + b
|
|
12
12
|
|
|
13
|
-
const sum = reduce(addition)(0n)
|
|
13
|
+
export const sum = reduce(addition)(0n)
|
|
14
14
|
|
|
15
15
|
/** @type {(a: bigint) => bigint} */
|
|
16
|
-
const abs = a => a >= 0 ? a : -a
|
|
16
|
+
export const abs = a => a >= 0 ? a : -a
|
|
17
17
|
|
|
18
|
-
/** @type {(a: bigint) =>
|
|
19
|
-
const sign = a => unsafeCmp(a)(0n)
|
|
18
|
+
/** @type {(a: bigint) => compare.Sign} */
|
|
19
|
+
export const sign = a => unsafeCmp(a)(0n)
|
|
20
20
|
|
|
21
21
|
/** @type {(a: bigint) => string} */
|
|
22
|
-
const serialize = a => `${a}n`
|
|
22
|
+
export const serialize = a => `${a}n`
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @template T
|
|
@@ -30,7 +30,7 @@ const serialize = a => `${a}n`
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
/** @type {<T>(a: Additive<T>) => (a: T) => (n: bigint) => T} */
|
|
33
|
-
const scalar_mul = ({ 0: _0, add }) => a => n => {
|
|
33
|
+
export const scalar_mul = ({ 0: _0, add }) => a => n => {
|
|
34
34
|
let ai = a
|
|
35
35
|
let ni = n
|
|
36
36
|
let result = _0
|
|
@@ -64,7 +64,7 @@ const scalar_mul = ({ 0: _0, add }) => a => n => {
|
|
|
64
64
|
* 2. **Binary Search Phase:** Refines the result by halving the step size and incrementally
|
|
65
65
|
* determining the exact value of the logarithm.
|
|
66
66
|
*/
|
|
67
|
-
const log2 = v => {
|
|
67
|
+
export const log2 = v => {
|
|
68
68
|
if (v <= 0n) { return -1n }
|
|
69
69
|
let result = 0n
|
|
70
70
|
let i = 1n
|
|
@@ -111,29 +111,10 @@ const log2 = v => {
|
|
|
111
111
|
* The function uses the `log2` function to calculate the position of the most significant bit(MSB)
|
|
112
112
|
* and adds `1n` to account for the MSB itself.For negative numbers, the absolute value is used.
|
|
113
113
|
*/
|
|
114
|
-
const bitLength = v => {
|
|
114
|
+
export const bitLength = v => {
|
|
115
115
|
if (v <= 0n) {
|
|
116
116
|
if (v === 0n) { return 0n }
|
|
117
117
|
v = -v
|
|
118
118
|
}
|
|
119
119
|
return log2(v) + 1n
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
export default {
|
|
123
|
-
/** @readonly */
|
|
124
|
-
addition,
|
|
125
|
-
/** @readonly */
|
|
126
|
-
sum,
|
|
127
|
-
/** @readonly */
|
|
128
|
-
abs,
|
|
129
|
-
/** @readonly */
|
|
130
|
-
sign,
|
|
131
|
-
/** @readonly */
|
|
132
|
-
serialize,
|
|
133
|
-
/** @readonly */
|
|
134
|
-
scalar_mul,
|
|
135
|
-
/** @readonly */
|
|
136
|
-
log2,
|
|
137
|
-
/** @readonly */
|
|
138
|
-
bitLength,
|
|
139
|
-
}
|
package/types/bigint/test.f.mjs
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @typedef {List.List<PathItem<T>>} Path
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @template T
|
|
7
|
+
* @typedef {{
|
|
8
|
+
* readonly first: First<T>,
|
|
9
|
+
* readonly tail: Path<T>
|
|
10
|
+
* }} Result<T>
|
|
11
|
+
*/
|
|
12
|
+
/** @type {<T>(c: cmp.Compare<T>) => (node: _.Node<T>) => Result<T>} */
|
|
13
|
+
export const find: <T>(c: cmp.Compare<T>) => (node: _.Node<T>) => Result<T>;
|
|
14
|
+
/** @type {<T>(first: First<T>) => boolean} */
|
|
15
|
+
export const isFound: <T>(first: First<T>) => boolean;
|
|
16
|
+
/** @type {<T>(first: First<T>) => T | null} */
|
|
17
|
+
export const value: <T>(first: First<T>) => T | null;
|
|
18
|
+
export type FirstLeaf1<T> = readonly [cmp.Index3, _.Leaf1<T>];
|
|
8
19
|
export type FirstBranch3<T> = readonly [1, _.Branch3<T>];
|
|
9
|
-
export type FirstLeaf2<T> = readonly [
|
|
20
|
+
export type FirstLeaf2<T> = readonly [cmp.Index5, _.Leaf2<T>];
|
|
10
21
|
export type FirstBranch5<T> = readonly [1 | 3, _.Branch5<T>];
|
|
11
22
|
export type First<T> = FirstLeaf1<T> | FirstBranch3<T> | FirstLeaf2<T> | FirstBranch5<T>;
|
|
12
23
|
export type PathItem3<T> = readonly [0 | 2, _.Branch3<T>];
|
|
@@ -20,23 +31,6 @@ export type Result<T> = {
|
|
|
20
31
|
readonly first: First<T>;
|
|
21
32
|
readonly tail: Path<T>;
|
|
22
33
|
};
|
|
23
|
-
|
|
24
|
-
* @template T
|
|
25
|
-
* @typedef {List.List<PathItem<T>>} Path
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* @template T
|
|
29
|
-
* @typedef {{
|
|
30
|
-
* readonly first: First<T>,
|
|
31
|
-
* readonly tail: Path<T>
|
|
32
|
-
* }} Result<T>
|
|
33
|
-
*/
|
|
34
|
-
/** @type {<T>(c: cmpT.Compare<T>) => (node: _.Node<T>) => Result<T>} */
|
|
35
|
-
declare const find: <T>(c: cmpT.Compare<T>) => (node: _.Node<T>) => Result<T>;
|
|
36
|
-
/** @type {<T>(first: First<T>) => T | null} */
|
|
37
|
-
declare const value: <T>(first: First<T>) => T | null;
|
|
38
|
-
/** @type {<T>(first: First<T>) => boolean} */
|
|
39
|
-
declare const isFound: <T>(first: First<T>) => boolean;
|
|
40
|
-
import * as cmpT from '../../function/compare/module.f.mjs';
|
|
34
|
+
import * as cmp from '../../function/compare/module.f.mjs';
|
|
41
35
|
import * as _ from '../types/module.f.mjs';
|
|
42
36
|
import * as List from '../../list/module.f.mjs';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
import * as _ from '../types/module.f.mjs'
|
|
3
3
|
import * as List from '../../list/module.f.mjs'
|
|
4
|
-
import
|
|
4
|
+
import * as cmp from '../../function/compare/module.f.mjs'
|
|
5
5
|
const { index3, index5 } = cmp
|
|
6
6
|
import * as Array from '../../array/module.f.mjs'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @template T
|
|
10
|
-
* @typedef {readonly[
|
|
10
|
+
* @typedef {readonly[cmp.Index3, _.Leaf1<T>]} FirstLeaf1
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -17,7 +17,7 @@ import * as Array from '../../array/module.f.mjs'
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @template T
|
|
20
|
-
* @typedef {readonly[
|
|
20
|
+
* @typedef {readonly[cmp.Index5, _.Leaf2<T>]} FirstLeaf2
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -62,11 +62,11 @@ const child = item =>
|
|
|
62
62
|
* }} Result<T>
|
|
63
63
|
*/
|
|
64
64
|
|
|
65
|
-
/** @type {<T>(c:
|
|
66
|
-
const find = c => {
|
|
65
|
+
/** @type {<T>(c: cmp.Compare<T>) => (node: _.Node<T>) => Result<T>} */
|
|
66
|
+
export const find = c => {
|
|
67
67
|
const i3 = index3(c)
|
|
68
68
|
const i5 = index5(c)
|
|
69
|
-
/** @typedef {typeof c extends
|
|
69
|
+
/** @typedef {typeof c extends cmp.Compare<infer T> ? T : never} T */
|
|
70
70
|
/** @type {(prior: Path<T>) => (node: _.Node<T>) => Result<T>} */
|
|
71
71
|
const f = tail => node => {
|
|
72
72
|
/** @type {(index: Array.KeyOf<typeof node>) => Result<T>} */
|
|
@@ -99,7 +99,7 @@ const find = c => {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/** @type {<T>(first: First<T>) => boolean} */
|
|
102
|
-
const isFound = ([i]) => {
|
|
102
|
+
export const isFound = ([i]) => {
|
|
103
103
|
switch (i) {
|
|
104
104
|
case 1: case 3: { return true }
|
|
105
105
|
default: { return false }
|
|
@@ -107,7 +107,7 @@ const isFound = ([i]) => {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/** @type {<T>(first: First<T>) => T | null} */
|
|
110
|
-
const value = ([i, r]) => {
|
|
110
|
+
export const value = ([i, r]) => {
|
|
111
111
|
switch (i) {
|
|
112
112
|
case 1: {
|
|
113
113
|
switch (r.length) {
|
|
@@ -123,12 +123,3 @@ const value = ([i, r]) => {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
export default {
|
|
128
|
-
/** @readonly */
|
|
129
|
-
find,
|
|
130
|
-
/** @readonly */
|
|
131
|
-
value,
|
|
132
|
-
/** @readonly */
|
|
133
|
-
isFound,
|
|
134
|
-
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import list from '../../list/module.f.mjs'
|
|
3
|
-
import
|
|
4
|
-
import o from '../../object/module.f.mjs'
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
|
+
import * as list from '../../list/module.f.mjs'
|
|
3
|
+
import * as json from '../../../json/module.f.mjs'
|
|
4
|
+
import * as o from '../../object/module.f.mjs'
|
|
5
5
|
const { sort } = o
|
|
6
6
|
import * as btree from '../types/module.f.mjs'
|
|
7
|
-
import string from '../../string/module.f.mjs'
|
|
7
|
+
import * as string from '../../string/module.f.mjs'
|
|
8
8
|
const { cmp } = string
|
|
9
|
-
import s from '../set/module.f.mjs'
|
|
9
|
+
import * as s from '../set/module.f.mjs'
|
|
10
10
|
|
|
11
11
|
const jsonStr = json.stringify(sort)
|
|
12
12
|
|
|
13
13
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
14
14
|
const set = node => value => s.set(cmp(value))(() => value)(node)
|
|
15
15
|
|
|
16
|
-
/** @type {(r:
|
|
16
|
+
/** @type {(r: _.Result<json.Unknown>) => string} */
|
|
17
17
|
const str = r => jsonStr(list.toArray(list.map(x => x[0])(r)))
|
|
18
18
|
|
|
19
19
|
/** @type {(i: string) => (m: btree.Node<string>) => string} */
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export default _default;
|
|
6
|
-
/** @type {<T>(tree: _.Tree<T>) => List.List<T>} */
|
|
7
|
-
declare const values: <T>(tree: _.Tree<T>) => List.List<T>;
|
|
1
|
+
export const empty: null;
|
|
2
|
+
/** @type {<T>(tree: _.Tree<T>) => list.List<T>} */
|
|
3
|
+
export const values: <T>(tree: _.Tree<T>) => list.List<T>;
|
|
8
4
|
import * as _ from './types/module.f.mjs';
|
|
9
|
-
import * as
|
|
5
|
+
import * as list from '../list/module.f.mjs';
|
package/types/btree/module.f.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import * as list from '../list/module.f.mjs'
|
|
4
4
|
const { flat } = list
|
|
5
|
-
import n from '../nullable/module.f.mjs'
|
|
5
|
+
import * as n from '../nullable/module.f.mjs'
|
|
6
6
|
const { map } = n
|
|
7
7
|
import * as _ from './types/module.f.mjs'
|
|
8
8
|
|
|
9
|
-
/** @type {<T>(node: _.Node<T>) =>
|
|
9
|
+
/** @type {<T>(node: _.Node<T>) => list.Thunk<T>} */
|
|
10
10
|
const nodeValues = node => () => {
|
|
11
11
|
switch (node.length) {
|
|
12
12
|
case 1: case 2: { return node }
|
|
@@ -29,12 +29,7 @@ const nodeValues = node => () => {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
const values = map(nodeValues)
|
|
32
|
+
export const empty = null
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
empty: null,
|
|
38
|
-
/** @readonly */
|
|
39
|
-
values,
|
|
40
|
-
}
|
|
34
|
+
/** @type {<T>(tree: _.Tree<T>) => list.List<T>} */
|
|
35
|
+
export const values = map(nodeValues)
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default _default;
|
|
1
|
+
/** @type {<T>(c: Cmp.Compare<T>) => (node: _.Node<T>) => _.Tree<T>} */
|
|
2
|
+
export const nodeRemove: <T>(c: Cmp.Compare<T>) => (node: _.Node<T>) => _.Tree<T>;
|
|
3
|
+
/** @type {<T>(c: Cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>} */
|
|
4
|
+
export const remove: <T>(c: Cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>;
|
|
6
5
|
export type Leaf01<T> = null | _.Leaf1<T>;
|
|
7
6
|
export type RemovePath<T> = {
|
|
8
7
|
readonly first: Leaf01<T>;
|
|
9
|
-
readonly tail:
|
|
8
|
+
readonly tail: find.Path<T>;
|
|
10
9
|
};
|
|
11
10
|
export type Branch<T> = _.Branch1<T> | _.Branch3<T> | _.Branch5<T>;
|
|
12
11
|
export type Merge<A, T> = (a: A) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>;
|
|
13
|
-
/** @type {<T>(c: Cmp.Compare<T>) => (node: _.Node<T>) => _.Tree<T>} */
|
|
14
|
-
declare const nodeRemove: <T>(c: Cmp.Compare<T>) => (node: _.Node<T>) => _.Tree<T>;
|
|
15
|
-
/** @type {<T>(c: Cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>} */
|
|
16
|
-
declare const remove: <T>(c: Cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>;
|
|
17
|
-
import * as _ from '../types/module.f.mjs';
|
|
18
|
-
import * as Find from '../find/module.f.mjs';
|
|
19
12
|
import * as Cmp from '../../function/compare/module.f.mjs';
|
|
13
|
+
import * as _ from '../types/module.f.mjs';
|
|
14
|
+
import * as find from '../find/module.f.mjs';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
import * as _ from '../types/module.f.mjs'
|
|
3
3
|
import * as Cmp from '../../function/compare/module.f.mjs'
|
|
4
|
-
import
|
|
5
|
-
import list from '../../list/module.f.mjs'
|
|
4
|
+
import * as find from '../find/module.f.mjs'
|
|
5
|
+
import * as list from '../../list/module.f.mjs'
|
|
6
6
|
const { fold, concat, next } = list
|
|
7
7
|
import * as Array from '../../array/module.f.mjs'
|
|
8
|
-
import n from '../../nullable/module.f.mjs'
|
|
8
|
+
import * as n from '../../nullable/module.f.mjs'
|
|
9
9
|
const { map } = n
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -17,11 +17,11 @@ const { map } = n
|
|
|
17
17
|
* @template T
|
|
18
18
|
* @typedef {{
|
|
19
19
|
* readonly first: Leaf01<T>,
|
|
20
|
-
* readonly tail:
|
|
20
|
+
* readonly tail: find.Path<T>
|
|
21
21
|
* }} RemovePath
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
/** @type {<T>(tail:
|
|
24
|
+
/** @type {<T>(tail: find.Path<T>) => (n: _.Node<T>) => readonly[T, RemovePath<T>]} */
|
|
25
25
|
const path = tail => n => {
|
|
26
26
|
switch (n.length) {
|
|
27
27
|
case 1: { return [n[0], { first: null, tail }] }
|
|
@@ -95,7 +95,7 @@ const initValue1 = a => n => {
|
|
|
95
95
|
* @typedef {(a: A) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} Merge
|
|
96
96
|
*/
|
|
97
97
|
|
|
98
|
-
/** @type {<A, T>(ms: Array.Array2<Merge<A, T>>) => (i:
|
|
98
|
+
/** @type {<A, T>(ms: Array.Array2<Merge<A, T>>) => (i: find.PathItem<T>) => (a: A) => Branch<T>} */
|
|
99
99
|
const reduceX = ms => ([i, n]) => a => {
|
|
100
100
|
const [m0, m2] = ms
|
|
101
101
|
/** @typedef {typeof ms extends Array.Array2<Merge<infer A, infer T>> ? [A,T] : never} AT */
|
|
@@ -118,14 +118,14 @@ const reduce = fold(reduceX([reduceValue0, reduceValue2]))
|
|
|
118
118
|
const initReduce = reduceX([initValue0, initValue1])
|
|
119
119
|
|
|
120
120
|
/** @type {<T>(c: Cmp.Compare<T>) => (node: _.Node<T>) => _.Tree<T>} */
|
|
121
|
-
const nodeRemove = c => node => {
|
|
121
|
+
export const nodeRemove = c => node => {
|
|
122
122
|
/** @typedef {typeof c extends Cmp.Compare<infer T> ? T : never} T */
|
|
123
123
|
/** @type {() => null | RemovePath<T>} */
|
|
124
124
|
const f = () => {
|
|
125
125
|
const { first, tail } = find.find(c)(node)
|
|
126
|
-
/** @type {(n: _.Node<T>) => (f: (v: T) =>
|
|
126
|
+
/** @type {(n: _.Node<T>) => (f: (v: T) => find.PathItem<T>) => RemovePath<T>} */
|
|
127
127
|
const branch = n => f => {
|
|
128
|
-
const [v, p] = path(/** @type {
|
|
128
|
+
const [v, p] = path(/** @type {find.Path<T>} */(null))(n)
|
|
129
129
|
return { first: p.first, tail: concat(p.tail)({ first: f(v), tail }) }
|
|
130
130
|
}
|
|
131
131
|
const [i, n] = first
|
|
@@ -158,11 +158,4 @@ const nodeRemove = c => node => {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/** @type {<T>(c: Cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>} */
|
|
161
|
-
const remove = c => map(nodeRemove(c))
|
|
162
|
-
|
|
163
|
-
export default {
|
|
164
|
-
/** @readonly */
|
|
165
|
-
nodeRemove,
|
|
166
|
-
/** @readonly */
|
|
167
|
-
remove,
|
|
168
|
-
}
|
|
161
|
+
export const remove = c => map(nodeRemove(c))
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import _ from './module.f.mjs'
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
2
|
import * as BTree from '../types/module.f.mjs'
|
|
3
|
-
import s from '../set/module.f.mjs'
|
|
4
|
-
import str from '../../string/module.f.mjs'
|
|
3
|
+
import * as s from '../set/module.f.mjs'
|
|
4
|
+
import * as str from '../../string/module.f.mjs'
|
|
5
5
|
const { cmp } = str
|
|
6
|
-
import json from '../../../json/module.f.mjs'
|
|
7
|
-
import o from '../../object/module.f.mjs'
|
|
6
|
+
import * as json from '../../../json/module.f.mjs'
|
|
7
|
+
import * as o from '../../object/module.f.mjs'
|
|
8
8
|
const { sort } = o
|
|
9
9
|
|
|
10
10
|
/** @type {(node: BTree.Node<string>) => (value: string) => BTree.Node<string>} */
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { set };
|
|
3
|
-
}
|
|
4
|
-
export default _default;
|
|
5
|
-
export type Branch1To3<T> = _.Branch1<T> | _.Branch3<T>;
|
|
6
1
|
/** @type {<T>(c: Cmp.Compare<T>) => (f: (value: T|null) => T) => (tree: _.Tree<T>) => _.Node<T>} */
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export const set: <T>(c: Cmp.Compare<T>) => (f: (value: T | null) => T) => (tree: _.Tree<T>) => _.Node<T>;
|
|
3
|
+
export type Branch1To3<T> = _.Branch1<T> | _.Branch3<T>;
|
|
9
4
|
import * as Cmp from '../../function/compare/module.f.mjs';
|
|
5
|
+
import * as _ from '../types/module.f.mjs';
|