functionalscript 0.12.9 → 0.12.10
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/package.json +1 -1
- package/types/bit_vec/module.f.d.ts +1 -0
- package/types/bit_vec/module.f.js +12 -7
- package/types/bit_vec/test.f.d.ts +5 -0
- package/types/bit_vec/test.f.js +23 -0
- package/types/string/module.f.d.ts +1 -0
- package/types/string/module.f.js +1 -0
- package/types/string/test.f.d.ts +7 -0
- package/types/string/test.f.js +48 -1
package/package.json
CHANGED
|
@@ -163,6 +163,7 @@ export type BitOrder = {
|
|
|
163
163
|
readonly cmp: (a: Vec) => (b: Vec) => Sign;
|
|
164
164
|
readonly unpackSplit: (len: bigint) => (u: Unpacked) => readonly [bigint, bigint];
|
|
165
165
|
readonly unpackConcat: (a: Unpacked) => (b: Unpacked) => Unpacked;
|
|
166
|
+
readonly startsWith: (prefix: Vec) => (v: Vec) => boolean;
|
|
166
167
|
};
|
|
167
168
|
/**
|
|
168
169
|
* Implements operations for handling vectors in a least-significant-bit (LSb) first order.
|
|
@@ -119,6 +119,13 @@ const bo = ({ front, removeFront, norm, uintCmp, unpackSplit, unpackConcatUint }
|
|
|
119
119
|
const unpackConcat = (a) => (b) => ({
|
|
120
120
|
length: a.length + b.length, uint: unpackConcatUint(a)(b)
|
|
121
121
|
});
|
|
122
|
+
const popFront = len => {
|
|
123
|
+
const f = unpackPopFront(len);
|
|
124
|
+
return v => {
|
|
125
|
+
const [uint, u] = f(unpack(v));
|
|
126
|
+
return [uint, pack(u)];
|
|
127
|
+
};
|
|
128
|
+
};
|
|
122
129
|
return {
|
|
123
130
|
front,
|
|
124
131
|
removeFront,
|
|
@@ -129,13 +136,7 @@ const bo = ({ front, removeFront, norm, uintCmp, unpackSplit, unpackConcatUint }
|
|
|
129
136
|
},
|
|
130
137
|
xor: op(norm)(xor),
|
|
131
138
|
unpackPopFront,
|
|
132
|
-
popFront
|
|
133
|
-
const f = unpackPopFront(len);
|
|
134
|
-
return v => {
|
|
135
|
-
const [uint, u] = f(unpack(v));
|
|
136
|
-
return [uint, pack(u)];
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
+
popFront,
|
|
139
140
|
norm,
|
|
140
141
|
cmp: a => b => {
|
|
141
142
|
const au = unpack(a);
|
|
@@ -148,6 +149,10 @@ const bo = ({ front, removeFront, norm, uintCmp, unpackSplit, unpackConcatUint }
|
|
|
148
149
|
},
|
|
149
150
|
unpackSplit,
|
|
150
151
|
unpackConcat,
|
|
152
|
+
startsWith: prefix => {
|
|
153
|
+
const { length: n, uint: u } = unpack(prefix);
|
|
154
|
+
return v => length(v) < n ? false : popFront(n)(v)[0] === u;
|
|
155
|
+
}
|
|
151
156
|
};
|
|
152
157
|
};
|
|
153
158
|
const lsbUnpackConcatUint = ({ uint: a, length }) => ({ uint: b }) => (b << length) | a;
|
|
@@ -39,6 +39,11 @@ declare const _default: {
|
|
|
39
39
|
repeat: () => void;
|
|
40
40
|
lsbCmp: () => void;
|
|
41
41
|
msbCmp: () => void;
|
|
42
|
+
startsWith: {
|
|
43
|
+
lsb: () => void;
|
|
44
|
+
msb: () => void;
|
|
45
|
+
emptyVec: () => void;
|
|
46
|
+
};
|
|
42
47
|
u8ListToVec: () => () => void;
|
|
43
48
|
u8ListUnaligned: () => void;
|
|
44
49
|
chunkList: {
|
package/types/bit_vec/test.f.js
CHANGED
|
@@ -458,6 +458,29 @@ export default {
|
|
|
458
458
|
c(vec(5n)(0x5n))(vec(4n)(0x5n))(-1); // 0b00101 < 0b0101_
|
|
459
459
|
c(vec(4n)(0x5n))(vec(5n)(0xan))(-1); // 0b0101_ < 0b01010
|
|
460
460
|
},
|
|
461
|
+
startsWith: {
|
|
462
|
+
// vector 0xF5 = 0b1111_0101 (8 bits)
|
|
463
|
+
// LSB reads from the low end: bits 0-3 = 0101 = 0x5, bits 4-7 = 1111 = 0xF
|
|
464
|
+
lsb: () => {
|
|
465
|
+
const v = vec(8n)(0xf5n);
|
|
466
|
+
assertEq(lsb.startsWith(vec(4n)(0x5n))(v), true); // low nibble matches
|
|
467
|
+
assertEq(lsb.startsWith(vec(4n)(0xfn))(v), false); // low nibble doesn't match
|
|
468
|
+
assertEq(lsb.startsWith(v)(vec(4n)(0x5n)), false); // prefix longer than vector
|
|
469
|
+
assertEq(lsb.startsWith(empty)(v), true); // empty prefix always matches
|
|
470
|
+
},
|
|
471
|
+
// MSB reads from the high end: bits 0-3 = 1111 = 0xF, bits 4-7 = 0101 = 0x5
|
|
472
|
+
msb: () => {
|
|
473
|
+
const v = vec(8n)(0xf5n);
|
|
474
|
+
assertEq(msb.startsWith(vec(4n)(0xfn))(v), true); // high nibble matches
|
|
475
|
+
assertEq(msb.startsWith(vec(4n)(0x5n))(v), false); // high nibble doesn't match
|
|
476
|
+
assertEq(msb.startsWith(v)(vec(4n)(0xfn)), false); // prefix longer than vector
|
|
477
|
+
assertEq(msb.startsWith(empty)(v), true); // empty prefix always matches
|
|
478
|
+
},
|
|
479
|
+
emptyVec: () => {
|
|
480
|
+
assertEq(lsb.startsWith(empty)(empty), true);
|
|
481
|
+
assertEq(msb.startsWith(empty)(empty), true);
|
|
482
|
+
},
|
|
483
|
+
},
|
|
461
484
|
u8ListToVec: () => {
|
|
462
485
|
// 131_072 is too much for Bun
|
|
463
486
|
const x = u8ListToVec(msb)(listRepeat(0x12)(131_071));
|
|
@@ -21,3 +21,4 @@ export declare const join: (_: string) => (input: List<string>) => string;
|
|
|
21
21
|
export declare const concat: (input: List<string>) => string;
|
|
22
22
|
export declare const repeat: (n: string) => (v: number) => string;
|
|
23
23
|
export declare const cmp: (a: string) => (b: string) => Sign;
|
|
24
|
+
export declare const splitAt: (p: number) => (v: string) => readonly [string, string];
|
package/types/string/module.f.js
CHANGED
package/types/string/test.f.d.ts
CHANGED
package/types/string/test.f.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, concat, repeat, cmp } from "./module.f.js";
|
|
1
|
+
import { join, concat, repeat, cmp, splitAt } from "./module.f.js";
|
|
2
2
|
import { repeat as repeatList } from "../list/module.f.js";
|
|
3
3
|
export default {
|
|
4
4
|
example: () => {
|
|
@@ -67,5 +67,52 @@ export default {
|
|
|
67
67
|
if (result !== -1) {
|
|
68
68
|
throw result;
|
|
69
69
|
}
|
|
70
|
+
},
|
|
71
|
+
splitAt: {
|
|
72
|
+
middle: () => {
|
|
73
|
+
const [a, b] = splitAt(3)('hello');
|
|
74
|
+
if (a !== 'hel') {
|
|
75
|
+
throw a;
|
|
76
|
+
}
|
|
77
|
+
if (b !== 'lo') {
|
|
78
|
+
throw b;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
zero: () => {
|
|
82
|
+
const [a, b] = splitAt(0)('hello');
|
|
83
|
+
if (a !== '') {
|
|
84
|
+
throw a;
|
|
85
|
+
}
|
|
86
|
+
if (b !== 'hello') {
|
|
87
|
+
throw b;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
full: () => {
|
|
91
|
+
const [a, b] = splitAt(5)('hello');
|
|
92
|
+
if (a !== 'hello') {
|
|
93
|
+
throw a;
|
|
94
|
+
}
|
|
95
|
+
if (b !== '') {
|
|
96
|
+
throw b;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
beyond: () => {
|
|
100
|
+
const [a, b] = splitAt(10)('hello');
|
|
101
|
+
if (a !== 'hello') {
|
|
102
|
+
throw a;
|
|
103
|
+
}
|
|
104
|
+
if (b !== '') {
|
|
105
|
+
throw b;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
empty: () => {
|
|
109
|
+
const [a, b] = splitAt(0)('');
|
|
110
|
+
if (a !== '') {
|
|
111
|
+
throw a;
|
|
112
|
+
}
|
|
113
|
+
if (b !== '') {
|
|
114
|
+
throw b;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
70
117
|
}
|
|
71
118
|
};
|