@calcit/procs 0.9.16 → 0.9.18
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/README.md +1 -1
- package/lib/calcit-data.mjs +32 -29
- package/lib/calcit.procs.mjs +5 -9
- package/lib/js-cirru.mjs +1 -1
- package/lib/js-list.mjs +3 -3
- package/lib/js-map.mjs +2 -2
- package/lib/js-primes.mjs +1 -1
- package/lib/js-record.mjs +5 -3
- package/lib/package.json +4 -4
- package/package.json +4 -4
- package/ts-src/calcit-data.mts +33 -28
- package/ts-src/calcit.procs.mts +5 -9
- package/ts-src/js-cirru.mts +1 -1
- package/ts-src/js-list.mts +3 -3
- package/ts-src/js-map.mts +2 -2
- package/ts-src/js-primes.mts +1 -1
- package/ts-src/js-record.mts +5 -3
package/README.md
CHANGED
package/lib/calcit-data.mjs
CHANGED
|
@@ -97,36 +97,32 @@ export let getStringName = (x) => {
|
|
|
97
97
|
};
|
|
98
98
|
/** returns -1 when not found */
|
|
99
99
|
export function findInFields(xs, y) {
|
|
100
|
-
let
|
|
101
|
-
let
|
|
102
|
-
while (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
|
|
100
|
+
let low = 0;
|
|
101
|
+
let high = xs.length - 1;
|
|
102
|
+
while (low <= high) {
|
|
103
|
+
const mid = Math.floor((low + high) / 2);
|
|
104
|
+
const midVal = xs[mid];
|
|
105
|
+
if (midVal.idx < y.idx) {
|
|
106
|
+
low = mid + 1;
|
|
107
107
|
}
|
|
108
|
-
else if (
|
|
109
|
-
|
|
108
|
+
else if (midVal.idx > y.idx) {
|
|
109
|
+
high = mid - 1;
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
|
-
return
|
|
112
|
+
return mid;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
if (y === xs[lower])
|
|
116
|
-
return lower;
|
|
117
|
-
if (y === xs[upper])
|
|
118
|
-
return upper;
|
|
119
115
|
return -1;
|
|
120
116
|
}
|
|
121
|
-
var
|
|
117
|
+
var tagRegistry = {};
|
|
122
118
|
export let newTag = (content) => {
|
|
123
|
-
let item =
|
|
119
|
+
let item = tagRegistry[content];
|
|
124
120
|
if (item != null) {
|
|
125
121
|
return item;
|
|
126
122
|
}
|
|
127
123
|
else {
|
|
128
124
|
let v = new CalcitTag(content);
|
|
129
|
-
|
|
125
|
+
tagRegistry[content] = v;
|
|
130
126
|
return v;
|
|
131
127
|
}
|
|
132
128
|
};
|
|
@@ -554,23 +550,30 @@ export let _$n__$e_ = (x, y) => {
|
|
|
554
550
|
return false;
|
|
555
551
|
}
|
|
556
552
|
let values = x.values();
|
|
553
|
+
let yValues = y.values();
|
|
554
|
+
// Optimize: create a Map for O(1) lookup instead of O(n) iteration
|
|
555
|
+
let yMap = new Map();
|
|
556
|
+
for (let idx = 0; idx < yValues.length; idx++) {
|
|
557
|
+
let yv = yValues[idx];
|
|
558
|
+
yMap.set(yv, true);
|
|
559
|
+
}
|
|
557
560
|
for (let idx = 0; idx < values.length; idx++) {
|
|
558
561
|
let v = values[idx];
|
|
559
562
|
let found = false;
|
|
560
|
-
//
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
for (let idx = 0; idx < yValues.length; idx++) {
|
|
564
|
-
let yv = yValues[idx];
|
|
565
|
-
if (_$n__$e_(v, yv)) {
|
|
566
|
-
found = true;
|
|
567
|
-
break;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
if (found) {
|
|
571
|
-
continue;
|
|
563
|
+
// First try direct lookup for primitive values
|
|
564
|
+
if (yMap.has(v)) {
|
|
565
|
+
found = true;
|
|
572
566
|
}
|
|
573
567
|
else {
|
|
568
|
+
// Fallback to deep equality check for complex values
|
|
569
|
+
for (let yv of yValues) {
|
|
570
|
+
if (_$n__$e_(v, yv)) {
|
|
571
|
+
found = true;
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (!found) {
|
|
574
577
|
return false;
|
|
575
578
|
}
|
|
576
579
|
}
|
package/lib/calcit.procs.mjs
CHANGED
|
@@ -638,14 +638,10 @@ export let round_$q_ = (a) => {
|
|
|
638
638
|
return a === Math.round(a);
|
|
639
639
|
};
|
|
640
640
|
export let _$n_str_$o_concat = (a, b) => {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
if (b != null) {
|
|
646
|
-
buffer += toString(b, false);
|
|
647
|
-
}
|
|
648
|
-
return buffer;
|
|
641
|
+
// Optimize string concatenation by avoiding unnecessary toString calls
|
|
642
|
+
const aStr = a != null ? toString(a, false) : "";
|
|
643
|
+
const bStr = b != null ? toString(b, false) : "";
|
|
644
|
+
return aStr + bStr;
|
|
649
645
|
};
|
|
650
646
|
export let sort = (xs, f) => {
|
|
651
647
|
if (xs == null) {
|
|
@@ -837,7 +833,7 @@ export let parse_float = (x) => {
|
|
|
837
833
|
export let trim = (x, c) => {
|
|
838
834
|
if (c != null) {
|
|
839
835
|
if (c.length !== 1) {
|
|
840
|
-
throw new Error("
|
|
836
|
+
throw new Error("Expected c of a character");
|
|
841
837
|
}
|
|
842
838
|
var buffer = x;
|
|
843
839
|
var size = buffer.length;
|
package/lib/js-cirru.mjs
CHANGED
package/lib/js-list.mjs
CHANGED
|
@@ -313,7 +313,7 @@ export let foldl = function (xs, acc, f) {
|
|
|
313
313
|
});
|
|
314
314
|
return result;
|
|
315
315
|
}
|
|
316
|
-
throw new Error("
|
|
316
|
+
throw new Error("Unknown data for foldl");
|
|
317
317
|
};
|
|
318
318
|
export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
319
319
|
if (arguments.length !== 4) {
|
|
@@ -411,7 +411,7 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
411
411
|
}
|
|
412
412
|
return v0;
|
|
413
413
|
}
|
|
414
|
-
throw new Error("
|
|
414
|
+
throw new Error("Unknown data for foldl-shortcut");
|
|
415
415
|
};
|
|
416
416
|
export let foldr_shortcut = function (xs, acc, v0, f) {
|
|
417
417
|
if (arguments.length !== 4) {
|
|
@@ -442,5 +442,5 @@ export let foldr_shortcut = function (xs, acc, v0, f) {
|
|
|
442
442
|
}
|
|
443
443
|
return v0;
|
|
444
444
|
}
|
|
445
|
-
throw new Error("
|
|
445
|
+
throw new Error("Unknown data for foldr-shortcut, expected only list");
|
|
446
446
|
};
|
package/lib/js-map.mjs
CHANGED
|
@@ -154,7 +154,7 @@ export class CalcitMap {
|
|
|
154
154
|
}
|
|
155
155
|
return new CalcitSet(ret);
|
|
156
156
|
}
|
|
157
|
-
/**
|
|
157
|
+
/** detecting in custom formatter */
|
|
158
158
|
nestedDataInChildren() {
|
|
159
159
|
let pairs = this.pairs();
|
|
160
160
|
for (let idx = 0; idx < pairs.length; idx++) {
|
|
@@ -365,7 +365,7 @@ export class CalcitSliceMap {
|
|
|
365
365
|
}
|
|
366
366
|
return new CalcitSet(ret);
|
|
367
367
|
}
|
|
368
|
-
/**
|
|
368
|
+
/** detecting in custom formatter */
|
|
369
369
|
nestedDataInChildren() {
|
|
370
370
|
let pairs = this.pairs();
|
|
371
371
|
for (let idx = 0; idx < pairs.length; idx++) {
|
package/lib/js-primes.mjs
CHANGED
|
@@ -40,7 +40,7 @@ var PseudoTypeIndex;
|
|
|
40
40
|
PseudoTypeIndex[PseudoTypeIndex["cirru_quote"] = 14] = "cirru_quote";
|
|
41
41
|
})(PseudoTypeIndex || (PseudoTypeIndex = {}));
|
|
42
42
|
let typeAsInt = (x) => {
|
|
43
|
-
// based on order used in Ord
|
|
43
|
+
// based on order used in Ord trait
|
|
44
44
|
if (x == null)
|
|
45
45
|
return PseudoTypeIndex.nil;
|
|
46
46
|
let t = typeof x;
|
package/lib/js-record.mjs
CHANGED
|
@@ -61,11 +61,13 @@ export class CalcitRecord {
|
|
|
61
61
|
return idx >= 0;
|
|
62
62
|
}
|
|
63
63
|
toString(disableJsDataWarning = false) {
|
|
64
|
-
|
|
64
|
+
// Optimize string building using array join instead of concatenation
|
|
65
|
+
const parts = ["(%{} ", this.name.toString()];
|
|
65
66
|
for (let idx = 0; idx < this.fields.length; idx++) {
|
|
66
|
-
|
|
67
|
+
parts.push(" (", this.fields[idx].toString(), " ", toString(this.values[idx], true, disableJsDataWarning), ")");
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
parts.push(")");
|
|
70
|
+
return parts.join("");
|
|
69
71
|
}
|
|
70
72
|
withClass(klass) {
|
|
71
73
|
if (klass instanceof CalcitRecord) {
|
package/lib/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calcit/procs",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.18",
|
|
4
4
|
"main": "./lib/calcit.procs.mjs",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@types/node": "^
|
|
7
|
-
"typescript": "^5.
|
|
6
|
+
"@types/node": "^24.1.0",
|
|
7
|
+
"typescript": "^5.9.2"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"compile": "rm -rfv lib/* && tsc",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "https://github.com/calcit-lang/calcit"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@calcit/ternary-tree": "0.0.
|
|
25
|
+
"@calcit/ternary-tree": "0.0.25",
|
|
26
26
|
"@cirru/parser.ts": "^0.0.6",
|
|
27
27
|
"@cirru/writer.ts": "^0.1.5"
|
|
28
28
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calcit/procs",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.18",
|
|
4
4
|
"main": "./lib/calcit.procs.mjs",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@types/node": "^
|
|
7
|
-
"typescript": "^5.
|
|
6
|
+
"@types/node": "^24.1.0",
|
|
7
|
+
"typescript": "^5.9.2"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"compile": "rm -rfv lib/* && tsc",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "https://github.com/calcit-lang/calcit"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@calcit/ternary-tree": "0.0.
|
|
25
|
+
"@calcit/ternary-tree": "0.0.25",
|
|
26
26
|
"@cirru/parser.ts": "^0.0.6",
|
|
27
27
|
"@cirru/writer.ts": "^0.1.5"
|
|
28
28
|
}
|
package/ts-src/calcit-data.mts
CHANGED
|
@@ -118,35 +118,32 @@ export let getStringName = (x: CalcitValue): string => {
|
|
|
118
118
|
|
|
119
119
|
/** returns -1 when not found */
|
|
120
120
|
export function findInFields(xs: Array<CalcitTag>, y: CalcitTag): number {
|
|
121
|
-
let
|
|
122
|
-
let
|
|
123
|
-
|
|
124
|
-
while (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
} else if (
|
|
130
|
-
|
|
121
|
+
let low = 0;
|
|
122
|
+
let high = xs.length - 1;
|
|
123
|
+
|
|
124
|
+
while (low <= high) {
|
|
125
|
+
const mid = Math.floor((low + high) / 2);
|
|
126
|
+
const midVal = xs[mid];
|
|
127
|
+
if (midVal.idx < y.idx) {
|
|
128
|
+
low = mid + 1;
|
|
129
|
+
} else if (midVal.idx > y.idx) {
|
|
130
|
+
high = mid - 1;
|
|
131
131
|
} else {
|
|
132
|
-
return
|
|
132
|
+
return mid;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
|
|
136
|
-
if (y === xs[lower]) return lower;
|
|
137
|
-
if (y === xs[upper]) return upper;
|
|
138
135
|
return -1;
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
var
|
|
138
|
+
var tagRegistry: Record<string, CalcitTag> = {};
|
|
142
139
|
|
|
143
140
|
export let newTag = (content: string) => {
|
|
144
|
-
let item =
|
|
141
|
+
let item = tagRegistry[content];
|
|
145
142
|
if (item != null) {
|
|
146
143
|
return item;
|
|
147
144
|
} else {
|
|
148
145
|
let v = new CalcitTag(content);
|
|
149
|
-
|
|
146
|
+
tagRegistry[content] = v;
|
|
150
147
|
return v;
|
|
151
148
|
}
|
|
152
149
|
};
|
|
@@ -591,22 +588,30 @@ export let _$n__$e_ = (x: CalcitValue, y: CalcitValue): boolean => {
|
|
|
591
588
|
return false;
|
|
592
589
|
}
|
|
593
590
|
let values = x.values();
|
|
591
|
+
let yValues = y.values();
|
|
592
|
+
// Optimize: create a Map for O(1) lookup instead of O(n) iteration
|
|
593
|
+
let yMap = new Map();
|
|
594
|
+
for (let idx = 0; idx < yValues.length; idx++) {
|
|
595
|
+
let yv = yValues[idx];
|
|
596
|
+
yMap.set(yv, true);
|
|
597
|
+
}
|
|
598
|
+
|
|
594
599
|
for (let idx = 0; idx < values.length; idx++) {
|
|
595
600
|
let v = values[idx];
|
|
596
601
|
let found = false;
|
|
597
|
-
//
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
602
|
+
// First try direct lookup for primitive values
|
|
603
|
+
if (yMap.has(v)) {
|
|
604
|
+
found = true;
|
|
605
|
+
} else {
|
|
606
|
+
// Fallback to deep equality check for complex values
|
|
607
|
+
for (let yv of yValues) {
|
|
608
|
+
if (_$n__$e_(v, yv)) {
|
|
609
|
+
found = true;
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
605
612
|
}
|
|
606
613
|
}
|
|
607
|
-
if (found) {
|
|
608
|
-
continue;
|
|
609
|
-
} else {
|
|
614
|
+
if (!found) {
|
|
610
615
|
return false;
|
|
611
616
|
}
|
|
612
617
|
}
|
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -696,14 +696,10 @@ export let round_$q_ = (a: number) => {
|
|
|
696
696
|
return a === Math.round(a);
|
|
697
697
|
};
|
|
698
698
|
export let _$n_str_$o_concat = (a: string, b: string) => {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
if (b != null) {
|
|
704
|
-
buffer += toString(b, false);
|
|
705
|
-
}
|
|
706
|
-
return buffer;
|
|
699
|
+
// Optimize string concatenation by avoiding unnecessary toString calls
|
|
700
|
+
const aStr = a != null ? toString(a, false) : "";
|
|
701
|
+
const bStr = b != null ? toString(b, false) : "";
|
|
702
|
+
return aStr + bStr;
|
|
707
703
|
};
|
|
708
704
|
export let sort = (xs: CalcitList | CalcitSliceList, f: CalcitFn): CalcitSliceList => {
|
|
709
705
|
if (xs == null) {
|
|
@@ -907,7 +903,7 @@ export let parse_float = (x: string): number => {
|
|
|
907
903
|
export let trim = (x: string, c: string): string => {
|
|
908
904
|
if (c != null) {
|
|
909
905
|
if (c.length !== 1) {
|
|
910
|
-
throw new Error("
|
|
906
|
+
throw new Error("Expected c of a character");
|
|
911
907
|
}
|
|
912
908
|
var buffer = x;
|
|
913
909
|
var size = buffer.length;
|
package/ts-src/js-cirru.mts
CHANGED
|
@@ -270,7 +270,7 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
|
|
|
270
270
|
throw new Error(`Expected pair of size 2, got: ${pair}`);
|
|
271
271
|
}
|
|
272
272
|
} else {
|
|
273
|
-
throw new Error(`Expected pairs for
|
|
273
|
+
throw new Error(`Expected pairs for record, got: ${pair}`);
|
|
274
274
|
}
|
|
275
275
|
});
|
|
276
276
|
entries.sort((a, b) => {
|
package/ts-src/js-list.mts
CHANGED
|
@@ -332,7 +332,7 @@ export let foldl = function (xs: CalcitValue, acc: CalcitValue, f: CalcitFn): Ca
|
|
|
332
332
|
});
|
|
333
333
|
return result;
|
|
334
334
|
}
|
|
335
|
-
throw new Error("
|
|
335
|
+
throw new Error("Unknown data for foldl");
|
|
336
336
|
};
|
|
337
337
|
|
|
338
338
|
export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: CalcitValue, f: CalcitFn): CalcitValue {
|
|
@@ -424,7 +424,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
424
424
|
}
|
|
425
425
|
return v0;
|
|
426
426
|
}
|
|
427
|
-
throw new Error("
|
|
427
|
+
throw new Error("Unknown data for foldl-shortcut");
|
|
428
428
|
};
|
|
429
429
|
export let foldr_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: CalcitValue, f: CalcitFn): CalcitValue {
|
|
430
430
|
if (arguments.length !== 4) {
|
|
@@ -455,5 +455,5 @@ export let foldr_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
455
455
|
return v0;
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
throw new Error("
|
|
458
|
+
throw new Error("Unknown data for foldr-shortcut, expected only list");
|
|
459
459
|
};
|
package/ts-src/js-map.mts
CHANGED
|
@@ -176,7 +176,7 @@ export class CalcitMap {
|
|
|
176
176
|
return new CalcitSet(ret);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
/**
|
|
179
|
+
/** detecting in custom formatter */
|
|
180
180
|
nestedDataInChildren() {
|
|
181
181
|
let pairs = this.pairs();
|
|
182
182
|
for (let idx = 0; idx < pairs.length; idx++) {
|
|
@@ -392,7 +392,7 @@ export class CalcitSliceMap {
|
|
|
392
392
|
return new CalcitSet(ret);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
/**
|
|
395
|
+
/** detecting in custom formatter */
|
|
396
396
|
nestedDataInChildren() {
|
|
397
397
|
let pairs = this.pairs();
|
|
398
398
|
for (let idx = 0; idx < pairs.length; idx++) {
|
package/ts-src/js-primes.mts
CHANGED
|
@@ -55,7 +55,7 @@ enum PseudoTypeIndex {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
let typeAsInt = (x: CalcitValue): number => {
|
|
58
|
-
// based on order used in Ord
|
|
58
|
+
// based on order used in Ord trait
|
|
59
59
|
if (x == null) return PseudoTypeIndex.nil;
|
|
60
60
|
let t = typeof x;
|
|
61
61
|
if (t === "boolean") return PseudoTypeIndex.bool;
|
package/ts-src/js-record.mts
CHANGED
|
@@ -66,11 +66,13 @@ export class CalcitRecord {
|
|
|
66
66
|
return idx >= 0;
|
|
67
67
|
}
|
|
68
68
|
toString(disableJsDataWarning: boolean = false): string {
|
|
69
|
-
|
|
69
|
+
// Optimize string building using array join instead of concatenation
|
|
70
|
+
const parts = ["(%{} ", this.name.toString()];
|
|
70
71
|
for (let idx = 0; idx < this.fields.length; idx++) {
|
|
71
|
-
|
|
72
|
+
parts.push(" (", this.fields[idx].toString(), " ", toString(this.values[idx], true, disableJsDataWarning), ")");
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
+
parts.push(")");
|
|
75
|
+
return parts.join("");
|
|
74
76
|
}
|
|
75
77
|
withClass(klass: CalcitValue): CalcitRecord {
|
|
76
78
|
if (klass instanceof CalcitRecord) {
|