@elaraai/east 1.0.108 → 1.0.110
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/dist/src/analyze.d.ts.map +1 -1
- package/dist/src/analyze.js +58 -0
- package/dist/src/analyze.js.map +1 -1
- package/dist/src/builtins.d.ts +1 -1
- package/dist/src/builtins.d.ts.map +1 -1
- package/dist/src/builtins.js +25 -0
- package/dist/src/builtins.js.map +1 -1
- package/dist/src/codegen/codegen.spec.js +66 -0
- package/dist/src/codegen/codegen.spec.js.map +1 -1
- package/dist/src/codegen/printer.d.ts.map +1 -1
- package/dist/src/codegen/printer.js +47 -2
- package/dist/src/codegen/printer.js.map +1 -1
- package/dist/src/codegen/spellings.d.ts +7 -5
- package/dist/src/codegen/spellings.d.ts.map +1 -1
- package/dist/src/codegen/spellings.js +4 -0
- package/dist/src/codegen/spellings.js.map +1 -1
- package/dist/src/codegen/spellings.spec.js +2 -1
- package/dist/src/codegen/spellings.spec.js.map +1 -1
- package/dist/src/compile/builtins/dict.d.ts +2 -0
- package/dist/src/compile/builtins/dict.d.ts.map +1 -1
- package/dist/src/compile/builtins/dict.js +6 -0
- package/dist/src/compile/builtins/dict.js.map +1 -1
- package/dist/src/compile/builtins/key_range.d.ts +63 -0
- package/dist/src/compile/builtins/key_range.d.ts.map +1 -0
- package/dist/src/compile/builtins/key_range.js +80 -0
- package/dist/src/compile/builtins/key_range.js.map +1 -0
- package/dist/src/compile/builtins/primitives.d.ts +1 -1
- package/dist/src/compile/builtins/set.d.ts +2 -0
- package/dist/src/compile/builtins/set.d.ts.map +1 -1
- package/dist/src/compile/builtins/set.js +6 -0
- package/dist/src/compile/builtins/set.js.map +1 -1
- package/dist/src/containers/range.d.ts +77 -0
- package/dist/src/containers/range.d.ts.map +1 -0
- package/dist/src/containers/range.js +68 -0
- package/dist/src/containers/range.js.map +1 -0
- package/dist/src/containers/range.spec.d.ts +6 -0
- package/dist/src/containers/range.spec.d.ts.map +1 -0
- package/dist/src/containers/range.spec.js +254 -0
- package/dist/src/containers/range.spec.js.map +1 -0
- package/dist/src/containers/sortedmap.d.ts +25 -0
- package/dist/src/containers/sortedmap.d.ts.map +1 -1
- package/dist/src/containers/sortedmap.js +29 -0
- package/dist/src/containers/sortedmap.js.map +1 -1
- package/dist/src/containers/sortedset.d.ts +26 -0
- package/dist/src/containers/sortedset.d.ts.map +1 -1
- package/dist/src/containers/sortedset.js +30 -0
- package/dist/src/containers/sortedset.js.map +1 -1
- package/dist/src/expr/dict.d.ts +86 -0
- package/dist/src/expr/dict.d.ts.map +1 -1
- package/dist/src/expr/dict.js +106 -0
- package/dist/src/expr/dict.js.map +1 -1
- package/dist/src/expr/key_range.d.ts +105 -0
- package/dist/src/expr/key_range.d.ts.map +1 -0
- package/dist/src/expr/key_range.js +124 -0
- package/dist/src/expr/key_range.js.map +1 -0
- package/dist/src/expr/set.d.ts +74 -0
- package/dist/src/expr/set.d.ts.map +1 -1
- package/dist/src/expr/set.js +94 -0
- package/dist/src/expr/set.js.map +1 -1
- package/dist/src/fuzz.d.ts +13 -0
- package/dist/src/fuzz.d.ts.map +1 -1
- package/dist/src/fuzz.js +26 -11
- package/dist/src/fuzz.js.map +1 -1
- package/dist/src/fuzz.spec.d.ts +6 -0
- package/dist/src/fuzz.spec.d.ts.map +1 -0
- package/dist/src/fuzz.spec.js +45 -0
- package/dist/src/fuzz.spec.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal.d.ts +1 -0
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +2 -0
- package/dist/src/internal.js.map +1 -1
- package/dist/src/key_bound.d.ts +94 -0
- package/dist/src/key_bound.d.ts.map +1 -0
- package/dist/src/key_bound.js +183 -0
- package/dist/src/key_bound.js.map +1 -0
- package/dist/src/key_bound.spec.d.ts +6 -0
- package/dist/src/key_bound.spec.d.ts.map +1 -0
- package/dist/src/key_bound.spec.js +158 -0
- package/dist/src/key_bound.spec.js.map +1 -0
- package/dist/src/serialization/beast2/v5/lazy.d.ts +4 -0
- package/dist/src/serialization/beast2/v5/lazy.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/lazy.js +36 -11
- package/dist/src/serialization/beast2/v5/lazy.js.map +1 -1
- package/dist/src/serialization/beast2/v5/project.spec.js +2 -12
- package/dist/src/serialization/beast2/v5/project.spec.js.map +1 -1
- package/dist/src/serialization/beast2/v5/stream.d.ts +138 -1
- package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/stream.js +224 -1
- package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
- package/dist/src/serialization/beast2/v5/view.d.ts +108 -0
- package/dist/src/serialization/beast2/v5/view.d.ts.map +1 -0
- package/dist/src/serialization/beast2/v5/view.js +227 -0
- package/dist/src/serialization/beast2/v5/view.js.map +1 -0
- package/dist/src/serialization/beast2/v5/view.spec.d.ts +6 -0
- package/dist/src/serialization/beast2/v5/view.spec.d.ts.map +1 -0
- package/dist/src/serialization/beast2/v5/view.spec.js +509 -0
- package/dist/src/serialization/beast2/v5/view.spec.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/** The probe that stands just before the first key the `from` test holds for. */
|
|
6
|
+
const FROM = Object.freeze({ bound: "from" });
|
|
7
|
+
/** The probe that stands just before the first key the `to` test holds for. */
|
|
8
|
+
const TO = Object.freeze({ bound: "to" });
|
|
9
|
+
/**
|
|
10
|
+
* Copies the entries of `source` between two bounds into `into`, in key order.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam K - The type of the keys
|
|
13
|
+
* @typeParam T - The type of the values
|
|
14
|
+
* @param source - The tree to read, which is not written
|
|
15
|
+
* @param into - A new, empty tree with the same comparison as `source`
|
|
16
|
+
* @param from - The test the run's first key is the first to pass; `undefined` for the first key
|
|
17
|
+
* @param to - The test the run stops before the first key to pass; `undefined` for the end
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Costs two searches down `source` and, for each node of the run, two binary
|
|
21
|
+
* searches inside it: fewer calls of the tests than the run has entries, and
|
|
22
|
+
* none for the entries outside it. `into` is built as an ascending insert
|
|
23
|
+
* builds it, node for node.
|
|
24
|
+
*
|
|
25
|
+
* A test that is not false, then true, over the keys in order gives a run that
|
|
26
|
+
* is not defined; a test that throws leaves `into` to be thrown away.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function copyRange(source, into, from, to) {
|
|
31
|
+
const compare = into._compare;
|
|
32
|
+
// How a key stands to a probe: past it once the probe's test holds. A bound left out
|
|
33
|
+
// stands before every key (`from`) or after every key (`to`).
|
|
34
|
+
const stands = (key, probe) => (probe === FROM
|
|
35
|
+
? (from === undefined || from(key) ? 1 : -1)
|
|
36
|
+
: (to !== undefined && to(key) ? 1 : -1));
|
|
37
|
+
// The search's comparison: a key with a probe, either way round, by the probe's test.
|
|
38
|
+
const probing = (a, b) => {
|
|
39
|
+
if (b === FROM || b === TO)
|
|
40
|
+
return stands(a, b);
|
|
41
|
+
if (a === FROM || a === TO)
|
|
42
|
+
return -stands(b, a);
|
|
43
|
+
return compare(a, b);
|
|
44
|
+
};
|
|
45
|
+
const search = Object.create(source, { _compare: { value: probing } });
|
|
46
|
+
// The fill's comparison: the key arriving is past every key held. `Object.is` tells it from
|
|
47
|
+
// the keys held, which differ from it in the tree's order: it tells the two zeros apart, as
|
|
48
|
+
// East's order does, and a NaN from every number.
|
|
49
|
+
let arriving;
|
|
50
|
+
const filling = (a, b) => {
|
|
51
|
+
if (Object.is(b, arriving))
|
|
52
|
+
return Object.is(a, arriving) ? 0 : -1;
|
|
53
|
+
if (Object.is(a, arriving))
|
|
54
|
+
return 1;
|
|
55
|
+
return compare(a, b);
|
|
56
|
+
};
|
|
57
|
+
into._compare = filling;
|
|
58
|
+
try {
|
|
59
|
+
search.forRange(FROM, TO, false, (key, value) => {
|
|
60
|
+
arriving = key;
|
|
61
|
+
into.set(key, value);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
into._compare = compare;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../../src/containers/range.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuDH,iFAAiF;AACjF,MAAM,IAAI,GAAW,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AACtD,+EAA+E;AAC/E,MAAM,EAAE,GAAW,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,SAAS,CAAO,MAAmB,EAAE,IAAiB,EAAE,IAA4B,EAAE,EAA0B;IAC5H,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC9B,qFAAqF;IACrF,8DAA8D;IAC9D,MAAM,MAAM,GAAG,CAAC,GAAM,EAAE,KAAc,EAAU,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI;QAC9D,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,sFAAsF;I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ACP,CAAC;YAAS,CAAC;QACP,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.spec.d.ts","sourceRoot":"","sources":["../../../src/containers/range.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The entries of a sorted map, or the elements of a sorted set, between two
|
|
7
|
+
* bounds (#1616, D3): what a range holds, that it is a new collection and
|
|
8
|
+
* never a frozen one, and what finding it costs — counted, never timed. A
|
|
9
|
+
* range is found by a search down the tree, so its cost follows the range and
|
|
10
|
+
* never the collection: the map's own comparison is not called at all, and
|
|
11
|
+
* the bounds' tests are called fewer times than the range has entries, plus
|
|
12
|
+
* a few for the two searches.
|
|
13
|
+
*/
|
|
14
|
+
import assert from "node:assert/strict";
|
|
15
|
+
import { describe, test } from "node:test";
|
|
16
|
+
import { compareFor } from "../comparison.js";
|
|
17
|
+
import { encodeBeast2SegmentsFor, openBeast2LazyFor } from "../serialization/index.js";
|
|
18
|
+
import { DictType, IntegerType, SetType } from "../types.js";
|
|
19
|
+
import { SortedMap } from "./sortedmap.js";
|
|
20
|
+
import { SortedSet } from "./sortedset.js";
|
|
21
|
+
/** A comparison of numbers that counts its calls. */
|
|
22
|
+
function counting() {
|
|
23
|
+
let calls = 0;
|
|
24
|
+
return {
|
|
25
|
+
compare: (a, b) => { calls += 1; return a < b ? -1 : a > b ? 1 : 0; },
|
|
26
|
+
calls: () => calls,
|
|
27
|
+
reset: () => { calls = 0; },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** The test "at or past `bound`" over numbers, counting its calls. */
|
|
31
|
+
function atOrPast(bound, count) {
|
|
32
|
+
return (key) => { count.calls += 1; return key >= bound; };
|
|
33
|
+
}
|
|
34
|
+
/** A map of the even numbers below `2 * size`, each to its half. */
|
|
35
|
+
function evens(size, compare) {
|
|
36
|
+
const map = new SortedMap(undefined, compare);
|
|
37
|
+
for (let i = 0; i < size; i++)
|
|
38
|
+
map.set(2 * i, i);
|
|
39
|
+
return map;
|
|
40
|
+
}
|
|
41
|
+
describe("the entries of a SortedMap between two bounds (#1616)", () => {
|
|
42
|
+
test("from the first key at or past `from` up to, and not including, the first at or past `to`", () => {
|
|
43
|
+
const map = evens(10);
|
|
44
|
+
const count = { calls: 0 };
|
|
45
|
+
assert.deepEqual([...map.range(atOrPast(4, count), atOrPast(10, count))], [[4, 2], [6, 3], [8, 4]]);
|
|
46
|
+
// A bound between two keys: the next key is the first kept, and the last before it the last.
|
|
47
|
+
assert.deepEqual([...map.range(atOrPast(5, count), atOrPast(11, count)).keys()], [6, 8, 10]);
|
|
48
|
+
});
|
|
49
|
+
test("a bound left out is that end of the map, and both left out is every entry", () => {
|
|
50
|
+
const map = evens(6);
|
|
51
|
+
const count = { calls: 0 };
|
|
52
|
+
assert.deepEqual([...map.range(atOrPast(7, count)).keys()], [8, 10]);
|
|
53
|
+
assert.deepEqual([...map.range(undefined, atOrPast(5, count)).keys()], [0, 2, 4]);
|
|
54
|
+
assert.deepEqual([...map.range()], [...map]);
|
|
55
|
+
});
|
|
56
|
+
test("`from` past `to`, a range past either end, and a range of an empty map hold nothing", () => {
|
|
57
|
+
const map = evens(6);
|
|
58
|
+
const count = { calls: 0 };
|
|
59
|
+
assert.equal(map.range(atOrPast(8, count), atOrPast(2, count)).size, 0);
|
|
60
|
+
assert.equal(map.range(atOrPast(4, count), atOrPast(4, count)).size, 0);
|
|
61
|
+
assert.equal(map.range(atOrPast(100, count)).size, 0);
|
|
62
|
+
assert.equal(map.range(undefined, atOrPast(-1, count)).size, 0);
|
|
63
|
+
assert.equal(new SortedMap().range(atOrPast(1, count), atOrPast(2, count)).size, 0);
|
|
64
|
+
});
|
|
65
|
+
test("every range of a map of 3,000 keys is what a walk of the whole keeps, for bounds on, between and beyond its keys", () => {
|
|
66
|
+
const map = evens(3_000);
|
|
67
|
+
const all = [...map];
|
|
68
|
+
const count = { calls: 0 };
|
|
69
|
+
const bounds = [-3, 0, 1, 2, 31, 32, 33, 63, 64, 1_000, 1_023, 1_024, 2_999, 3_000, 5_997, 5_998, 5_999, 7_000];
|
|
70
|
+
for (const from of bounds) {
|
|
71
|
+
for (const to of bounds) {
|
|
72
|
+
const kept = all.filter(([key]) => key >= from && !(key >= to));
|
|
73
|
+
assert.deepEqual([...map.range(atOrPast(from, count), atOrPast(to, count))], kept, `from ${from} to ${to}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
test("a range is a new map with the source's comparison: read by key, added to and iterated from a key as any map is", () => {
|
|
78
|
+
const order = counting();
|
|
79
|
+
const map = evens(500, order.compare);
|
|
80
|
+
const count = { calls: 0 };
|
|
81
|
+
const range = map.range(atOrPast(100, count), atOrPast(300, count));
|
|
82
|
+
assert.equal(range.size, 100);
|
|
83
|
+
for (let key = 100; key < 300; key += 2)
|
|
84
|
+
assert.equal(range.get(key), key / 2);
|
|
85
|
+
assert.equal(range.get(98), undefined);
|
|
86
|
+
assert.equal(range.has(300), false);
|
|
87
|
+
assert.equal(range.minKey(), 100);
|
|
88
|
+
assert.equal(range.maxKey(), 298);
|
|
89
|
+
// Added to, in and out of order, it stays sorted: the comparison is the source's again.
|
|
90
|
+
range.set(151, -1).set(50, -2).set(400, -3);
|
|
91
|
+
assert.deepEqual([...range.keys(149)].slice(0, 3), [150, 151, 152]);
|
|
92
|
+
assert.deepEqual([[...range.keys()][0], [...range.keys()].at(-1)], [50, 400]);
|
|
93
|
+
assert.equal(range.size, 103);
|
|
94
|
+
// The source is as it was.
|
|
95
|
+
assert.equal(map.size, 500);
|
|
96
|
+
assert.equal(map.has(151), false);
|
|
97
|
+
});
|
|
98
|
+
test("a range of a frozen map is not frozen, and the frozen map is left as it is", () => {
|
|
99
|
+
const map = evens(40);
|
|
100
|
+
Object.freeze(map);
|
|
101
|
+
const count = { calls: 0 };
|
|
102
|
+
const range = map.range(atOrPast(10, count), atOrPast(20, count));
|
|
103
|
+
assert.equal(Object.isFrozen(range), false);
|
|
104
|
+
range.set(11, 0);
|
|
105
|
+
range.delete(10);
|
|
106
|
+
assert.deepEqual([...range.keys()], [11, 12, 14, 16, 18]);
|
|
107
|
+
assert.equal(map.size, 40);
|
|
108
|
+
assert.throws(() => map.set(11, 0), TypeError);
|
|
109
|
+
});
|
|
110
|
+
test("the values a range holds are the source's own", () => {
|
|
111
|
+
const first = { n: 1 };
|
|
112
|
+
const second = { n: 2 };
|
|
113
|
+
const map = new SortedMap([[1, first], [2, second]]);
|
|
114
|
+
assert.equal(map.range((key) => key >= 2).get(2), second);
|
|
115
|
+
});
|
|
116
|
+
test("a test that throws leaves the source as it was, its comparison its own", () => {
|
|
117
|
+
const order = counting();
|
|
118
|
+
const map = evens(200, order.compare);
|
|
119
|
+
assert.throws(() => map.range(() => { throw new Error("no"); }), /no/);
|
|
120
|
+
order.reset();
|
|
121
|
+
assert.equal(map.get(100), 50);
|
|
122
|
+
assert.ok(order.calls() > 0, "the map's own comparison answers a keyed read again");
|
|
123
|
+
assert.deepEqual([...map.range((key) => key >= 396)].map(([key]) => key), [396, 398]);
|
|
124
|
+
});
|
|
125
|
+
test("a range is found by a search: the map's comparison is never called, and the tests fewer times than the range has entries", () => {
|
|
126
|
+
const order = counting();
|
|
127
|
+
const size = 100_000;
|
|
128
|
+
const map = evens(size, order.compare);
|
|
129
|
+
// The two searches come to a few binary searches down the tree: far below the map's size.
|
|
130
|
+
const SEARCH = 200;
|
|
131
|
+
const cases = [
|
|
132
|
+
[100_000, 100_100], // 50 entries in the middle
|
|
133
|
+
[0, 20], // 10 at the start
|
|
134
|
+
[199_980, 200_000], // 10 at the end
|
|
135
|
+
[100_001, 100_001], // none
|
|
136
|
+
[60_000, 140_000], // 40,000 across many nodes
|
|
137
|
+
];
|
|
138
|
+
for (const [from, to] of cases) {
|
|
139
|
+
order.reset();
|
|
140
|
+
const count = { calls: 0 };
|
|
141
|
+
const range = map.range(atOrPast(from, count), atOrPast(to, count));
|
|
142
|
+
const kept = Math.max(0, Math.ceil((to - from) / 2));
|
|
143
|
+
assert.equal(range.size, kept, `from ${from} to ${to}`);
|
|
144
|
+
assert.equal(order.calls(), 0, `the map's comparison, from ${from} to ${to}`);
|
|
145
|
+
assert.ok(count.calls <= kept + SEARCH, `${count.calls} test calls for ${kept} entries, from ${from} to ${to}`);
|
|
146
|
+
}
|
|
147
|
+
// An end left out costs nothing: its test is never made.
|
|
148
|
+
order.reset();
|
|
149
|
+
const count = { calls: 0 };
|
|
150
|
+
assert.equal(map.range(undefined, atOrPast(20, count)).size, 10);
|
|
151
|
+
assert.ok(count.calls <= SEARCH, `${count.calls} test calls for an open start`);
|
|
152
|
+
assert.equal(order.calls(), 0);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe("the elements of a SortedSet between two bounds (#1616)", () => {
|
|
156
|
+
/** The multiples of three below `3 * size`. */
|
|
157
|
+
const threes = (size, compare) => {
|
|
158
|
+
const set = new SortedSet(undefined, compare);
|
|
159
|
+
for (let i = 0; i < size; i++)
|
|
160
|
+
set.add(3 * i);
|
|
161
|
+
return set;
|
|
162
|
+
};
|
|
163
|
+
test("the elements a walk of the whole keeps, for bounds on, between and beyond its elements; an end left out is that end", () => {
|
|
164
|
+
const set = threes(2_000);
|
|
165
|
+
const all = [...set];
|
|
166
|
+
const count = { calls: 0 };
|
|
167
|
+
const bounds = [-1, 0, 1, 3, 95, 96, 97, 3_000, 5_996, 5_997, 5_998, 9_000];
|
|
168
|
+
for (const from of bounds) {
|
|
169
|
+
for (const to of bounds) {
|
|
170
|
+
assert.deepEqual([...set.range(atOrPast(from, count), atOrPast(to, count))], all.filter((key) => key >= from && !(key >= to)), `from ${from} to ${to}`);
|
|
171
|
+
}
|
|
172
|
+
assert.deepEqual([...set.range(atOrPast(from, count))], all.filter((key) => key >= from), `from ${from}`);
|
|
173
|
+
assert.deepEqual([...set.range(undefined, atOrPast(from, count))], all.filter((key) => !(key >= from)), `to ${from}`);
|
|
174
|
+
}
|
|
175
|
+
assert.deepEqual([...set.range()], all);
|
|
176
|
+
assert.equal(new SortedSet().range(atOrPast(1, count)).size, 0);
|
|
177
|
+
});
|
|
178
|
+
test("a range is a new set with the source's comparison, never frozen, and the source is left as it is", () => {
|
|
179
|
+
const order = counting();
|
|
180
|
+
const set = threes(300, order.compare);
|
|
181
|
+
Object.freeze(set);
|
|
182
|
+
const count = { calls: 0 };
|
|
183
|
+
const range = set.range(atOrPast(30, count), atOrPast(45, count));
|
|
184
|
+
assert.deepEqual([...range], [30, 33, 36, 39, 42]);
|
|
185
|
+
assert.equal(Object.isFrozen(range), false);
|
|
186
|
+
range.add(31).add(1_000);
|
|
187
|
+
range.delete(42);
|
|
188
|
+
assert.deepEqual([...range], [30, 31, 33, 36, 39, 1_000]);
|
|
189
|
+
assert.equal(range.has(33), true);
|
|
190
|
+
assert.equal(range.has(42), false);
|
|
191
|
+
// Its set algebra gives sets of the same order.
|
|
192
|
+
assert.deepEqual([...range.union(new SortedSet([2, 32], order.compare))], [2, 30, 31, 32, 33, 36, 39, 1_000]);
|
|
193
|
+
assert.equal(set.size, 300);
|
|
194
|
+
assert.throws(() => set.add(31), TypeError);
|
|
195
|
+
});
|
|
196
|
+
test("a range is found by a search: the set's comparison is never called, and the tests fewer times than the range has elements", () => {
|
|
197
|
+
const order = counting();
|
|
198
|
+
const set = threes(100_000, order.compare);
|
|
199
|
+
const SEARCH = 200;
|
|
200
|
+
for (const [from, to] of [[150_000, 150_150], [0, 30], [90_000, 210_000]]) {
|
|
201
|
+
order.reset();
|
|
202
|
+
const count = { calls: 0 };
|
|
203
|
+
const range = set.range(atOrPast(from, count), atOrPast(to, count));
|
|
204
|
+
const kept = (to - from) / 3;
|
|
205
|
+
assert.equal(range.size, kept, `from ${from} to ${to}`);
|
|
206
|
+
assert.equal(order.calls(), 0, `the set's comparison, from ${from} to ${to}`);
|
|
207
|
+
assert.ok(count.calls <= kept + SEARCH, `${count.calls} test calls for ${kept} elements, from ${from} to ${to}`);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
describe("a range of a lazily opened collection (#1616)", () => {
|
|
212
|
+
// What the pager decodes for a range is counted where the pager serves one (D4); here, that a
|
|
213
|
+
// range of a collection opened lazily holds what a range of the same collection held in memory does.
|
|
214
|
+
const Squares = DictType(IntegerType, IntegerType);
|
|
215
|
+
const Evens = SetType(IntegerType);
|
|
216
|
+
const squares = new SortedMap(Array.from({ length: 5_000 }, (_, i) => [BigInt(i), BigInt(i * i)]), compareFor(IntegerType));
|
|
217
|
+
const evens = new SortedSet(Array.from({ length: 5_000 }, (_, i) => BigInt(2 * i)), compareFor(IntegerType));
|
|
218
|
+
const from = (key) => key >= 1990n;
|
|
219
|
+
const to = (key) => key >= 2010n;
|
|
220
|
+
/** The entries, or the elements, in segments of 64. */
|
|
221
|
+
const segments = (all) => Array.from({ length: Math.ceil(all.length / 64) }, (_, i) => all.slice(64 * i, 64 * (i + 1)));
|
|
222
|
+
test("a Dict's range is the held Dict's, whether the source is opened plain or frozen, and is never frozen", () => {
|
|
223
|
+
const blob = encodeBeast2SegmentsFor(Squares)(segments([...squares]).map((entries) => new Map(entries)));
|
|
224
|
+
const held = [...squares.range(from, to)];
|
|
225
|
+
assert.equal(held.length, 20);
|
|
226
|
+
for (const frozen of [false, true]) {
|
|
227
|
+
const lazy = openBeast2LazyFor(Squares, { frozen })(blob);
|
|
228
|
+
const range = lazy.range(from, to);
|
|
229
|
+
assert.deepEqual([...range], held, `frozen ${frozen}`);
|
|
230
|
+
assert.equal(Object.isFrozen(range), false);
|
|
231
|
+
range.set(-1n, 1n);
|
|
232
|
+
assert.equal(range.size, 21);
|
|
233
|
+
// The source answers as before.
|
|
234
|
+
assert.equal(lazy.size, 5_000);
|
|
235
|
+
assert.equal(lazy.get(-1n), undefined);
|
|
236
|
+
assert.equal(lazy.get(2000n), 4000000n);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
test("a Set's range is the held Set's, whether the source is opened plain or frozen, and is never frozen", () => {
|
|
240
|
+
const blob = encodeBeast2SegmentsFor(Evens)(segments([...evens]).map((elements) => new Set(elements)));
|
|
241
|
+
const held = [...evens.range(from, to)];
|
|
242
|
+
assert.deepEqual(held, [1990n, 1992n, 1994n, 1996n, 1998n, 2000n, 2002n, 2004n, 2006n, 2008n]);
|
|
243
|
+
for (const frozen of [false, true]) {
|
|
244
|
+
const lazy = openBeast2LazyFor(Evens, { frozen })(blob);
|
|
245
|
+
const range = lazy.range(from, to);
|
|
246
|
+
assert.deepEqual([...range], held, `frozen ${frozen}`);
|
|
247
|
+
range.add(1991n);
|
|
248
|
+
assert.equal(range.has(1991n), true);
|
|
249
|
+
assert.equal(lazy.has(1991n), false);
|
|
250
|
+
assert.equal(lazy.size, 5_000);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
//# sourceMappingURL=range.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.spec.js","sourceRoot":"","sources":["../../../src/containers/range.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AAEH,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3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,IAAI,EAAE,EAAE,CAAC,CAAC;YACnC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,MAAM,EAAE,CAAC,CAAC;YACvD,KAAK,CAAC,GAAG,CAAC,KAAM,CAAC,CAAC;YAClB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAM,CAAC,EAAE,IAAI,CAAC,CAAC;YACtC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAM,CAAC,EAAE,KAAK,CAAC,CAAC;YACtC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACnC,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type KeyTest } from "./range.js";
|
|
1
2
|
/**
|
|
2
3
|
* A sorted map implementation using a B-tree data structure.
|
|
3
4
|
*
|
|
@@ -9,6 +10,7 @@
|
|
|
9
10
|
* - Maintains entries in sorted order by key based on a comparison function
|
|
10
11
|
* - Supports {@link minKey} and {@link maxKey} for accessing key extrema
|
|
11
12
|
* - Provides range-based iteration starting from any key
|
|
13
|
+
* - Gives the entries between two bounds as a new map ({@link range}), found by a search
|
|
12
14
|
* - Respects frozen state and throws errors on modification attempts
|
|
13
15
|
* - Includes static {@link groupBy} method for aggregation operations
|
|
14
16
|
* - {@link getOrInsert} and {@link getOrInsertComputed} find a key by the comparison function, as every lookup does
|
|
@@ -153,6 +155,29 @@ export declare class SortedMap<K, T> implements Map<K, T> {
|
|
|
153
155
|
* If `firstKey` is provided, iteration starts from that key.
|
|
154
156
|
*/
|
|
155
157
|
entries(firstKey?: K | undefined): MapIterator<[K, T]>;
|
|
158
|
+
/**
|
|
159
|
+
* Returns the entries between two bounds as a new map.
|
|
160
|
+
*
|
|
161
|
+
* @param from - A test that is false, then true, over the keys in order: the first key it holds for is the first kept. Left out, the map's first key is
|
|
162
|
+
* @param to - A test of the same kind: the first key it holds for, and every key after it, is left out. Left out, the entries run to the map's last
|
|
163
|
+
* @returns A new {@link SortedMap} with this map's comparison, holding the values this map holds for the keys kept
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* A bound of a key range is a key's first fields, which is no key the map can be asked for, so each
|
|
167
|
+
* bound is given as the test "is this key at or past it?" (`keyAtOrPast`, for an East key).
|
|
168
|
+
*
|
|
169
|
+
* The ends are found by a search down the tree and the entries between them are walked: neither
|
|
170
|
+
* the tests nor the map's comparison is called for an entry outside the range. The new map is not
|
|
171
|
+
* frozen, whatever this one is, and nothing of this one is changed.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* const squares = new SortedMap<number, number>([[1, 1], [2, 4], [3, 9], [4, 16]]);
|
|
176
|
+
* const middle = squares.range((key) => key >= 2, (key) => key >= 4);
|
|
177
|
+
* // Map { 2 => 4, 3 => 9 }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
range(from?: KeyTest<K>, to?: KeyTest<K>): SortedMap<K, T>;
|
|
156
181
|
/**
|
|
157
182
|
* Returns an iterator over the map's entries in sorted order by key.
|
|
158
183
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortedmap.d.ts","sourceRoot":"","sources":["../../../src/containers/sortedmap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sortedmap.d.ts","sourceRoot":"","sources":["../../../src/containers/sortedmap.ts"],"names":[],"mappings":"AAOA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAWrD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,SAAS,CAAC,CAAC,EAAE,CAAC,CAAE,YAAW,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAc;IAE3B;;;;;;;;;OASG;IACH,YAAY,MAAM,CAAC,E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js";
|
|
8
|
+
import { copyRange } from "./range.js";
|
|
8
9
|
// Deal with CJS default import. Node's ESM interop hands back the whole
|
|
9
10
|
// `module.exports`, so the class is under `.default`; Vite/vitest (and other
|
|
10
11
|
// bundlers) already unwrap it, leaving `.default` undefined. Take whichever is
|
|
@@ -23,6 +24,7 @@ const BTree = sorted_btree.default
|
|
|
23
24
|
* - Maintains entries in sorted order by key based on a comparison function
|
|
24
25
|
* - Supports {@link minKey} and {@link maxKey} for accessing key extrema
|
|
25
26
|
* - Provides range-based iteration starting from any key
|
|
27
|
+
* - Gives the entries between two bounds as a new map ({@link range}), found by a search
|
|
26
28
|
* - Respects frozen state and throws errors on modification attempts
|
|
27
29
|
* - Includes static {@link groupBy} method for aggregation operations
|
|
28
30
|
* - {@link getOrInsert} and {@link getOrInsertComputed} find a key by the comparison function, as every lookup does
|
|
@@ -229,6 +231,33 @@ export class SortedMap {
|
|
|
229
231
|
})(this.btree);
|
|
230
232
|
return builtinIterator(gen);
|
|
231
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Returns the entries between two bounds as a new map.
|
|
236
|
+
*
|
|
237
|
+
* @param from - A test that is false, then true, over the keys in order: the first key it holds for is the first kept. Left out, the map's first key is
|
|
238
|
+
* @param to - A test of the same kind: the first key it holds for, and every key after it, is left out. Left out, the entries run to the map's last
|
|
239
|
+
* @returns A new {@link SortedMap} with this map's comparison, holding the values this map holds for the keys kept
|
|
240
|
+
*
|
|
241
|
+
* @remarks
|
|
242
|
+
* A bound of a key range is a key's first fields, which is no key the map can be asked for, so each
|
|
243
|
+
* bound is given as the test "is this key at or past it?" (`keyAtOrPast`, for an East key).
|
|
244
|
+
*
|
|
245
|
+
* The ends are found by a search down the tree and the entries between them are walked: neither
|
|
246
|
+
* the tests nor the map's comparison is called for an entry outside the range. The new map is not
|
|
247
|
+
* frozen, whatever this one is, and nothing of this one is changed.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* const squares = new SortedMap<number, number>([[1, 1], [2, 4], [3, 9], [4, 16]]);
|
|
252
|
+
* const middle = squares.range((key) => key >= 2, (key) => key >= 4);
|
|
253
|
+
* // Map { 2 => 4, 3 => 9 }
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
range(from, to) {
|
|
257
|
+
const result = new SortedMap(undefined, this.btree._compare);
|
|
258
|
+
copyRange(this.btree, result.btree, from, to);
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
232
261
|
/**
|
|
233
262
|
* Returns an iterator over the map's entries in sorted order by key.
|
|
234
263
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortedmap.js","sourceRoot":"","sources":["../../../src/containers/sortedmap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"sortedmap.js","sourceRoot":"","sources":["../../../src/containers/sortedmap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAgB,MAAM,YAAY,CAAC;AAErD,wEAAwE;AACxE,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAC/E,2EAA2E;AAC3E,MAAM,KAAK,GAAI,YAAqE,CAAC,OAAO;OACtF,YAAuD,CAAC;AAG9D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,SAAS;IACV,KAAK,CAAc;IAE3B;;;;;;;;;OASG;IACH,YAAY,MAAwB,EAAE,OAAgC;QAClE,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,SAAS,EAA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pB,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,OAAO,CAAO,KAAkB,EAAE,WAA2B,EAAE,OAAgC;QAClG,MAAM,GAAG,GAAG,IAAI,SAAS,CAAS,SAAS,EAAE,OAAO,CAAC,CAAC;QACtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;YAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACtB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;YACzB,CAAC;iBAAM,CAAC;gBACJ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AACD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACrC,OAAO,KAAK,YAAY,GAAG,IAAI,KAAK,YAAY,SAAS,CAAC;AAC9D,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type KeyTest } from "./range.js";
|
|
1
2
|
/**
|
|
2
3
|
* A sorted set implementation using a B-tree data structure.
|
|
3
4
|
*
|
|
@@ -8,6 +9,7 @@
|
|
|
8
9
|
* - Maintains keys in sorted order based on a comparison function
|
|
9
10
|
* - Supports {@link minKey} and {@link maxKey} for accessing extrema
|
|
10
11
|
* - Provides range-based iteration starting from any key
|
|
12
|
+
* - Gives the elements between two bounds as a new set ({@link range}), found by a search
|
|
11
13
|
* - Implements ES2024 set operations (union, intersection, difference, etc.)
|
|
12
14
|
* - Respects frozen state and throws errors on modification attempts
|
|
13
15
|
*
|
|
@@ -171,6 +173,30 @@ export declare class SortedSet<K> implements Set<K> {
|
|
|
171
173
|
* If `firstKey` is provided, iteration starts from that key.
|
|
172
174
|
*/
|
|
173
175
|
entries(firstKey?: K | undefined): SetIterator<[K, K]>;
|
|
176
|
+
/**
|
|
177
|
+
* Returns the elements between two bounds as a new set.
|
|
178
|
+
*
|
|
179
|
+
* @param from - A test that is false, then true, over the elements in order: the first it holds for is the first kept. Left out, the set's first element is
|
|
180
|
+
* @param to - A test of the same kind: the first element it holds for, and every one after it, is left out. Left out, the elements run to the set's last
|
|
181
|
+
* @returns A new {@link SortedSet} with this set's comparison, holding the elements kept
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* A bound of a key range is an element's first fields, which is no element the set can be asked
|
|
185
|
+
* for, so each bound is given as the test "is this element at or past it?" (`keyAtOrPast`, for an
|
|
186
|
+
* East key).
|
|
187
|
+
*
|
|
188
|
+
* The ends are found by a search down the tree and the elements between them are walked:
|
|
189
|
+
* neither the tests nor the set's comparison is called for an element outside the range. The new
|
|
190
|
+
* set is not frozen, whatever this one is, and nothing of this one is changed.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* const primes = new SortedSet<number>([2, 3, 5, 7, 11]);
|
|
195
|
+
* const middle = primes.range((key) => key >= 3, (key) => key >= 11);
|
|
196
|
+
* // Set { 3, 5, 7 }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
range(from?: KeyTest<K>, to?: KeyTest<K>): SortedSet<K>;
|
|
174
200
|
/**
|
|
175
201
|
* Returns an iterator over the set's values in sorted order.
|
|
176
202
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortedset.d.ts","sourceRoot":"","sources":["../../../src/containers/sortedset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sortedset.d.ts","sourceRoot":"","sources":["../../../src/containers/sortedset.ts"],"names":[],"mappings":"AAOA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC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;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,CAE3D"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import sorted_btree from "sorted-btree";
|
|
6
6
|
import { defaultKeyCompare } from "../string_order.js";
|
|
7
7
|
import { builtinIterator } from "./iterators.js";
|
|
8
|
+
import { copyRange } from "./range.js";
|
|
8
9
|
// Deal with CJS default import. Node's ESM interop hands back the whole
|
|
9
10
|
// `module.exports`, so the class is under `.default`; Vite/vitest (and other
|
|
10
11
|
// bundlers) already unwrap it, leaving `.default` undefined. Take whichever is
|
|
@@ -24,6 +25,7 @@ const BTree = sorted_btree.default
|
|
|
24
25
|
* - Maintains keys in sorted order based on a comparison function
|
|
25
26
|
* - Supports {@link minKey} and {@link maxKey} for accessing extrema
|
|
26
27
|
* - Provides range-based iteration starting from any key
|
|
28
|
+
* - Gives the elements between two bounds as a new set ({@link range}), found by a search
|
|
27
29
|
* - Implements ES2024 set operations (union, intersection, difference, etc.)
|
|
28
30
|
* - Respects frozen state and throws errors on modification attempts
|
|
29
31
|
*
|
|
@@ -301,6 +303,34 @@ export class SortedSet {
|
|
|
301
303
|
})(this.btree);
|
|
302
304
|
return builtinIterator(gen);
|
|
303
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Returns the elements between two bounds as a new set.
|
|
308
|
+
*
|
|
309
|
+
* @param from - A test that is false, then true, over the elements in order: the first it holds for is the first kept. Left out, the set's first element is
|
|
310
|
+
* @param to - A test of the same kind: the first element it holds for, and every one after it, is left out. Left out, the elements run to the set's last
|
|
311
|
+
* @returns A new {@link SortedSet} with this set's comparison, holding the elements kept
|
|
312
|
+
*
|
|
313
|
+
* @remarks
|
|
314
|
+
* A bound of a key range is an element's first fields, which is no element the set can be asked
|
|
315
|
+
* for, so each bound is given as the test "is this element at or past it?" (`keyAtOrPast`, for an
|
|
316
|
+
* East key).
|
|
317
|
+
*
|
|
318
|
+
* The ends are found by a search down the tree and the elements between them are walked:
|
|
319
|
+
* neither the tests nor the set's comparison is called for an element outside the range. The new
|
|
320
|
+
* set is not frozen, whatever this one is, and nothing of this one is changed.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* const primes = new SortedSet<number>([2, 3, 5, 7, 11]);
|
|
325
|
+
* const middle = primes.range((key) => key >= 3, (key) => key >= 11);
|
|
326
|
+
* // Set { 3, 5, 7 }
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
range(from, to) {
|
|
330
|
+
const result = new SortedSet(undefined, this.compare);
|
|
331
|
+
copyRange(this.btree, result.btree, from, to);
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
304
334
|
/**
|
|
305
335
|
* Returns an iterator over the set's values in sorted order.
|
|
306
336
|
*
|