@calcit/ternary-tree 0.0.16 → 0.0.19-a1
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/lib/{hash.d.ts → hash.d.mts} +0 -0
- package/lib/{hash.js → hash.mjs} +0 -0
- package/lib/index.d.mts +4 -0
- package/lib/index.mjs +4 -0
- package/lib/{list.d.ts → list.d.mts} +2 -1
- package/lib/{list.js → list.mjs} +12 -4
- package/lib/main.d.mts +2 -0
- package/lib/{main.js → main.mjs} +6 -6
- package/lib/{map.d.ts → map.d.mts} +3 -2
- package/lib/{map.js → map.mjs} +62 -29
- package/lib/{test-list.d.ts → test-list.d.mts} +0 -0
- package/lib/{test-list.js → test-list.mjs} +24 -3
- package/lib/{test-map.d.ts → test-map.d.mts} +0 -0
- package/lib/{test-map.js → test-map.mjs} +18 -18
- package/lib/{types.d.ts → types.d.mts} +0 -0
- package/lib/{types.js → types.mjs} +0 -0
- package/lib/{utils.d.ts → utils.d.mts} +2 -2
- package/lib/{utils.js → utils.mjs} +3 -3
- package/package.json +9 -7
- package/assets/index.html +0 -2
- package/lib/bundle.js +0 -2979
- package/lib/bundle.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -4
- package/lib/main.d.ts +0 -2
- package/src/costs.nim +0 -62
- package/src/hash.ts +0 -78
- package/src/index.ts +0 -5
- package/src/list.ts +0 -987
- package/src/main.ts +0 -20
- package/src/map.ts +0 -1307
- package/src/shape.nim +0 -62
- package/src/test-list.ts +0 -264
- package/src/test-map.ts +0 -287
- package/src/types.ts +0 -87
- package/src/utils.ts +0 -124
File without changes
|
package/lib/{hash.js → hash.mjs}
RENAMED
File without changes
|
package/lib/index.d.mts
ADDED
package/lib/index.mjs
ADDED
@@ -1,7 +1,8 @@
|
|
1
|
-
import { TernaryTreeList } from "./types";
|
1
|
+
import { TernaryTreeList } from "./types.mjs";
|
2
2
|
export declare function getDepth<T>(tree: TernaryTreeList<T>): number;
|
3
3
|
export declare function makeTernaryTreeList<T>(size: number, offset: number, xs: Array<TernaryTreeList<T>>): TernaryTreeList<T>;
|
4
4
|
export declare function initTernaryTreeList<T>(xs: Array<T>): TernaryTreeList<T>;
|
5
|
+
export declare function initTernaryTreeListFromRange<T>(xs: Array<T>, from: number, to: number): TernaryTreeList<T>;
|
5
6
|
export declare function initEmptyTernaryTreeList<T>(): TernaryTreeList<T>;
|
6
7
|
export declare function listToString<T>(tree: TernaryTreeList<T>): string;
|
7
8
|
export declare function listLen<T>(tree: TernaryTreeList<T>): number;
|
package/lib/{list.js → list.mjs}
RENAMED
@@ -1,6 +1,5 @@
|
|
1
|
-
import { TernaryTreeKind } from "./types";
|
2
|
-
import "./
|
3
|
-
import { dataEqual, divideTernarySizes, roughIntPow } from "./utils";
|
1
|
+
import { TernaryTreeKind } from "./types.mjs";
|
2
|
+
import { dataEqual, divideTernarySizes, roughIntPow } from "./utils.mjs";
|
4
3
|
// just get, will not compute recursively
|
5
4
|
export function getDepth(tree) {
|
6
5
|
if (tree == null)
|
@@ -90,6 +89,15 @@ export function initTernaryTreeList(xs) {
|
|
90
89
|
}
|
91
90
|
return makeTernaryTreeList(xs.length, 0, ys);
|
92
91
|
}
|
92
|
+
// from a slice of an existed array
|
93
|
+
export function initTernaryTreeListFromRange(xs, from, to) {
|
94
|
+
let ys = new Array(xs.length);
|
95
|
+
for (let idx = from; idx < to; idx++) {
|
96
|
+
let x = xs[idx];
|
97
|
+
ys[idx] = { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: x };
|
98
|
+
}
|
99
|
+
return makeTernaryTreeList(xs.length, 0, ys);
|
100
|
+
}
|
93
101
|
export function initEmptyTernaryTreeList() {
|
94
102
|
return { kind: TernaryTreeKind.ternaryTreeBranch, size: 0, depth: 1, middle: emptyBranch, left: emptyBranch, right: emptyBranch };
|
95
103
|
}
|
@@ -789,7 +797,7 @@ export function listEqual(xs, ys) {
|
|
789
797
|
return true;
|
790
798
|
}
|
791
799
|
export function checkListStructure(tree) {
|
792
|
-
if (tree == null) {
|
800
|
+
if (tree == null || listLen(tree) === 0) {
|
793
801
|
return true;
|
794
802
|
}
|
795
803
|
else {
|
package/lib/main.d.mts
ADDED
package/lib/{main.js → main.mjs}
RENAMED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { deepEqual, overwriteComparator } from "./utils";
|
2
|
-
import "./test-list";
|
3
|
-
import "./test-map";
|
4
|
-
import { runListTests } from "./test-list";
|
5
|
-
import { runMapTests } from "./test-map";
|
6
|
-
import { mergeValueHash, overwriteHashGenerator, valueHash } from "./types";
|
1
|
+
import { deepEqual, overwriteComparator } from "./utils.mjs";
|
2
|
+
import "./test-list.mjs";
|
3
|
+
import "./test-map.mjs";
|
4
|
+
import { runListTests } from "./test-list.mjs";
|
5
|
+
import { runMapTests } from "./test-map.mjs";
|
6
|
+
import { mergeValueHash, overwriteHashGenerator, valueHash } from "./types.mjs";
|
7
7
|
overwriteComparator((x, y) => {
|
8
8
|
// console.log("comparing", x, y);
|
9
9
|
return deepEqual(x, y);
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import { TernaryTreeMap, TernaryTreeMapHashEntry } from "./types";
|
1
|
+
import { TernaryTreeMap, TernaryTreeMapHashEntry } from "./types.mjs";
|
2
2
|
export declare function getMapDepth<K, V>(tree: TernaryTreeMap<K, V>): number;
|
3
3
|
export declare function initTernaryTreeMapFromHashEntries<K, T>(xs: Array<TernaryTreeMapHashEntry<K, T>>): TernaryTreeMap<K, T>;
|
4
|
-
export declare function initTernaryTreeMap<K, T>(t: Map<K, T>
|
4
|
+
export declare function initTernaryTreeMap<K, T>(t: Map<K, T>): TernaryTreeMap<K, T>;
|
5
|
+
export declare function initTernaryTreeMapFromArray<K, T>(t: Array<[K, T]>): TernaryTreeMap<K, T>;
|
5
6
|
export declare function initEmptyTernaryTreeMap<K, T>(): TernaryTreeMap<K, T>;
|
6
7
|
export declare function mapToString<K, V>(tree: TernaryTreeMap<K, V>): string;
|
7
8
|
export declare function mapLen<K, V>(tree: TernaryTreeMap<K, V>): number;
|
package/lib/{map.js → map.mjs}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { TernaryTreeKind, hashGenerator } from "./types";
|
2
|
-
import { divideTernarySizes, cmp, dataEqual } from "./utils";
|
1
|
+
import { TernaryTreeKind, hashGenerator, } from "./types.mjs";
|
2
|
+
import { divideTernarySizes, cmp, dataEqual } from "./utils.mjs";
|
3
3
|
let emptyBranch = null;
|
4
4
|
let nilResult = null;
|
5
5
|
function getMax(tree) {
|
@@ -123,6 +123,7 @@ export function initTernaryTreeMapFromHashEntries(xs) {
|
|
123
123
|
}
|
124
124
|
export function initTernaryTreeMap(t) {
|
125
125
|
let groupBuffers = new Map();
|
126
|
+
let xs = [];
|
126
127
|
for (let [k, v] of t) {
|
127
128
|
let h = hashGenerator(k);
|
128
129
|
if (groupBuffers.has(h)) {
|
@@ -135,16 +136,16 @@ export function initTernaryTreeMap(t) {
|
|
135
136
|
}
|
136
137
|
}
|
137
138
|
else {
|
138
|
-
|
139
|
+
let pairs = [[k, v]];
|
140
|
+
groupBuffers.set(h, pairs);
|
141
|
+
xs.push({
|
142
|
+
hash: h,
|
143
|
+
pairs,
|
144
|
+
});
|
139
145
|
}
|
140
146
|
}
|
141
|
-
let xs = [];
|
142
147
|
for (let [k, v] of groupBuffers) {
|
143
148
|
if (v != null) {
|
144
|
-
xs.push({
|
145
|
-
hash: k,
|
146
|
-
pairs: v,
|
147
|
-
});
|
148
149
|
}
|
149
150
|
else {
|
150
151
|
throw new Error("Expected reference to paris");
|
@@ -156,6 +157,38 @@ export function initTernaryTreeMap(t) {
|
|
156
157
|
// checkMapStructure(result);
|
157
158
|
return result;
|
158
159
|
}
|
160
|
+
// use for..in for performance
|
161
|
+
export function initTernaryTreeMapFromArray(t) {
|
162
|
+
let groupBuffers = {};
|
163
|
+
let xs = [];
|
164
|
+
for (let idx = 0; idx < t.length; idx++) {
|
165
|
+
let k = t[idx][0];
|
166
|
+
let v = t[idx][1];
|
167
|
+
let h = hashGenerator(k);
|
168
|
+
if (groupBuffers[h] != null) {
|
169
|
+
let branch = groupBuffers[h];
|
170
|
+
if (branch != null) {
|
171
|
+
branch.push([k, v]);
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
throw new Error("Expected referece to pairs");
|
175
|
+
}
|
176
|
+
}
|
177
|
+
else {
|
178
|
+
let pairs = [[k, v]];
|
179
|
+
groupBuffers[h] = pairs;
|
180
|
+
xs.push({
|
181
|
+
hash: h,
|
182
|
+
pairs: pairs,
|
183
|
+
});
|
184
|
+
}
|
185
|
+
}
|
186
|
+
// MUTABLE in-place sort
|
187
|
+
xs.sort((a, b) => cmp(a.hash, b.hash));
|
188
|
+
let result = initTernaryTreeMapFromHashEntries(xs);
|
189
|
+
// checkMapStructure(result);
|
190
|
+
return result;
|
191
|
+
}
|
159
192
|
// for empty map
|
160
193
|
export function initEmptyTernaryTreeMap() {
|
161
194
|
let result = emptyBranch;
|
@@ -593,7 +626,7 @@ function assocExisted(tree, key, item, thisHash = null) {
|
|
593
626
|
left: assocExisted(tree.left, key, item, thisHash),
|
594
627
|
middle: tree.middle,
|
595
628
|
right: tree.right,
|
596
|
-
depth: 0,
|
629
|
+
depth: 0, // TODO
|
597
630
|
};
|
598
631
|
return result;
|
599
632
|
}
|
@@ -608,7 +641,7 @@ function assocExisted(tree, key, item, thisHash = null) {
|
|
608
641
|
left: tree.left,
|
609
642
|
middle: assocExisted(tree.middle, key, item, thisHash),
|
610
643
|
right: tree.right,
|
611
|
-
depth: 0,
|
644
|
+
depth: 0, // TODO
|
612
645
|
};
|
613
646
|
return result;
|
614
647
|
}
|
@@ -623,7 +656,7 @@ function assocExisted(tree, key, item, thisHash = null) {
|
|
623
656
|
left: tree.left,
|
624
657
|
middle: tree.middle,
|
625
658
|
right: assocExisted(tree.right, key, item, thisHash),
|
626
|
-
depth: 0,
|
659
|
+
depth: 0, // TODO
|
627
660
|
};
|
628
661
|
return result;
|
629
662
|
}
|
@@ -649,7 +682,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
649
682
|
left: tree,
|
650
683
|
middle: childBranch,
|
651
684
|
right: emptyBranch,
|
652
|
-
depth: 0,
|
685
|
+
depth: 0, // TODO
|
653
686
|
};
|
654
687
|
return result;
|
655
688
|
}
|
@@ -666,7 +699,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
666
699
|
left: childBranch,
|
667
700
|
middle: tree,
|
668
701
|
right: emptyBranch,
|
669
|
-
depth: 0,
|
702
|
+
depth: 0, // TODO
|
670
703
|
};
|
671
704
|
return result;
|
672
705
|
}
|
@@ -707,7 +740,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
707
740
|
left: childBranch,
|
708
741
|
middle: tree.left,
|
709
742
|
right: tree.middle,
|
710
|
-
depth: 0,
|
743
|
+
depth: 0, // TODO
|
711
744
|
};
|
712
745
|
return result;
|
713
746
|
}
|
@@ -724,7 +757,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
724
757
|
left: childBranch,
|
725
758
|
middle: tree,
|
726
759
|
right: emptyBranch,
|
727
|
-
depth: 0,
|
760
|
+
depth: 0, // TODO
|
728
761
|
};
|
729
762
|
return result;
|
730
763
|
}
|
@@ -744,7 +777,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
744
777
|
left: tree.left,
|
745
778
|
middle: childBranch,
|
746
779
|
right: emptyBranch,
|
747
|
-
depth: 0,
|
780
|
+
depth: 0, // TODO
|
748
781
|
};
|
749
782
|
return result;
|
750
783
|
}
|
@@ -761,7 +794,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
761
794
|
left: tree.left,
|
762
795
|
middle: tree.middle,
|
763
796
|
right: childBranch,
|
764
|
-
depth: 0,
|
797
|
+
depth: 0, // TODO
|
765
798
|
};
|
766
799
|
return result;
|
767
800
|
}
|
@@ -778,7 +811,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
778
811
|
left: tree,
|
779
812
|
middle: childBranch,
|
780
813
|
right: emptyBranch,
|
781
|
-
depth: 0,
|
814
|
+
depth: 0, // TODO
|
782
815
|
};
|
783
816
|
return result;
|
784
817
|
}
|
@@ -791,7 +824,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
791
824
|
left: assocNew(tree.left, key, item, thisHash),
|
792
825
|
middle: tree.middle,
|
793
826
|
right: tree.right,
|
794
|
-
depth: 0,
|
827
|
+
depth: 0, // TODO
|
795
828
|
};
|
796
829
|
return result;
|
797
830
|
}
|
@@ -803,7 +836,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
803
836
|
left: tree.left,
|
804
837
|
middle: assocNew(tree.middle, key, item, thisHash),
|
805
838
|
right: tree.right,
|
806
|
-
depth: 0,
|
839
|
+
depth: 0, // TODO
|
807
840
|
};
|
808
841
|
return result;
|
809
842
|
}
|
@@ -815,7 +848,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
815
848
|
left: tree.left,
|
816
849
|
middle: tree.middle,
|
817
850
|
right: assocNew(tree.right, key, item, thisHash),
|
818
|
-
depth: 0,
|
851
|
+
depth: 0, // TODO
|
819
852
|
};
|
820
853
|
return result;
|
821
854
|
}
|
@@ -830,7 +863,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
830
863
|
left: assocNew(tree.left, key, item, thisHash),
|
831
864
|
middle: tree.middle,
|
832
865
|
right: tree.right,
|
833
|
-
depth: 0,
|
866
|
+
depth: 0, // TODO
|
834
867
|
};
|
835
868
|
return result;
|
836
869
|
}
|
@@ -842,7 +875,7 @@ function assocNew(tree, key, item, thisHash = null) {
|
|
842
875
|
left: tree.left,
|
843
876
|
middle: tree.middle,
|
844
877
|
right: assocNew(tree.right, key, item, thisHash),
|
845
|
-
depth: 0,
|
878
|
+
depth: 0, // TODO
|
846
879
|
};
|
847
880
|
return result;
|
848
881
|
}
|
@@ -905,7 +938,7 @@ function dissocExisted(tree, key) {
|
|
905
938
|
left: tree.middle,
|
906
939
|
middle: tree.right,
|
907
940
|
right: emptyBranch,
|
908
|
-
depth: 0,
|
941
|
+
depth: 0, // TODO
|
909
942
|
};
|
910
943
|
return result;
|
911
944
|
}
|
@@ -917,7 +950,7 @@ function dissocExisted(tree, key) {
|
|
917
950
|
left: changedBranch,
|
918
951
|
middle: tree.middle,
|
919
952
|
right: tree.right,
|
920
|
-
depth: 0,
|
953
|
+
depth: 0, // TODO
|
921
954
|
};
|
922
955
|
return result;
|
923
956
|
}
|
@@ -935,7 +968,7 @@ function dissocExisted(tree, key) {
|
|
935
968
|
left: tree.left,
|
936
969
|
middle: tree.right,
|
937
970
|
right: emptyBranch,
|
938
|
-
depth: 0,
|
971
|
+
depth: 0, // TODO
|
939
972
|
};
|
940
973
|
return result;
|
941
974
|
}
|
@@ -947,7 +980,7 @@ function dissocExisted(tree, key) {
|
|
947
980
|
left: tree.left,
|
948
981
|
middle: changedBranch,
|
949
982
|
right: tree.right,
|
950
|
-
depth: 0,
|
983
|
+
depth: 0, // TODO
|
951
984
|
};
|
952
985
|
return result;
|
953
986
|
}
|
@@ -962,7 +995,7 @@ function dissocExisted(tree, key) {
|
|
962
995
|
left: tree.left,
|
963
996
|
middle: tree.middle,
|
964
997
|
right: emptyBranch,
|
965
|
-
depth: 0,
|
998
|
+
depth: 0, // TODO
|
966
999
|
};
|
967
1000
|
return result;
|
968
1001
|
}
|
@@ -974,7 +1007,7 @@ function dissocExisted(tree, key) {
|
|
974
1007
|
left: tree.left,
|
975
1008
|
middle: tree.middle,
|
976
1009
|
right: changedBranch,
|
977
|
-
depth: 0,
|
1010
|
+
depth: 0, // TODO
|
978
1011
|
};
|
979
1012
|
return result;
|
980
1013
|
}
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { listToString, initTernaryTreeList, indexOf, findIndex, reverse, checkListStructure, slice, listToPairs, listToItems, formatListInline, sameListShape, assocBefore, concat, assocAfter, prepend, append, rest, butlast, first, assocList, dissocList, listGet, insert, initEmptyTernaryTreeList, last, listLen, forceListInplaceBalancing, listEqual, indexToItems, listMapValues, } from "./list";
|
2
|
-
import { test, check, arrayEqual, checkEqual } from "./utils";
|
1
|
+
import { listToString, initTernaryTreeList, initTernaryTreeListFromRange, indexOf, findIndex, reverse, checkListStructure, slice, listToPairs, listToItems, formatListInline, sameListShape, assocBefore, concat, assocAfter, prepend, append, rest, butlast, first, assocList, dissocList, listGet, insert, initEmptyTernaryTreeList, last, listLen, forceListInplaceBalancing, listEqual, indexToItems, listMapValues, } from "./list.mjs";
|
2
|
+
import { test, check, arrayEqual, checkEqual } from "./utils.mjs";
|
3
3
|
export let runListTests = () => {
|
4
4
|
test("init list", () => {
|
5
5
|
check(listToString(initTernaryTreeList([1, 2, 3, 4])) === "TernaryTreeList[4, ...]");
|
@@ -89,6 +89,9 @@ export let runListTests = () => {
|
|
89
89
|
let data4 = initTernaryTreeList(origin4);
|
90
90
|
let data4n = initTernaryTreeList(origin4);
|
91
91
|
let data4Made = prepend(initTernaryTreeList([2, 3, 4]), 1);
|
92
|
+
checkListStructure(data4);
|
93
|
+
checkListStructure(data4n);
|
94
|
+
checkListStructure(data4Made);
|
92
95
|
check(sameListShape(data4, data4) === true);
|
93
96
|
check(sameListShape(data4, data4n) === true);
|
94
97
|
check(sameListShape(data4, data4Made) === false);
|
@@ -101,6 +104,7 @@ export let runListTests = () => {
|
|
101
104
|
var data = initTernaryTreeList([]);
|
102
105
|
for (let idx = 0; idx < 20; idx++) {
|
103
106
|
data = append(data, idx, true);
|
107
|
+
checkListStructure(data);
|
104
108
|
}
|
105
109
|
// echo data.formatInline
|
106
110
|
check(formatListInline(data) === "(((0 1 2) (3 4 5) (6 7 8)) ((9 10 11) (12 13 14) (15 16 17)) (18 19 _))");
|
@@ -111,6 +115,7 @@ export let runListTests = () => {
|
|
111
115
|
test("iterator", () => {
|
112
116
|
let origin4 = [1, 2, 3, 4];
|
113
117
|
let data4 = initTernaryTreeList(origin4);
|
118
|
+
checkListStructure(data4);
|
114
119
|
var i = 0;
|
115
120
|
for (let item of listToItems(data4)) {
|
116
121
|
i = i + 1;
|
@@ -126,11 +131,18 @@ export let runListTests = () => {
|
|
126
131
|
var data = initTernaryTreeList([]);
|
127
132
|
for (let idx = 0; idx < 20; idx++) {
|
128
133
|
data = append(data, idx, true);
|
134
|
+
checkListStructure(data);
|
129
135
|
}
|
130
136
|
check(checkListStructure(data));
|
137
|
+
for (let idx = 0; idx < 20; idx++) {
|
138
|
+
data = rest(data);
|
139
|
+
checkListStructure(data);
|
140
|
+
}
|
131
141
|
let origin11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
132
142
|
let data11 = initTernaryTreeList(origin11);
|
133
143
|
check(checkListStructure(data11));
|
144
|
+
checkListStructure(prepend(initEmptyTernaryTreeList(), 1));
|
145
|
+
checkListStructure(prepend(null, 1));
|
134
146
|
});
|
135
147
|
test("slices", () => {
|
136
148
|
var data = initTernaryTreeList([]);
|
@@ -144,6 +156,7 @@ export let runListTests = () => {
|
|
144
156
|
for (let i = 0; i < 40; i++) {
|
145
157
|
for (let j = i; j < 40; j++) {
|
146
158
|
check(arrayEqual([...listToItems(slice(data, i, j))], list40.slice(i, j)));
|
159
|
+
checkListStructure(slice(data, i, j));
|
147
160
|
}
|
148
161
|
}
|
149
162
|
});
|
@@ -156,6 +169,7 @@ export let runListTests = () => {
|
|
156
169
|
test("list traverse", () => {
|
157
170
|
var i = 0;
|
158
171
|
let data = initTernaryTreeList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
172
|
+
checkListStructure(data);
|
159
173
|
for (let x of listToItems(data)) {
|
160
174
|
i = i + 1;
|
161
175
|
}
|
@@ -174,6 +188,13 @@ export let runListTests = () => {
|
|
174
188
|
let data3 = listMapValues(data, (x) => x * x);
|
175
189
|
checkListStructure(data3);
|
176
190
|
check(listEqual(data2, data3));
|
177
|
-
check(formatListInline(data2)
|
191
|
+
check(formatListInline(data2) === formatListInline(data3));
|
192
|
+
});
|
193
|
+
test("concat", () => {
|
194
|
+
let data1 = initTernaryTreeList([3, 4]);
|
195
|
+
let data2 = initTernaryTreeListFromRange([1, 2, 3, 4, 5, 6], 2, 4);
|
196
|
+
check(listEqual(data1, data2));
|
197
|
+
checkListStructure(data1);
|
198
|
+
checkListStructure(data2);
|
178
199
|
});
|
179
200
|
};
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { hashGenerator } from "./types";
|
2
|
-
import { test, check, cmp, deepEqual, justDisplay } from "./utils";
|
3
|
-
import { initTernaryTreeMap, toHashSortedPairs, merge, mergeSkip, formatMapInline, assocMap, dissocMap, contains, toPairs, initEmptyTernaryTreeMap, sameMapShape, checkMapStructure, mapLen, mapEqual, toKeys, toPairsArray, mapMapValues, mapGetDefault, } from "./map";
|
1
|
+
import { hashGenerator } from "./types.mjs";
|
2
|
+
import { test, check, cmp, deepEqual, justDisplay } from "./utils.mjs";
|
3
|
+
import { initTernaryTreeMap, initTernaryTreeMapFromArray, toHashSortedPairs, merge, mergeSkip, formatMapInline, assocMap, dissocMap, contains, toPairs, initEmptyTernaryTreeMap, sameMapShape, checkMapStructure, mapLen, mapEqual, toKeys, toPairsArray, mapMapValues, mapGetDefault, } from "./map.mjs";
|
4
4
|
export let runMapTests = () => {
|
5
5
|
test("init map", () => {
|
6
6
|
var dict = new Map();
|
@@ -16,15 +16,15 @@ export let runMapTests = () => {
|
|
16
16
|
return cmp(hx, hy);
|
17
17
|
});
|
18
18
|
let data10 = initTernaryTreeMap(dict);
|
19
|
-
let data11 =
|
19
|
+
let data11 = initTernaryTreeMapFromArray(inList);
|
20
20
|
checkMapStructure(data10);
|
21
21
|
checkMapStructure(data11);
|
22
22
|
// echo data10
|
23
23
|
justDisplay(formatMapInline(data10, true), " ((0:10 1:11 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19))");
|
24
24
|
check(deepEqual(toHashSortedPairs(data10), inList));
|
25
25
|
check(deepEqual(toHashSortedPairs(data11), inList));
|
26
|
-
check(contains(data10, "1")
|
27
|
-
check(contains(data10, "11")
|
26
|
+
check(contains(data10, "1") === true);
|
27
|
+
check(contains(data10, "11") === false);
|
28
28
|
check(deepEqual(mapGetDefault(data10, "1", null), 11));
|
29
29
|
check(deepEqual(mapGetDefault(data10, "111", 0), 0));
|
30
30
|
// check(deepEqual(mapGetDefault(data10, "11", {} as any), null)); // should throws error
|
@@ -65,8 +65,8 @@ export let runMapTests = () => {
|
|
65
65
|
}
|
66
66
|
let data = initTernaryTreeMap(dict);
|
67
67
|
// echo data.formatInline
|
68
|
-
check(contains(data, "1")
|
69
|
-
check(contains(data, "12")
|
68
|
+
check(contains(data, "1") === true);
|
69
|
+
check(contains(data, "12") === false);
|
70
70
|
checkMapStructure(data);
|
71
71
|
justDisplay(formatMapInline(assocMap(data, "1", 2222), true), "((0:10 1:2222 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19))");
|
72
72
|
justDisplay(formatMapInline(assocMap(data, "23", 2222), true), "(((0:10 1:11 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19)) 23:2222 _)");
|
@@ -81,14 +81,14 @@ export let runMapTests = () => {
|
|
81
81
|
// echo data.formatInline
|
82
82
|
for (let idx = 0; idx < 10; idx++) {
|
83
83
|
let v = dissocMap(data, `${idx}`);
|
84
|
-
check(contains(v, `${idx}`)
|
85
|
-
check(contains(data, `${idx}`)
|
86
|
-
check(mapLen(v)
|
84
|
+
check(contains(v, `${idx}`) === false);
|
85
|
+
check(contains(data, `${idx}`) === true);
|
86
|
+
check(mapLen(v) === mapLen(data) - 1);
|
87
87
|
}
|
88
88
|
for (let idx = 10; idx < 12; idx++) {
|
89
89
|
let v = dissocMap(data, `${idx}`);
|
90
|
-
check(contains(v, `${idx}`)
|
91
|
-
check(mapLen(v)
|
90
|
+
check(contains(v, `${idx}`) === false);
|
91
|
+
check(mapLen(v) === mapLen(data));
|
92
92
|
}
|
93
93
|
});
|
94
94
|
test("to array", () => {
|
@@ -116,8 +116,8 @@ export let runMapTests = () => {
|
|
116
116
|
check(!mapEqual(data, b));
|
117
117
|
let c = assocMap(data, "3", 15);
|
118
118
|
check(sameMapShape(data, data));
|
119
|
-
check(sameMapShape(data, b)
|
120
|
-
check(sameMapShape(data, c)
|
119
|
+
check(sameMapShape(data, b) === false);
|
120
|
+
check(sameMapShape(data, c) === false);
|
121
121
|
let d = assocMap(c, "3", 13);
|
122
122
|
check(mapEqual(data, d));
|
123
123
|
check(data !== d); // not identical
|
@@ -173,12 +173,12 @@ export let runMapTests = () => {
|
|
173
173
|
for (let [k, v] of toPairs(data)) {
|
174
174
|
i = i + 1;
|
175
175
|
}
|
176
|
-
check(i
|
176
|
+
check(i === 4);
|
177
177
|
i = 0;
|
178
178
|
for (let key of toPairs(data)) {
|
179
179
|
i = i + 1;
|
180
180
|
}
|
181
|
-
check(i
|
181
|
+
check(i === 4);
|
182
182
|
});
|
183
183
|
test("each map", () => {
|
184
184
|
var dict = new Map();
|
@@ -192,7 +192,7 @@ export let runMapTests = () => {
|
|
192
192
|
// echo "..{k}-{v}.."
|
193
193
|
i = i + 1;
|
194
194
|
}
|
195
|
-
check(i
|
195
|
+
check(i === 100);
|
196
196
|
});
|
197
197
|
test("map values", () => {
|
198
198
|
var dict = new Map();
|
File without changes
|
File without changes
|
@@ -15,6 +15,6 @@ export declare let check: (x: boolean) => void;
|
|
15
15
|
/** compare by reference */
|
16
16
|
export declare let checkEqual: (x: any, y: any) => void;
|
17
17
|
export declare let justDisplay: (x: any, y: any) => void;
|
18
|
-
export declare let cmp: (x: any, y: any) =>
|
18
|
+
export declare let cmp: (x: any, y: any) => 0 | 1 | -1;
|
19
19
|
export declare let deepEqual: (x: any, y: any) => boolean;
|
20
|
-
export declare
|
20
|
+
export declare function arrayEqual<T>(xs: Array<T>, ys: Array<T>): boolean;
|
@@ -85,7 +85,7 @@ export let deepEqual = function (x, y) {
|
|
85
85
|
if (x === y) {
|
86
86
|
return true;
|
87
87
|
}
|
88
|
-
else if (typeof x
|
88
|
+
else if (typeof x === "object" && x != null && typeof y === "object" && y != null) {
|
89
89
|
if (Object.keys(x).length != Object.keys(y).length)
|
90
90
|
return false;
|
91
91
|
for (var prop in x) {
|
@@ -101,7 +101,7 @@ export let deepEqual = function (x, y) {
|
|
101
101
|
else
|
102
102
|
return false;
|
103
103
|
};
|
104
|
-
export
|
104
|
+
export function arrayEqual(xs, ys) {
|
105
105
|
if (xs.length != ys.length) {
|
106
106
|
return false;
|
107
107
|
}
|
@@ -111,4 +111,4 @@ export let arrayEqual = (xs, ys) => {
|
|
111
111
|
}
|
112
112
|
}
|
113
113
|
return true;
|
114
|
-
}
|
114
|
+
}
|
package/package.json
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "@calcit/ternary-tree",
|
3
|
-
"version": "0.0.
|
4
|
-
"main": "./lib/index.
|
3
|
+
"version": "0.0.19-a1",
|
4
|
+
"main": "./lib/index.mjs",
|
5
|
+
"scripts": {
|
6
|
+
"bundle": "esbuild src/main.mts --bundle --outfile=lib/bundle.js --platform=node --resolve-extensions=.mjs,.mts,.ts,.js"
|
7
|
+
},
|
5
8
|
"devDependencies": {
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"webpack-cli": "^4.4.0"
|
9
|
+
"esbuild": "^0.14.27",
|
10
|
+
"prettier": "^2.6.0",
|
11
|
+
"typescript": "^4.6.2",
|
12
|
+
"vite": "^2.8.6"
|
11
13
|
}
|
12
14
|
}
|
package/assets/index.html
DELETED