functionalscript 0.3.7 → 0.3.8
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.js +0 -1
- package/com/cs/module.f.js +5 -6
- package/com/rust/module.f.d.ts +3 -3
- package/com/rust/module.f.js +24 -29
- package/com/test/build.f.js +2 -2
- package/com/types/module.f.d.ts +1 -1
- package/com/types/module.f.js +1 -2
- package/com/types/testlib.f.js +0 -1
- package/commonjs/build/module.f.d.ts +2 -2
- package/commonjs/build/module.f.js +3 -6
- package/commonjs/build/test.f.js +0 -4
- package/commonjs/module/function/module.f.d.ts +1 -1
- package/commonjs/module/function/module.f.js +1 -1
- package/commonjs/module/module.f.d.ts +1 -1
- package/commonjs/module/module.f.js +2 -3
- package/commonjs/path/module.f.d.ts +5 -5
- package/commonjs/path/module.f.js +6 -8
- package/commonjs/path/test.f.js +1 -2
- package/crypto/prime_field/module.f.d.ts +1 -1
- package/crypto/prime_field/module.f.js +1 -1
- package/crypto/secp/module.f.d.ts +1 -1
- package/crypto/secp/module.f.js +2 -2
- package/crypto/sha2/module.f.d.ts +75 -12
- package/crypto/sha2/module.f.js +246 -139
- package/crypto/sha2/test.f.d.ts +22 -3
- package/crypto/sha2/test.f.js +120 -67
- package/dev/test/module.f.d.ts +1 -1
- package/dev/test/module.f.js +4 -5
- package/dev/test.f.js +0 -4
- package/djs/module.f.d.ts +1 -1
- package/djs/module.f.js +0 -1
- package/djs/parser/module.f.d.ts +1 -1
- package/djs/parser/module.f.js +0 -2
- package/djs/serializer/module.f.d.ts +2 -2
- package/djs/serializer/module.f.js +0 -2
- package/djs/tokenizer/module.f.js +0 -1
- package/fsc/test.f.js +0 -1
- package/js/tokenizer/module.f.d.ts +1 -1
- package/js/tokenizer/module.f.js +1 -1
- package/json/parser/module.f.d.ts +2 -2
- package/json/parser/module.f.js +0 -3
- package/json/serializer/module.f.js +0 -2
- package/json/tokenizer/module.f.js +0 -1
- package/package.json +1 -1
- package/text/ascii/module.f.d.ts +1 -1
- package/text/ascii/module.f.js +2 -3
- package/text/ascii/test.f.js +2 -4
- package/text/module.f.d.ts +18 -3
- package/text/module.f.js +22 -6
- package/text/sgr/module.f.js +1 -1
- package/text/test.f.d.ts +4 -1
- package/text/test.f.js +24 -16
- package/text/utf16/module.f.d.ts +5 -6
- package/text/utf16/module.f.js +9 -10
- package/text/utf16/test.f.js +29 -30
- package/text/utf8/module.f.d.ts +8 -5
- package/text/utf8/module.f.js +3 -5
- package/text/utf8/test.f.js +34 -35
- package/types/bigfloat/module.f.js +1 -1
- package/types/bigint/module.f.d.ts +17 -5
- package/types/bigint/module.f.js +19 -4
- package/types/bigint/test.f.d.ts +1 -0
- package/types/bigint/test.f.js +7 -2
- package/types/bit_vec/module.f.d.ts +103 -83
- package/types/bit_vec/module.f.js +68 -110
- package/types/bit_vec/test.f.d.ts +20 -8
- package/types/bit_vec/test.f.js +110 -117
- package/types/btree/find/test.f.js +3 -4
- package/types/btree/module.f.d.ts +3 -3
- package/types/btree/module.f.js +2 -5
- package/types/btree/remove/test.f.js +2 -3
- package/types/btree/set/test.f.js +3 -6
- package/types/btree/test.f.js +0 -1
- package/types/btree/types/module.f.d.ts +3 -3
- package/types/byte_set/module.f.d.ts +2 -2
- package/types/byte_set/module.f.js +0 -2
- package/types/function/compare/module.f.d.ts +1 -1
- package/types/function/compare/module.f.js +0 -1
- package/types/function/compare/test.f.js +1 -2
- package/types/function/module.f.d.ts +1 -1
- package/types/function/module.f.js +1 -1
- package/types/function/operator/module.f.d.ts +2 -3
- package/types/function/operator/module.f.js +5 -5
- package/types/function/test.f.js +1 -2
- package/types/list/module.f.d.ts +1 -1
- package/types/list/module.f.js +9 -9
- package/types/list/test.f.js +2 -4
- package/types/map/module.f.d.ts +6 -6
- package/types/map/module.f.js +6 -15
- package/types/map/test.f.js +1 -2
- package/types/nibble_set/module.f.d.ts +2 -3
- package/types/nibble_set/test.f.js +1 -2
- package/types/number/test.f.js +1 -2
- package/types/object/module.f.d.ts +5 -5
- package/types/object/module.f.js +2 -4
- package/types/range_map/module.f.d.ts +4 -4
- package/types/range_map/module.f.js +3 -9
- package/types/result/module.f.d.ts +2 -3
- package/types/sorted_list/module.f.d.ts +6 -6
- package/types/sorted_list/module.f.js +2 -6
- package/types/sorted_list/test.f.js +4 -9
- package/types/sorted_set/module.f.d.ts +1 -1
- package/types/sorted_set/module.f.js +2 -5
- package/types/sorted_set/test.f.js +4 -9
- package/types/string/module.f.d.ts +3 -3
- package/types/string/module.f.js +1 -2
- package/types/string/test.f.js +2 -4
- package/types/string_set/module.f.d.ts +1 -1
- package/types/string_set/module.f.js +5 -11
package/text/utf8/test.f.js
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toCodePointList, fromCodePointList } from "./module.f.js";
|
|
2
2
|
import * as json from "../../json/module.f.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import * as list from "../../types/list/module.f.js";
|
|
3
|
+
import { sort } from "../../types/object/module.f.js";
|
|
4
|
+
import { toArray } from "../../types/list/module.f.js";
|
|
6
5
|
const stringify = json.stringify(sort);
|
|
7
6
|
export default {
|
|
8
7
|
toCodePoint: [
|
|
9
8
|
() => {
|
|
10
|
-
const result = stringify(
|
|
9
|
+
const result = stringify(toArray(toCodePointList([-1, 256])));
|
|
11
10
|
if (result !== '[2147483648,2147483648]') {
|
|
12
11
|
throw result;
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
() => {
|
|
16
|
-
const result = stringify(
|
|
15
|
+
const result = stringify(toArray(toCodePointList([128, 193, 245, 255])));
|
|
17
16
|
if (result !== '[-2147483520,-2147483455,-2147483403,-2147483393]') {
|
|
18
17
|
throw result;
|
|
19
18
|
}
|
|
20
19
|
},
|
|
21
20
|
() => {
|
|
22
|
-
const result = stringify(
|
|
21
|
+
const result = stringify(toArray(toCodePointList([0, 1, 127])));
|
|
23
22
|
if (result !== '[0,1,127]') {
|
|
24
23
|
throw result;
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
() => {
|
|
28
|
-
const result = stringify(
|
|
27
|
+
const result = stringify(toArray(toCodePointList([194, 128, 194, 169, 223, 191])));
|
|
29
28
|
if (result !== '[128,169,2047]') {
|
|
30
29
|
throw result;
|
|
31
30
|
}
|
|
32
31
|
},
|
|
33
32
|
() => {
|
|
34
|
-
const result = stringify(
|
|
33
|
+
const result = stringify(toArray(toCodePointList([194, 194, 127, 194, 192, 194])));
|
|
35
34
|
if (result !== '[-2147483454,-2147483454,127,-2147483454,-2147483456,-2147483454]') {
|
|
36
35
|
throw result;
|
|
37
36
|
}
|
|
38
37
|
},
|
|
39
38
|
() => {
|
|
40
|
-
const result = stringify(
|
|
39
|
+
const result = stringify(toArray(toCodePointList([224, 160, 128, 224, 160, 129, 239, 191, 191])));
|
|
41
40
|
if (result !== '[2048,2049,65535]') {
|
|
42
41
|
throw result;
|
|
43
42
|
}
|
|
44
43
|
},
|
|
45
44
|
() => {
|
|
46
|
-
const result = stringify(
|
|
45
|
+
const result = stringify(toArray(toCodePointList([224, 224, 160, 127, 239, 191])));
|
|
47
46
|
if (result !== '[-2147483424,-2147482592,127,-2147481601]') {
|
|
48
47
|
throw result;
|
|
49
48
|
}
|
|
50
49
|
},
|
|
51
50
|
() => {
|
|
52
|
-
const result = stringify(
|
|
51
|
+
const result = stringify(toArray(toCodePointList([240, 144, 128, 128, 240, 144, 128, 129, 244, 143, 191, 191])));
|
|
53
52
|
if (result !== '[65536,65537,1114111]') {
|
|
54
53
|
throw result;
|
|
55
54
|
}
|
|
56
55
|
},
|
|
57
56
|
() => {
|
|
58
|
-
const result = stringify(
|
|
57
|
+
const result = stringify(toArray(toCodePointList([240, 240, 160, 127, 244, 191])));
|
|
59
58
|
if (result !== '[-2147483408,-2147483104,127,-2147482817]') {
|
|
60
59
|
throw result;
|
|
61
60
|
}
|
|
62
61
|
},
|
|
63
62
|
() => {
|
|
64
|
-
const result = stringify(
|
|
63
|
+
const result = stringify(toArray(toCodePointList([240, 160, 160, 244, 160, 160])));
|
|
65
64
|
if (result !== '[-2147448800,-2147432416]') {
|
|
66
65
|
throw result;
|
|
67
66
|
}
|
|
@@ -69,67 +68,67 @@ export default {
|
|
|
69
68
|
],
|
|
70
69
|
fromCodePointList: [
|
|
71
70
|
() => {
|
|
72
|
-
const result = stringify(
|
|
71
|
+
const result = stringify(toArray(fromCodePointList([0, 1, 0x7F])));
|
|
73
72
|
if (result !== '[0,1,127]') {
|
|
74
73
|
throw result;
|
|
75
74
|
}
|
|
76
75
|
},
|
|
77
76
|
() => {
|
|
78
|
-
const result = stringify(
|
|
77
|
+
const result = stringify(toArray(fromCodePointList([0x80])));
|
|
79
78
|
if (result !== '[194,128]') {
|
|
80
79
|
throw result;
|
|
81
80
|
}
|
|
82
81
|
},
|
|
83
82
|
() => {
|
|
84
|
-
const result = stringify(
|
|
83
|
+
const result = stringify(toArray(fromCodePointList([0xa9])));
|
|
85
84
|
if (result !== '[194,169]') {
|
|
86
85
|
throw result;
|
|
87
86
|
}
|
|
88
87
|
},
|
|
89
88
|
() => {
|
|
90
|
-
const result = stringify(
|
|
89
|
+
const result = stringify(toArray(fromCodePointList([0x7ff])));
|
|
91
90
|
if (result !== '[223,191]') {
|
|
92
91
|
throw result;
|
|
93
92
|
}
|
|
94
93
|
},
|
|
95
94
|
() => {
|
|
96
|
-
const result = stringify(
|
|
95
|
+
const result = stringify(toArray(fromCodePointList([0x800])));
|
|
97
96
|
if (result !== '[224,160,128]') {
|
|
98
97
|
throw result;
|
|
99
98
|
}
|
|
100
99
|
},
|
|
101
100
|
() => {
|
|
102
|
-
const result = stringify(
|
|
101
|
+
const result = stringify(toArray(fromCodePointList([0x801])));
|
|
103
102
|
if (result !== '[224,160,129]') {
|
|
104
103
|
throw result;
|
|
105
104
|
}
|
|
106
105
|
},
|
|
107
106
|
() => {
|
|
108
|
-
const result = stringify(
|
|
107
|
+
const result = stringify(toArray(fromCodePointList([0xffff])));
|
|
109
108
|
if (result !== '[239,191,191]') {
|
|
110
109
|
throw result;
|
|
111
110
|
}
|
|
112
111
|
},
|
|
113
112
|
() => {
|
|
114
|
-
const result = stringify(
|
|
113
|
+
const result = stringify(toArray(fromCodePointList([0x10000])));
|
|
115
114
|
if (result !== '[240,144,128,128]') {
|
|
116
115
|
throw result;
|
|
117
116
|
}
|
|
118
117
|
},
|
|
119
118
|
() => {
|
|
120
|
-
const result = stringify(
|
|
119
|
+
const result = stringify(toArray(fromCodePointList([0x10001])));
|
|
121
120
|
if (result !== '[240,144,128,129]') {
|
|
122
121
|
throw result;
|
|
123
122
|
}
|
|
124
123
|
},
|
|
125
124
|
() => {
|
|
126
|
-
const result = stringify(
|
|
125
|
+
const result = stringify(toArray(fromCodePointList([0x10FFFF])));
|
|
127
126
|
if (result !== '[244,143,191,191]') {
|
|
128
127
|
throw result;
|
|
129
128
|
}
|
|
130
129
|
},
|
|
131
130
|
() => {
|
|
132
|
-
const result = stringify(
|
|
131
|
+
const result = stringify(toArray(fromCodePointList([0x110000, 2147483648])));
|
|
133
132
|
if (result !== '[2147483648,2147483648]') {
|
|
134
133
|
throw result;
|
|
135
134
|
}
|
|
@@ -137,36 +136,36 @@ export default {
|
|
|
137
136
|
],
|
|
138
137
|
toFrom: [
|
|
139
138
|
() => {
|
|
140
|
-
const codePointList =
|
|
141
|
-
const result = stringify(
|
|
139
|
+
const codePointList = toCodePointList([128, 193, 245, 255]);
|
|
140
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
142
141
|
if (result !== '[128,193,245,255]') {
|
|
143
142
|
throw result;
|
|
144
143
|
}
|
|
145
144
|
},
|
|
146
145
|
() => {
|
|
147
|
-
const codePointList =
|
|
148
|
-
const result = stringify(
|
|
146
|
+
const codePointList = toCodePointList([194, 194, 127, 194, 192, 194]);
|
|
147
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
149
148
|
if (result !== '[194,194,127,194,192,194]') {
|
|
150
149
|
throw result;
|
|
151
150
|
}
|
|
152
151
|
},
|
|
153
152
|
() => {
|
|
154
|
-
const codePointList =
|
|
155
|
-
const result = stringify(
|
|
153
|
+
const codePointList = toCodePointList([224, 224, 160, 127, 239, 191]);
|
|
154
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
156
155
|
if (result !== '[224,224,160,127,239,191]') {
|
|
157
156
|
throw result;
|
|
158
157
|
}
|
|
159
158
|
},
|
|
160
159
|
() => {
|
|
161
|
-
const codePointList =
|
|
162
|
-
const result = stringify(
|
|
160
|
+
const codePointList = toCodePointList([240, 240, 160, 127, 244, 191]);
|
|
161
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
163
162
|
if (result !== '[240,240,160,127,244,191]') {
|
|
164
163
|
throw result;
|
|
165
164
|
}
|
|
166
165
|
},
|
|
167
166
|
() => {
|
|
168
|
-
const codePointList =
|
|
169
|
-
const result = stringify(
|
|
167
|
+
const codePointList = toCodePointList([240, 160, 160, 244, 160, 160]);
|
|
168
|
+
const result = stringify(toArray(fromCodePointList(codePointList)));
|
|
170
169
|
if (result !== '[240,160,160,244,160,160]') {
|
|
171
170
|
throw result;
|
|
172
171
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as compare from '../function/compare/module.f.ts';
|
|
2
2
|
import type * as Operator from '../function/operator/module.f.ts';
|
|
3
3
|
import { type List } from '../list/module.f.ts';
|
|
4
|
-
type Unary = Operator.Unary<bigint, bigint>;
|
|
5
|
-
type Reduce = Operator.Reduce<bigint>;
|
|
4
|
+
export type Unary = Operator.Unary<bigint, bigint>;
|
|
5
|
+
export type Reduce = Operator.Reduce<bigint>;
|
|
6
6
|
export declare const addition: Reduce;
|
|
7
7
|
export declare const sum: (input: List<bigint>) => bigint;
|
|
8
8
|
export declare const abs: Unary;
|
|
@@ -44,8 +44,20 @@ export declare const log2: (v: bigint) => bigint;
|
|
|
44
44
|
* @returns The bit length of the input BigInt.
|
|
45
45
|
*
|
|
46
46
|
* @remark
|
|
47
|
-
* The function uses the `log2` function to calculate the position of the most significant bit(MSB)
|
|
48
|
-
* and adds `1n` to account for the MSB itself.For negative numbers, the absolute value is used.
|
|
47
|
+
* The function uses the `log2` function to calculate the position of the most significant bit (MSB)
|
|
48
|
+
* and adds `1n` to account for the MSB itself. For negative numbers, the absolute value is used.
|
|
49
49
|
*/
|
|
50
50
|
export declare const bitLength: (v: bigint) => bigint;
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Generates a bitmask with the specified number of bits set to 1.
|
|
53
|
+
*
|
|
54
|
+
* @param len - The number of bits to set in the mask. Must be a non-negative integer.
|
|
55
|
+
* @returns A bigint representing the bitmask, where the least significant `len` bits are 1.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
*
|
|
59
|
+
* ```js
|
|
60
|
+
* const result = mask(3n) // 7n
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const mask: (len: bigint) => bigint;
|
package/types/bigint/module.f.js
CHANGED
|
@@ -4,8 +4,8 @@ import { reduce } from "../list/module.f.js";
|
|
|
4
4
|
export const addition = a => b => a + b;
|
|
5
5
|
export const sum = reduce(addition)(0n);
|
|
6
6
|
export const abs = a => a >= 0 ? a : -a;
|
|
7
|
-
export const sign = a => unsafeCmp(a)(0n);
|
|
8
|
-
export const serialize = a => `${a}n`;
|
|
7
|
+
export const sign = (a) => unsafeCmp(a)(0n);
|
|
8
|
+
export const serialize = (a) => `${a}n`;
|
|
9
9
|
/**
|
|
10
10
|
* Calculates the base-2 logarithm (floor).
|
|
11
11
|
*
|
|
@@ -25,6 +25,8 @@ export const serialize = a => `${a}n`;
|
|
|
25
25
|
* determining the exact value of the logarithm.
|
|
26
26
|
*/
|
|
27
27
|
export const log2 = (v) => {
|
|
28
|
+
// TODO: use step 32 and `Math.clz32()` at the end.
|
|
29
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
|
|
28
30
|
if (v <= 0n) {
|
|
29
31
|
return -1n;
|
|
30
32
|
}
|
|
@@ -69,8 +71,8 @@ export const log2 = (v) => {
|
|
|
69
71
|
* @returns The bit length of the input BigInt.
|
|
70
72
|
*
|
|
71
73
|
* @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
|
+
* The function uses the `log2` function to calculate the position of the most significant bit (MSB)
|
|
75
|
+
* and adds `1n` to account for the MSB itself. For negative numbers, the absolute value is used.
|
|
74
76
|
*/
|
|
75
77
|
export const bitLength = (v) => {
|
|
76
78
|
if (v <= 0n) {
|
|
@@ -81,3 +83,16 @@ export const bitLength = (v) => {
|
|
|
81
83
|
}
|
|
82
84
|
return log2(v) + 1n;
|
|
83
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Generates a bitmask with the specified number of bits set to 1.
|
|
88
|
+
*
|
|
89
|
+
* @param len - The number of bits to set in the mask. Must be a non-negative integer.
|
|
90
|
+
* @returns A bigint representing the bitmask, where the least significant `len` bits are 1.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
*
|
|
94
|
+
* ```js
|
|
95
|
+
* const result = mask(3n) // 7n
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export const mask = (len) => (1n << len) - 1n;
|
package/types/bigint/test.f.d.ts
CHANGED
package/types/bigint/test.f.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
const { sum, abs, serialize, log2, bitLength } = _;
|
|
1
|
+
import { sum, abs, serialize, log2, bitLength, mask } from "./module.f.js";
|
|
3
2
|
export default {
|
|
3
|
+
mask: () => {
|
|
4
|
+
const result = mask(3n); // 7n
|
|
5
|
+
if (result !== 7n) {
|
|
6
|
+
throw result;
|
|
7
|
+
}
|
|
8
|
+
},
|
|
4
9
|
sum: () => {
|
|
5
10
|
const result = sum([2n, 3n, 4n, 5n]);
|
|
6
11
|
if (result !== 14n) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type List, type Thunk } from '../list/module.f.ts';
|
|
1
2
|
/**
|
|
2
3
|
* A vector of bits represented as a `bigint`.
|
|
3
4
|
*/
|
|
4
|
-
type Vec = bigint;
|
|
5
|
+
export type Vec = bigint;
|
|
5
6
|
/**
|
|
6
7
|
* An empty vector of bits.
|
|
7
8
|
*/
|
|
@@ -22,6 +23,10 @@ export declare const length: (v: bigint) => bigint;
|
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
25
|
export declare const vec: (len: bigint) => (ui: bigint) => Vec;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an 8 bit vector from an unsigned integer.
|
|
28
|
+
*/
|
|
29
|
+
export declare const vec8: (u: bigint) => Vec;
|
|
25
30
|
/**
|
|
26
31
|
* Returns the unsigned integer of the given vector by removing a stop bit.
|
|
27
32
|
*
|
|
@@ -34,101 +39,116 @@ export declare const vec: (len: bigint) => (ui: bigint) => Vec;
|
|
|
34
39
|
*/
|
|
35
40
|
export declare const uint: (v: Vec) => bigint;
|
|
36
41
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
42
|
+
* Represents operations for handling bit vectors with a specific bit order.
|
|
40
43
|
*
|
|
41
|
-
*
|
|
42
|
-
* const vector = vec(8n)(0xF5n) // 0x1F5n
|
|
43
|
-
* const result = uintLsb(4n)(vector); // result is 5n
|
|
44
|
-
* const result2 = uintLsb(16n)(vector); // result2 is 0xF5n
|
|
45
|
-
* ```
|
|
44
|
+
* https://en.wikipedia.org/wiki/Bit_numbering
|
|
46
45
|
*/
|
|
47
|
-
export
|
|
46
|
+
export type BitOrder = {
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the first unsigned integer of the specified length from the given vector.
|
|
49
|
+
*
|
|
50
|
+
* @param len - The number of bits to read from the start of the vector.
|
|
51
|
+
* @returns A function that takes a vector and returns the extracted unsigned integer.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```js
|
|
56
|
+
* const vector = vec(8n)(0xF5n) // 0x1F5n
|
|
57
|
+
*
|
|
58
|
+
* const resultL0 = lsb.front(4n)(vector) // resultL0 is 5n
|
|
59
|
+
* const resultL1 = lsb.front(16n)(vector) // resultL1 is 0xF5n
|
|
60
|
+
*
|
|
61
|
+
* const resultM0 = msb.front(4n)(vector) // resultM0 is 0xFn
|
|
62
|
+
* const resultM1 = msb.front(16n)(vector) // resultM1 is 0xF500n
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
readonly front: (len: bigint) => (v: Vec) => bigint;
|
|
66
|
+
/**
|
|
67
|
+
* Removes a specified number of bits from the start of the given vector.
|
|
68
|
+
*
|
|
69
|
+
* @param len - The number of bits to remove from the vector.
|
|
70
|
+
* @returns A function that takes a vector and returns the remaining vector.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
*
|
|
74
|
+
* ```js
|
|
75
|
+
* const v = vec(16n)(0x3456n) // 0x13456n
|
|
76
|
+
*
|
|
77
|
+
* const rL0 = lsb.removeFront(4n)(v) // 0x1345n
|
|
78
|
+
* const rL1 = lsb.removeFront(24n)(v) // 0x1n
|
|
79
|
+
*
|
|
80
|
+
* const rM0 = msb.removeFront(4n)(v) // 0x1456n
|
|
81
|
+
* const rM1 = msb.removeFront(24n)(v) // 0x1n
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
readonly removeFront: (len: bigint) => (v: Vec) => Vec;
|
|
85
|
+
/**
|
|
86
|
+
* Removes a specified number of bits from the start of the vector and returns
|
|
87
|
+
* the removed bits and the remaining vector.
|
|
88
|
+
*
|
|
89
|
+
* @param len - The number of bits to remove from the vector.
|
|
90
|
+
* @returns A function that takes a vector and returns
|
|
91
|
+
* a tuple containing the removed bits as an unsigned integer and the remaining vector.
|
|
92
|
+
*
|
|
93
|
+
* ```js
|
|
94
|
+
* const vector = vec(8n)(0xF5n) // 0x1F5n
|
|
95
|
+
*
|
|
96
|
+
* const [uL0, rL0] = lsb.popFront(4n)(vector) // [5n, 0x1Fn]
|
|
97
|
+
* const [uL1, rL1] = lsb.popFront(16n)(vector) // [0xF5n, 1n]
|
|
98
|
+
*
|
|
99
|
+
* const [uM0, rM0] = msb.popFront(4n)(vector) // [0xFn, 0x15n]
|
|
100
|
+
* const [uM1, rM1] = msb.popFront(16n)(vector) // [0xF500n, 1n]
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
readonly popFront: (len: bigint) => (v: Vec) => readonly [bigint, Vec];
|
|
104
|
+
/**
|
|
105
|
+
* Concatenates two vectors.
|
|
106
|
+
*
|
|
107
|
+
* @param a - The first vector.
|
|
108
|
+
* @returns A function that takes a second vector and returns the concatenated vector.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
*
|
|
112
|
+
* ```js
|
|
113
|
+
* const u8 = vec(8n)
|
|
114
|
+
* const a = u8(0x45n) // 0x145n
|
|
115
|
+
* const b = u8(0x89n) // 0x189n
|
|
116
|
+
*
|
|
117
|
+
* const abL = lsb.concat(a)(b) // 0x18945n
|
|
118
|
+
* const abM = msb.concat(a)(b) // 0x14589n
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
readonly concat: (a: Vec) => (b: Vec) => Vec;
|
|
122
|
+
};
|
|
48
123
|
/**
|
|
49
|
-
*
|
|
124
|
+
* Implements operations for handling vectors in a least-significant-bit (LSb) first order.
|
|
50
125
|
*
|
|
51
|
-
*
|
|
126
|
+
* https://en.wikipedia.org/wiki/Bit_numbering#LSb_0_bit_numbering
|
|
52
127
|
*
|
|
53
|
-
*
|
|
54
|
-
* const v = vec(16n)(0x3456n) // 0x13456n
|
|
55
|
-
* const r = removeLsb(4n)(v) // 0x1345n
|
|
56
|
-
* const r2 = removeLsb(24n)(v) // 0x1n
|
|
57
|
-
* ```
|
|
128
|
+
* Usually associated with Little-Endian (LE) byte order.
|
|
58
129
|
*/
|
|
59
|
-
export declare const
|
|
130
|
+
export declare const lsb: BitOrder;
|
|
60
131
|
/**
|
|
61
|
-
*
|
|
132
|
+
* Implements operations for handling vectors in a most-significant-bit (MSb) first order.
|
|
62
133
|
*
|
|
63
|
-
*
|
|
134
|
+
* https://en.wikipedia.org/wiki/Bit_numbering#MSb_0_bit_numbering
|
|
64
135
|
*
|
|
65
|
-
*
|
|
66
|
-
* const vector = vec(8n)(0xF5n) // 0x1F5n
|
|
67
|
-
* const [result, rest] = popUintLsb(4n)(vector); // result is 5n, rest is 0x1Fn
|
|
68
|
-
* const [result2, rest2] = popUintLsb(16n)(vector); // result2 is 0xF5n, rest2 is 1n
|
|
69
|
-
* ```
|
|
136
|
+
* Usually associated with Big-Endian (BE) byte order.
|
|
70
137
|
*/
|
|
71
|
-
export declare const
|
|
138
|
+
export declare const msb: BitOrder;
|
|
72
139
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
140
|
+
* Converts a list of unsigned 8-bit integers to a bit vector.
|
|
76
141
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* const result2 = uintMsb(16n)(vector); // result2 is 0xF500n
|
|
81
|
-
* ```
|
|
142
|
+
* @param bo The bit order for the conversion
|
|
143
|
+
* @param list The list of unsigned 8-bit integers to be converted.
|
|
144
|
+
* @returns The resulting vector based on the provided bit order.
|
|
82
145
|
*/
|
|
83
|
-
export declare const
|
|
146
|
+
export declare const u8ListToVec: (bo: BitOrder) => (list: List<number>) => Vec;
|
|
84
147
|
/**
|
|
85
|
-
*
|
|
148
|
+
* Converts a bit vector to a list of unsigned 8-bit integers based on the provided bit order.
|
|
86
149
|
*
|
|
87
|
-
* @
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* const v = vec(16n)(0x3456n) // 0x13456n
|
|
91
|
-
* const r = removeMsb(4n)(v) // 0x1456n
|
|
92
|
-
* const r2 = removeMsb(24n)(v) // 0x1n
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export declare const removeMsb: (len: bigint) => (v: Vec) => Vec;
|
|
96
|
-
/**
|
|
97
|
-
* Extracts the most significant unsigned integer and removes it from the vector.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
*
|
|
101
|
-
* ```js
|
|
102
|
-
* const vector = vec(8n)(0xF5n) // 0x1F5n
|
|
103
|
-
* const [result, rest] = popUintMsb(4n)(vector); // [0xFn, 0x15n]
|
|
104
|
-
* const [result2, rest2] = popUintMsb(16n)(vector); // [0xF500n, 1n]
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
export declare const popUintMsb: (len: bigint) => (v: Vec) => readonly [bigint, Vec];
|
|
108
|
-
/**
|
|
109
|
-
* Concat the given vectors of bits. The first vector is the least significant.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
*
|
|
113
|
-
* ```js
|
|
114
|
-
* const u8 = vec(8n)
|
|
115
|
-
* const a = u8(0x45n) // 0x145n
|
|
116
|
-
* const b = u8(0x89n) // 0x189n
|
|
117
|
-
* const ab = concatLsb(a)(b) // 0x18945n
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export declare const concatLsb: (a: Vec) => (b: Vec) => Vec;
|
|
121
|
-
/**
|
|
122
|
-
* Concat the given vectors of bits. The first vector is the most significant.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
*
|
|
126
|
-
* ```js
|
|
127
|
-
* const u8 = vec(8n)
|
|
128
|
-
* const a = u8(0x45n) // 0x145n
|
|
129
|
-
* const b = u8(0x89n) // 0x189n
|
|
130
|
-
* const ab = concatMsb(a)(b) // 0x14589n
|
|
131
|
-
* ```
|
|
150
|
+
* @param bitOrder The bit order for the conversion.
|
|
151
|
+
* @param v The vector to be converted.
|
|
152
|
+
* @returns A thunk that produces a list of unsigned 8-bit integers.
|
|
132
153
|
*/
|
|
133
|
-
export declare const
|
|
134
|
-
export {};
|
|
154
|
+
export declare const u8List: ({ popFront }: BitOrder) => (v: Vec) => Thunk<number>;
|