@calcit/ternary-tree 0.0.18 → 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.
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ export * from "./types.mjs";
2
+ export * from "./map.mjs";
3
+ export * from "./list.mjs";
4
+ export { overwriteComparator } from "./utils.mjs";
package/lib/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./types.mjs";
2
+ export * from "./map.mjs";
3
+ export * from "./list.mjs";
4
+ export { overwriteComparator } from "./utils.mjs";
@@ -1,4 +1,4 @@
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>;
@@ -1,5 +1,5 @@
1
- import { TernaryTreeKind } from "./types";
2
- import { dataEqual, divideTernarySizes, roughIntPow } from "./utils";
1
+ import { TernaryTreeKind } from "./types.mjs";
2
+ import { dataEqual, divideTernarySizes, roughIntPow } from "./utils.mjs";
3
3
  // just get, will not compute recursively
4
4
  export function getDepth(tree) {
5
5
  if (tree == null)
@@ -797,7 +797,7 @@ export function listEqual(xs, ys) {
797
797
  return true;
798
798
  }
799
799
  export function checkListStructure(tree) {
800
- if (tree == null) {
800
+ if (tree == null || listLen(tree) === 0) {
801
801
  return true;
802
802
  }
803
803
  else {
package/lib/main.d.mts ADDED
@@ -0,0 +1,2 @@
1
+ import "./test-list.mjs";
2
+ import "./test-map.mjs";
@@ -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,4 +1,4 @@
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
4
  export declare function initTernaryTreeMap<K, T>(t: Map<K, T>): TernaryTreeMap<K, T>;
@@ -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) {
File without changes
@@ -1,5 +1,5 @@
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";
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
  }
@@ -180,5 +194,7 @@ export let runListTests = () => {
180
194
  let data1 = initTernaryTreeList([3, 4]);
181
195
  let data2 = initTernaryTreeListFromRange([1, 2, 3, 4, 5, 6], 2, 4);
182
196
  check(listEqual(data1, data2));
197
+ checkListStructure(data1);
198
+ checkListStructure(data2);
183
199
  });
184
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, initTernaryTreeMapFromArray, 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();
File without changes
File without changes
@@ -17,4 +17,4 @@ export declare let checkEqual: (x: any, y: any) => void;
17
17
  export declare let justDisplay: (x: any, y: any) => void;
18
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 let arrayEqual: <T>(xs: T[], ys: T[]) => boolean;
20
+ export declare function arrayEqual<T>(xs: Array<T>, ys: Array<T>): boolean;
@@ -101,7 +101,7 @@ export let deepEqual = function (x, y) {
101
101
  else
102
102
  return false;
103
103
  };
104
- export let arrayEqual = (xs, ys) => {
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.18",
4
- "main": "./lib/index.js",
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
- "prettier": "^2.4.1",
7
- "typescript": "^4.4.4",
8
- "vite": "^2.6.13",
9
- "webpack": "^5.62.1",
10
- "webpack-cli": "^4.9.1"
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
@@ -1,2 +0,0 @@
1
-
2
- <script type="application/javascript" src="bundle.js" ></script>