functionalscript 0.1.609 → 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/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/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/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/test/module.f.d.mts +2 -3
- package/dev/test/module.f.mjs +4 -6
- package/djs/module.f.d.mts +13 -18
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.d.mts +11 -15
- package/djs/parser/module.f.mjs +18 -24
- package/djs/parser/test.f.mjs +9 -9
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.d.mts +6 -10
- package/djs/tokenizer/module.f.mjs +18 -23
- package/djs/tokenizer/test.f.mjs +6 -6
- package/fsc/module.f.d.mts +4 -9
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/module.f.d.mts +13 -20
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/module.f.d.mts +7 -12
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/js/tokenizer/module.f.d.mts +10 -15
- package/js/tokenizer/module.f.mjs +55 -62
- package/js/tokenizer/test.f.mjs +6 -6
- 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 +14 -19
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +1 -1
- 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/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/text/utf16/test.f.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import encoding from './module.f.mjs'
|
|
2
|
-
import
|
|
3
|
-
import o from '../../types/object/module.f.mjs'
|
|
1
|
+
import * as encoding from './module.f.mjs'
|
|
2
|
+
import * as json from '../../json/module.f.mjs'
|
|
3
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
4
4
|
const { sort } = o
|
|
5
|
-
import list from '../../types/list/module.f.mjs'
|
|
5
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
6
6
|
|
|
7
|
-
/** @type {(a: readonly
|
|
7
|
+
/** @type {(a: readonly json.Unknown[]) => string} */
|
|
8
8
|
const stringify = a => json.stringify(sort)(a)
|
|
9
9
|
|
|
10
10
|
export default {
|
package/text/utf8/module.f.d.mts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export default _default;
|
|
1
|
+
export const fromCodePointList: (input: list.List<number>) => list.Thunk<number>;
|
|
2
|
+
/** @type {(input: list.List<u8>) => list.List<i32>} */
|
|
3
|
+
export const toCodePointList: (input: list.List<u8>) => list.List<i32>;
|
|
6
4
|
export type ByteOrEof = u8 | null;
|
|
7
5
|
export type Utf8NonEmptyState = Array.Array1<number> | Array.Array2<number> | Array.Array3<number>;
|
|
8
6
|
export type Utf8State = null | Utf8NonEmptyState;
|
|
9
7
|
export type u8 = number;
|
|
10
8
|
export type i32 = number;
|
|
11
|
-
|
|
12
|
-
/** @type {(input: List.List<u8>) => List.List<i32>} */
|
|
13
|
-
declare const toCodePointList: (input: List.List<u8>) => List.List<i32>;
|
|
9
|
+
import * as list from '../../types/list/module.f.mjs';
|
|
14
10
|
import * as Array from '../../types/array/module.f.mjs';
|
|
15
|
-
import * as List from '../../types/list/module.f.mjs';
|
package/text/utf8/module.f.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
|
-
import
|
|
2
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
3
3
|
import * as operator from '../../types/function/operator/module.f.mjs'
|
|
4
4
|
import * as Array from '../../types/array/module.f.mjs'
|
|
5
5
|
const { flatMap, flat, stateScan } = list
|
|
@@ -16,7 +16,7 @@ const { flatMap, flat, stateScan } = list
|
|
|
16
16
|
|
|
17
17
|
const errorMask = 0b1000_0000_0000_0000_0000_0000_0000_0000
|
|
18
18
|
|
|
19
|
-
/** @type {(input:number) =>
|
|
19
|
+
/** @type {(input:number) => list.List<u8>} */
|
|
20
20
|
const codePointToUtf8 = input => {
|
|
21
21
|
if (input >= 0x0000 && input <= 0x007f) { return [input & 0b01111_1111] }
|
|
22
22
|
if (input >= 0x0080 && input <= 0x07ff) { return [input >> 6 | 0b1100_0000, input & 0b0011_1111 | 0b1000_0000] }
|
|
@@ -31,7 +31,7 @@ const codePointToUtf8 = input => {
|
|
|
31
31
|
return [errorMask]
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const fromCodePointList = flatMap(codePointToUtf8)
|
|
34
|
+
export const fromCodePointList = flatMap(codePointToUtf8)
|
|
35
35
|
|
|
36
36
|
/** @type {(state: Utf8NonEmptyState) => i32}*/
|
|
37
37
|
const utf8StateToError = state => {
|
|
@@ -59,7 +59,7 @@ const utf8StateToError = state => {
|
|
|
59
59
|
return x | errorMask
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/** @type {operator.StateScan<number, Utf8State,
|
|
62
|
+
/** @type {operator.StateScan<number, Utf8State, list.List<i32>>} */
|
|
63
63
|
const utf8ByteToCodePointOp = state => byte => {
|
|
64
64
|
if (byte < 0x00 || byte > 0xff) {
|
|
65
65
|
return [[errorMask], state]
|
|
@@ -95,22 +95,15 @@ const utf8ByteToCodePointOp = state => byte => {
|
|
|
95
95
|
return [[error, byte | errorMask], null]
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
/** @type {(state: Utf8State) => readonly[
|
|
98
|
+
/** @type {(state: Utf8State) => readonly[list.List<i32>, Utf8State]} */
|
|
99
99
|
const utf8EofToCodePointOp = state =>
|
|
100
100
|
[state === null ? null : [utf8StateToError(state)], null]
|
|
101
101
|
|
|
102
|
-
/** @type {operator.StateScan<ByteOrEof, Utf8State,
|
|
102
|
+
/** @type {operator.StateScan<ByteOrEof, Utf8State, list.List<i32>>} */
|
|
103
103
|
const utf8ByteOrEofToCodePointOp = state => input => input === null ? utf8EofToCodePointOp(state) : utf8ByteToCodePointOp(state)(input)
|
|
104
104
|
|
|
105
|
-
/** @type {
|
|
105
|
+
/** @type {list.List<ByteOrEof>} */
|
|
106
106
|
const eofList = [null]
|
|
107
107
|
|
|
108
|
-
/** @type {(input:
|
|
109
|
-
const toCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(null)(flat([input, eofList])))
|
|
110
|
-
|
|
111
|
-
export default {
|
|
112
|
-
/** @readonly */
|
|
113
|
-
fromCodePointList,
|
|
114
|
-
/** @readonly */
|
|
115
|
-
toCodePointList
|
|
116
|
-
}
|
|
108
|
+
/** @type {(input: list.List<u8>) => list.List<i32>} */
|
|
109
|
+
export const toCodePointList = input => flat(stateScan(utf8ByteOrEofToCodePointOp)(null)(flat([input, eofList])))
|
package/text/utf8/test.f.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import encoding from './module.f.mjs'
|
|
2
|
-
import json from '../../json/module.f.mjs'
|
|
3
|
-
import o from '../../types/object/module.f.mjs'
|
|
1
|
+
import * as encoding from './module.f.mjs'
|
|
2
|
+
import * as json from '../../json/module.f.mjs'
|
|
3
|
+
import * as o from '../../types/object/module.f.mjs'
|
|
4
4
|
const { sort } = o
|
|
5
|
-
import list from '../../types/list/module.f.mjs'
|
|
5
|
+
import * as list from '../../types/list/module.f.mjs'
|
|
6
6
|
|
|
7
7
|
const stringify = json.stringify(sort)
|
|
8
8
|
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
export
|
|
1
|
+
/** @type {(index: number) => <T>(a: readonly T[]) => T|null} */
|
|
2
|
+
export const at: (index: number) => <T>(a: readonly T[]) => T | null;
|
|
3
|
+
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
4
|
+
export const first: <T>(_: readonly T[]) => T | null;
|
|
5
|
+
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
6
|
+
export const last: <T>(_: readonly T[]) => T | null;
|
|
7
|
+
/** @type {<T>(_: readonly T[]) => readonly T[] | null} */
|
|
8
|
+
export const tail: <T>(_: readonly T[]) => readonly T[] | null;
|
|
9
|
+
/** @type {<T>(_: readonly T[]) => readonly[T, readonly T[]]|null} */
|
|
10
|
+
export const splitFirst: <T>(_: readonly T[]) => readonly [T, readonly T[]] | null;
|
|
11
|
+
/** @type {<T>(_: readonly T[]) => readonly T[]|null} */
|
|
12
|
+
export const head: <T>(_: readonly T[]) => readonly T[] | null;
|
|
13
|
+
/** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|null} */
|
|
14
|
+
export const splitLast: <T>(_: readonly T[]) => readonly [readonly T[], T] | null;
|
|
11
15
|
export type Array1<T> = readonly [T];
|
|
12
16
|
export type Index1 = 0;
|
|
13
17
|
export type Array2<T> = readonly [T, T];
|
|
@@ -25,17 +29,3 @@ export type Index16 = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
|
|
|
25
29
|
export type Array1_5<T> = Array1<T> | Array2<T> | Array3<T> | Array4<T> | Array5<T>;
|
|
26
30
|
export type Index5 = 0 | 1 | 2 | 3 | 4;
|
|
27
31
|
export type KeyOf<T> = T extends Array1<infer _> ? Index1 : T extends Array2<infer _> ? Index2 : T extends Array3<infer _> ? Index3 : T extends Array4<infer _> ? Index4 : T extends Array5<infer _> ? Index5 : T extends readonly (infer _)[] ? number : never;
|
|
28
|
-
/** @type {(index: number) => <T>(a: readonly T[]) => T|null} */
|
|
29
|
-
declare const at: (index: number) => <T>(a: readonly T[]) => T | null;
|
|
30
|
-
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
31
|
-
declare const first: <T>(_: readonly T[]) => T | null;
|
|
32
|
-
/** @type {<T>(_: readonly T[]) => T|null} */
|
|
33
|
-
declare const last: <T>(_: readonly T[]) => T | null;
|
|
34
|
-
/** @type {<T>(_: readonly T[]) => readonly T[]|null} */
|
|
35
|
-
declare const head: <T>(_: readonly T[]) => readonly T[] | null;
|
|
36
|
-
/** @type {<T>(_: readonly T[]) => readonly T[] | null} */
|
|
37
|
-
declare const tail: <T>(_: readonly T[]) => readonly T[] | null;
|
|
38
|
-
/** @type {<T>(_: readonly T[]) => readonly[T, readonly T[]]|null} */
|
|
39
|
-
declare const splitFirst: <T>(_: readonly T[]) => readonly [T, readonly T[]] | null;
|
|
40
|
-
/** @type {<T>(_: readonly T[]) => readonly[readonly T[], T]|null} */
|
|
41
|
-
declare const splitLast: <T>(_: readonly T[]) => readonly [readonly T[], T] | null;
|
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';
|