@calcit/procs 0.5.38 → 0.5.41

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.
@@ -3,7 +3,7 @@ import { overwriteComparator } from "@calcit/ternary-tree";
3
3
  import { overwriteMapComparator } from "./js-map.mjs";
4
4
  import { CalcitRecord, fieldsEqual } from "./js-record.mjs";
5
5
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
6
- import "./js-primes.mjs";
6
+ import { _$n_compare } from "./js-primes.mjs";
7
7
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
8
8
  import { CalcitSet, overwriteSetComparator } from "./js-set.mjs";
9
9
  import { CalcitTuple } from "./js-tuple.mjs";
@@ -220,9 +220,10 @@ export let hashFunction = (x) => {
220
220
  return base;
221
221
  }
222
222
  if (x instanceof CalcitSet) {
223
- // TODO not using dirty solution for code
224
223
  let base = defaultHash_set;
225
224
  let values = x.values();
225
+ // sort elements for stable hash result
226
+ values.sort((a, b) => _$n_compare(a, b));
226
227
  for (let idx = 0; idx < values.length; idx++) {
227
228
  let item = values[idx];
228
229
  base = mergeValueHash(base, hashFunction(item));
@@ -249,7 +250,9 @@ export let hashFunction = (x) => {
249
250
  }
250
251
  if (x instanceof CalcitSliceMap) {
251
252
  let base = defaultHash_map;
252
- for (let [k, v] of x.pairs()) {
253
+ let pairs = x.pairs();
254
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
255
+ for (let [k, v] of pairs) {
253
256
  base = mergeValueHash(base, hashFunction(k));
254
257
  base = mergeValueHash(base, hashFunction(v));
255
258
  }
@@ -258,7 +261,9 @@ export let hashFunction = (x) => {
258
261
  }
259
262
  if (x instanceof CalcitMap) {
260
263
  let base = defaultHash_map;
261
- for (let [k, v] of x.pairs()) {
264
+ let pairs = x.pairs();
265
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
266
+ for (let [k, v] of pairs) {
262
267
  base = mergeValueHash(base, hashFunction(k));
263
268
  base = mergeValueHash(base, hashFunction(v));
264
269
  }
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.5.38";
3
+ export const calcit_version = "0.5.41";
4
4
  import { parse } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
6
6
  import "./js-primes.mjs";
package/lib/js-list.mjs CHANGED
@@ -110,7 +110,10 @@ export class CalcitSliceList {
110
110
  return this.end - this.start;
111
111
  }
112
112
  get(idx) {
113
- return this.value[this.start + idx];
113
+ if (idx >= 0 && this.start + idx < this.end) {
114
+ return this.value[this.start + idx];
115
+ }
116
+ return null;
114
117
  }
115
118
  assoc(idx, v) {
116
119
  return this.turnListMode().assoc(idx, v);
@@ -147,6 +150,10 @@ export class CalcitSliceList {
147
150
  if (to < from) {
148
151
  throw new Error("end index too small");
149
152
  }
153
+ if (from === to) {
154
+ // when it's empty, just return empty list
155
+ return new CalcitSliceList([]);
156
+ }
150
157
  let result = new CalcitSliceList(this.value);
151
158
  result.start = this.start + from;
152
159
  result.end = this.start + to;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.5.38",
3
+ "version": "0.5.41",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
- "@types/node": "^17.0.23",
6
+ "@types/node": "^17.0.29",
7
7
  "typescript": "^4.6.3"
8
8
  },
9
9
  "scripts": {
@@ -5,7 +5,7 @@ import { overwriteMapComparator } from "./js-map.mjs";
5
5
  import { CalcitRecord, fieldsEqual } from "./js-record.mjs";
6
6
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
7
7
 
8
- import { CalcitValue } from "./js-primes.mjs";
8
+ import { CalcitValue, _$n_compare } from "./js-primes.mjs";
9
9
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
10
10
  import { CalcitSet, overwriteSetComparator } from "./js-set.mjs";
11
11
  import { CalcitTuple } from "./js-tuple.mjs";
@@ -251,9 +251,10 @@ export let hashFunction = (x: CalcitValue): Hash => {
251
251
  return base;
252
252
  }
253
253
  if (x instanceof CalcitSet) {
254
- // TODO not using dirty solution for code
255
254
  let base = defaultHash_set;
256
255
  let values = x.values();
256
+ // sort elements for stable hash result
257
+ values.sort((a, b) => _$n_compare(a, b));
257
258
  for (let idx = 0; idx < values.length; idx++) {
258
259
  let item = values[idx];
259
260
  base = mergeValueHash(base, hashFunction(item));
@@ -280,7 +281,9 @@ export let hashFunction = (x: CalcitValue): Hash => {
280
281
  }
281
282
  if (x instanceof CalcitSliceMap) {
282
283
  let base = defaultHash_map;
283
- for (let [k, v] of x.pairs()) {
284
+ let pairs = x.pairs();
285
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
286
+ for (let [k, v] of pairs) {
284
287
  base = mergeValueHash(base, hashFunction(k));
285
288
  base = mergeValueHash(base, hashFunction(v));
286
289
  }
@@ -289,7 +292,10 @@ export let hashFunction = (x: CalcitValue): Hash => {
289
292
  }
290
293
  if (x instanceof CalcitMap) {
291
294
  let base = defaultHash_map;
292
- for (let [k, v] of x.pairs()) {
295
+
296
+ let pairs = x.pairs();
297
+ pairs.sort((a, b) => _$n_compare(a[0], b[0]));
298
+ for (let [k, v] of pairs) {
293
299
  base = mergeValueHash(base, hashFunction(k));
294
300
  base = mergeValueHash(base, hashFunction(v));
295
301
  }
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.5.38";
2
+ export const calcit_version = "0.5.41";
3
3
 
4
4
  import { parse, ICirruNode } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -132,7 +132,10 @@ export class CalcitSliceList {
132
132
  return this.end - this.start;
133
133
  }
134
134
  get(idx: number) {
135
- return this.value[this.start + idx];
135
+ if (idx >= 0 && this.start + idx < this.end) {
136
+ return this.value[this.start + idx];
137
+ }
138
+ return null;
136
139
  }
137
140
  assoc(idx: number, v: CalcitValue) {
138
141
  return this.turnListMode().assoc(idx, v);
@@ -166,6 +169,10 @@ export class CalcitSliceList {
166
169
  if (to < from) {
167
170
  throw new Error("end index too small");
168
171
  }
172
+ if (from === to) {
173
+ // when it's empty, just return empty list
174
+ return new CalcitSliceList([]);
175
+ }
169
176
  let result = new CalcitSliceList(this.value);
170
177
  result.start = this.start + from;
171
178
  result.end = this.start + to;