@thi.ng/sorted-map 1.1.42 → 1.2.1
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/CHANGELOG.md +14 -1
- package/README.md +1 -1
- package/package.json +10 -10
- package/sorted-map.d.ts +7 -4
- package/sorted-map.js +74 -46
- package/sorted-set.d.ts +6 -4
- package/sorted-set.js +33 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-
|
|
3
|
+
- **Last updated**: 2025-07-10T14:20:23Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -11,6 +11,19 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
11
11
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
12
|
and/or version bumps of transitive dependencies.
|
|
13
13
|
|
|
14
|
+
## [1.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/sorted-map@1.2.0) (2025-07-10)
|
|
15
|
+
|
|
16
|
+
#### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- add `Symbol.dispose` support ([7583094](https://github.com/thi-ng/umbrella/commit/7583094))
|
|
19
|
+
- update all `SortedMap` & `SortedSet` impls
|
|
20
|
+
|
|
21
|
+
#### ♻️ Refactoring
|
|
22
|
+
|
|
23
|
+
- update all Map/Set private state and `toString()` impls ([#505](https://github.com/thi-ng/umbrella/issues/505)) ([ce2e43a](https://github.com/thi-ng/umbrella/commit/ce2e43a))
|
|
24
|
+
- use private class properties instead of WeakMap to strore internal state
|
|
25
|
+
- replace `__inspectable` with `__tostringMixin`
|
|
26
|
+
|
|
14
27
|
### [1.1.29](https://github.com/thi-ng/umbrella/tree/@thi.ng/sorted-map@1.1.29) (2025-03-10)
|
|
15
28
|
|
|
16
29
|
#### 🩹 Bug fixes
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/sorted-map",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Skiplist-based sorted map & set implementation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.11.
|
|
43
|
-
"@thi.ng/associative": "^7.
|
|
44
|
-
"@thi.ng/checks": "^3.7.
|
|
45
|
-
"@thi.ng/compare": "^2.4.
|
|
46
|
-
"@thi.ng/random": "^4.1.
|
|
47
|
-
"@thi.ng/transducers": "^9.
|
|
42
|
+
"@thi.ng/api": "^8.11.30",
|
|
43
|
+
"@thi.ng/associative": "^7.1.1",
|
|
44
|
+
"@thi.ng/checks": "^3.7.10",
|
|
45
|
+
"@thi.ng/compare": "^2.4.22",
|
|
46
|
+
"@thi.ng/random": "^4.1.21",
|
|
47
|
+
"@thi.ng/transducers": "^9.6.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"esbuild": "^0.25.
|
|
51
|
-
"typedoc": "^0.28.
|
|
50
|
+
"esbuild": "^0.25.6",
|
|
51
|
+
"typedoc": "^0.28.7",
|
|
52
52
|
"typescript": "^5.8.3"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
],
|
|
98
98
|
"year": 2018
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "a81765bd79046980463c56a8bd187f9aaa88dd65\n"
|
|
101
101
|
}
|
package/sorted-map.d.ts
CHANGED
|
@@ -25,10 +25,13 @@ declare class Node<K, V> {
|
|
|
25
25
|
* - https://www.educba.com/skip-list-java/
|
|
26
26
|
*/
|
|
27
27
|
export declare class SortedMap<K, V> extends Map<K, V> {
|
|
28
|
+
#private;
|
|
28
29
|
constructor(pairs?: Iterable<Pair<K, V>> | null, opts?: Partial<SortedMapOpts<K>>);
|
|
29
30
|
get size(): number;
|
|
30
31
|
get [Symbol.species](): typeof SortedMap;
|
|
31
|
-
[Symbol.
|
|
32
|
+
get [Symbol.toStringTag](): string;
|
|
33
|
+
[Symbol.iterator](): MapIterator<Pair<K, V>>;
|
|
34
|
+
[Symbol.dispose](): void;
|
|
32
35
|
/**
|
|
33
36
|
* Yields iterator of sorted `[key, value]` pairs, optionally taking given
|
|
34
37
|
* `key` and `max` flag into account.
|
|
@@ -44,21 +47,21 @@ export declare class SortedMap<K, V> extends Map<K, V> {
|
|
|
44
47
|
* @param key
|
|
45
48
|
* @param max
|
|
46
49
|
*/
|
|
47
|
-
entries(key?: K, max?: boolean):
|
|
50
|
+
entries(key?: K, max?: boolean): MapIterator<Pair<K, V>>;
|
|
48
51
|
/**
|
|
49
52
|
* Similar to {@link SortedMap.entries}, but only yield sequence of keys.
|
|
50
53
|
*
|
|
51
54
|
* @param key
|
|
52
55
|
* @param max
|
|
53
56
|
*/
|
|
54
|
-
keys(key?: K, max?: boolean):
|
|
57
|
+
keys(key?: K, max?: boolean): MapIterator<K>;
|
|
55
58
|
/**
|
|
56
59
|
* Similar to {@link SortedMap.entries}, but only yield sequence of values.
|
|
57
60
|
*
|
|
58
61
|
* @param key
|
|
59
62
|
* @param max
|
|
60
63
|
*/
|
|
61
|
-
values(key?: K, max?: boolean):
|
|
64
|
+
values(key?: K, max?: boolean): MapIterator<V>;
|
|
62
65
|
clear(): void;
|
|
63
66
|
empty(): SortedMap<K, V>;
|
|
64
67
|
copy(): SortedMap<K, V>;
|
package/sorted-map.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __typeError = (msg) => {
|
|
4
|
+
throw TypeError(msg);
|
|
5
|
+
};
|
|
3
6
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
7
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
8
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -8,14 +11,27 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
8
11
|
if (kind && result) __defProp(target, key, result);
|
|
9
12
|
return result;
|
|
10
13
|
};
|
|
14
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
15
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
16
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
17
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
18
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
19
|
+
set _(value) {
|
|
20
|
+
__privateSet(obj, member, value, setter);
|
|
21
|
+
},
|
|
22
|
+
get _() {
|
|
23
|
+
return __privateGet(obj, member, getter);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
var _head, _cmp, _p, _rnd, _size;
|
|
11
27
|
import { dissoc } from "@thi.ng/associative/dissoc";
|
|
28
|
+
import { __disposableEntries } from "@thi.ng/associative/internal/dispose";
|
|
12
29
|
import { __equivMap } from "@thi.ng/associative/internal/equiv";
|
|
13
|
-
import {
|
|
30
|
+
import { __tostringMixin } from "@thi.ng/associative/internal/tostring";
|
|
14
31
|
import { into } from "@thi.ng/associative/into";
|
|
15
32
|
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
|
|
16
33
|
import { compare } from "@thi.ng/compare/compare";
|
|
17
34
|
import { SYSTEM } from "@thi.ng/random/system";
|
|
18
|
-
import { map } from "@thi.ng/transducers/map";
|
|
19
35
|
import { isReduced } from "@thi.ng/transducers/reduced";
|
|
20
36
|
class Node {
|
|
21
37
|
constructor(k, v, level = 0) {
|
|
@@ -28,27 +44,32 @@ class Node {
|
|
|
28
44
|
up;
|
|
29
45
|
down;
|
|
30
46
|
}
|
|
31
|
-
const __private = /* @__PURE__ */ new WeakMap();
|
|
32
47
|
let SortedMap = class extends Map {
|
|
33
48
|
constructor(pairs, opts = {}) {
|
|
34
49
|
super();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
__privateAdd(this, _head);
|
|
51
|
+
__privateAdd(this, _cmp);
|
|
52
|
+
__privateAdd(this, _p);
|
|
53
|
+
__privateAdd(this, _rnd);
|
|
54
|
+
__privateAdd(this, _size);
|
|
55
|
+
__privateSet(this, _head, new Node());
|
|
56
|
+
__privateSet(this, _cmp, opts.compare || compare);
|
|
57
|
+
__privateSet(this, _rnd, opts.rnd || SYSTEM);
|
|
58
|
+
__privateSet(this, _p, opts.probability || 1 / Math.E);
|
|
59
|
+
__privateSet(this, _size, 0);
|
|
42
60
|
if (pairs) {
|
|
43
61
|
this.into(pairs);
|
|
44
62
|
}
|
|
45
63
|
}
|
|
46
64
|
get size() {
|
|
47
|
-
return
|
|
65
|
+
return __privateGet(this, _size);
|
|
48
66
|
}
|
|
49
67
|
get [Symbol.species]() {
|
|
50
68
|
return SortedMap;
|
|
51
69
|
}
|
|
70
|
+
get [Symbol.toStringTag]() {
|
|
71
|
+
return "SortedMap";
|
|
72
|
+
}
|
|
52
73
|
*[Symbol.iterator]() {
|
|
53
74
|
let node = this.firstNode();
|
|
54
75
|
while (node?.k !== void 0) {
|
|
@@ -56,6 +77,9 @@ let SortedMap = class extends Map {
|
|
|
56
77
|
node = node.next;
|
|
57
78
|
}
|
|
58
79
|
}
|
|
80
|
+
// mixin
|
|
81
|
+
[Symbol.dispose]() {
|
|
82
|
+
}
|
|
59
83
|
/**
|
|
60
84
|
* Yields iterator of sorted `[key, value]` pairs, optionally taking given
|
|
61
85
|
* `key` and `max` flag into account.
|
|
@@ -76,8 +100,8 @@ let SortedMap = class extends Map {
|
|
|
76
100
|
yield* this;
|
|
77
101
|
return;
|
|
78
102
|
}
|
|
79
|
-
|
|
80
|
-
|
|
103
|
+
if (!__privateGet(this, _size)) return;
|
|
104
|
+
const cmp = __privateGet(this, _cmp);
|
|
81
105
|
if (max) {
|
|
82
106
|
let node = this.firstNode();
|
|
83
107
|
while (node?.k !== void 0 && cmp(node.k, key) <= 0) {
|
|
@@ -101,8 +125,10 @@ let SortedMap = class extends Map {
|
|
|
101
125
|
* @param key
|
|
102
126
|
* @param max
|
|
103
127
|
*/
|
|
104
|
-
keys(key, max = false) {
|
|
105
|
-
|
|
128
|
+
*keys(key, max = false) {
|
|
129
|
+
for (let p of this.entries(key, max)) {
|
|
130
|
+
yield p[0];
|
|
131
|
+
}
|
|
106
132
|
}
|
|
107
133
|
/**
|
|
108
134
|
* Similar to {@link SortedMap.entries}, but only yield sequence of values.
|
|
@@ -110,13 +136,14 @@ let SortedMap = class extends Map {
|
|
|
110
136
|
* @param key
|
|
111
137
|
* @param max
|
|
112
138
|
*/
|
|
113
|
-
values(key, max = false) {
|
|
114
|
-
|
|
139
|
+
*values(key, max = false) {
|
|
140
|
+
for (let p of this.entries(key, max)) {
|
|
141
|
+
yield p[1];
|
|
142
|
+
}
|
|
115
143
|
}
|
|
116
144
|
clear() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
$this.size = 0;
|
|
145
|
+
__privateSet(this, _head, new Node());
|
|
146
|
+
__privateSet(this, _size, 0);
|
|
120
147
|
}
|
|
121
148
|
empty() {
|
|
122
149
|
return new SortedMap(null, this.opts());
|
|
@@ -148,20 +175,16 @@ let SortedMap = class extends Map {
|
|
|
148
175
|
return node?.k !== void 0 ? [node.k, node.v] : void 0;
|
|
149
176
|
}
|
|
150
177
|
get(key, notFound) {
|
|
151
|
-
const $this = __private.get(this);
|
|
152
178
|
const node = this.findNode(key);
|
|
153
|
-
return node.k !== void 0 &&
|
|
179
|
+
return node.k !== void 0 && __privateGet(this, _cmp).call(this, node.k, key) === 0 ? node.v : notFound;
|
|
154
180
|
}
|
|
155
181
|
has(key) {
|
|
156
|
-
const { cmp } = __private.get(this);
|
|
157
182
|
const node = this.findNode(key);
|
|
158
|
-
return node.k !== void 0 &&
|
|
183
|
+
return node.k !== void 0 && __privateGet(this, _cmp).call(this, node.k, key) === 0;
|
|
159
184
|
}
|
|
160
185
|
set(key, val) {
|
|
161
|
-
const $this = __private.get(this);
|
|
162
|
-
const { cmp, p, rnd } = $this;
|
|
163
186
|
let node = this.findNode(key);
|
|
164
|
-
if (node.k !== void 0 &&
|
|
187
|
+
if (node.k !== void 0 && __privateGet(this, _cmp).call(this, node.k, key) === 0) {
|
|
165
188
|
node.v = val;
|
|
166
189
|
while (node.down) {
|
|
167
190
|
node = node.down;
|
|
@@ -172,7 +195,9 @@ let SortedMap = class extends Map {
|
|
|
172
195
|
let newNode = new Node(key, val, node.level);
|
|
173
196
|
this.insertInLane(node, newNode);
|
|
174
197
|
let currLevel = node.level;
|
|
175
|
-
let headLevel =
|
|
198
|
+
let headLevel = __privateGet(this, _head).level;
|
|
199
|
+
const rnd = __privateGet(this, _rnd);
|
|
200
|
+
const p = __privateGet(this, _p);
|
|
176
201
|
while (rnd.probability(p)) {
|
|
177
202
|
if (currLevel >= headLevel) {
|
|
178
203
|
const newHead = new Node(
|
|
@@ -180,8 +205,8 @@ let SortedMap = class extends Map {
|
|
|
180
205
|
void 0,
|
|
181
206
|
headLevel + 1
|
|
182
207
|
);
|
|
183
|
-
this.linkLanes(newHead,
|
|
184
|
-
|
|
208
|
+
this.linkLanes(newHead, __privateGet(this, _head));
|
|
209
|
+
__privateSet(this, _head, newHead);
|
|
185
210
|
headLevel++;
|
|
186
211
|
}
|
|
187
212
|
while (!node.up) node = node.prev;
|
|
@@ -192,13 +217,12 @@ let SortedMap = class extends Map {
|
|
|
192
217
|
newNode = tmp;
|
|
193
218
|
currLevel++;
|
|
194
219
|
}
|
|
195
|
-
|
|
220
|
+
__privateWrapper(this, _size)._++;
|
|
196
221
|
return this;
|
|
197
222
|
}
|
|
198
223
|
delete(key) {
|
|
199
|
-
const $this = __private.get(this);
|
|
200
224
|
let node = this.findNode(key);
|
|
201
|
-
if (node.k === void 0 ||
|
|
225
|
+
if (node.k === void 0 || __privateGet(this, _cmp).call(this, node.k, key) !== 0) return false;
|
|
202
226
|
while (node.down) node = node.down;
|
|
203
227
|
let prev;
|
|
204
228
|
let next;
|
|
@@ -209,11 +233,11 @@ let SortedMap = class extends Map {
|
|
|
209
233
|
if (next) next.prev = prev;
|
|
210
234
|
node = node.up;
|
|
211
235
|
}
|
|
212
|
-
while (
|
|
213
|
-
|
|
214
|
-
|
|
236
|
+
while (!__privateGet(this, _head).next && __privateGet(this, _head).down) {
|
|
237
|
+
__privateSet(this, _head, __privateGet(this, _head).down);
|
|
238
|
+
__privateGet(this, _head).up = void 0;
|
|
215
239
|
}
|
|
216
|
-
|
|
240
|
+
__privateWrapper(this, _size)._--;
|
|
217
241
|
return true;
|
|
218
242
|
}
|
|
219
243
|
into(pairs) {
|
|
@@ -244,11 +268,10 @@ let SortedMap = class extends Map {
|
|
|
244
268
|
return acc;
|
|
245
269
|
}
|
|
246
270
|
opts() {
|
|
247
|
-
const $this = __private.get(this);
|
|
248
271
|
return {
|
|
249
|
-
compare:
|
|
250
|
-
probability:
|
|
251
|
-
rnd:
|
|
272
|
+
compare: __privateGet(this, _cmp),
|
|
273
|
+
probability: __privateGet(this, _p),
|
|
274
|
+
rnd: __privateGet(this, _rnd)
|
|
252
275
|
};
|
|
253
276
|
}
|
|
254
277
|
/**
|
|
@@ -278,8 +301,7 @@ let SortedMap = class extends Map {
|
|
|
278
301
|
* will be the first data node (with the smallest key).
|
|
279
302
|
*/
|
|
280
303
|
firstNode() {
|
|
281
|
-
|
|
282
|
-
let node = head;
|
|
304
|
+
let node = __privateGet(this, _head);
|
|
283
305
|
while (node.down) node = node.down;
|
|
284
306
|
while (node.prev) node = node.prev;
|
|
285
307
|
if (node.next) node = node.next;
|
|
@@ -292,8 +314,8 @@ let SortedMap = class extends Map {
|
|
|
292
314
|
* @param key
|
|
293
315
|
*/
|
|
294
316
|
findNode(key) {
|
|
295
|
-
|
|
296
|
-
let node =
|
|
317
|
+
const cmp = __privateGet(this, _cmp);
|
|
318
|
+
let node = __privateGet(this, _head);
|
|
297
319
|
let next;
|
|
298
320
|
let down;
|
|
299
321
|
let nodeKey;
|
|
@@ -312,8 +334,14 @@ let SortedMap = class extends Map {
|
|
|
312
334
|
return node;
|
|
313
335
|
}
|
|
314
336
|
};
|
|
337
|
+
_head = new WeakMap();
|
|
338
|
+
_cmp = new WeakMap();
|
|
339
|
+
_p = new WeakMap();
|
|
340
|
+
_rnd = new WeakMap();
|
|
341
|
+
_size = new WeakMap();
|
|
315
342
|
SortedMap = __decorateClass([
|
|
316
|
-
|
|
343
|
+
__disposableEntries,
|
|
344
|
+
__tostringMixin
|
|
317
345
|
], SortedMap);
|
|
318
346
|
function defSortedMap(src, opts) {
|
|
319
347
|
return isPlainObject(src) ? new SortedMap(Object.entries(src), opts) : new SortedMap(src, opts);
|
package/sorted-set.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ import type { SortedSetOpts } from "./api.js";
|
|
|
24
24
|
* resizing characteristics.
|
|
25
25
|
*/
|
|
26
26
|
export declare class SortedSet<T> extends Set<T> implements IEquivSet<T>, ICompare<Set<T>>, IReducible<T, any> {
|
|
27
|
+
#private;
|
|
27
28
|
/**
|
|
28
29
|
* Creates new instance with optional given values and/or
|
|
29
30
|
* implementation options. The options are the same as used by
|
|
@@ -33,7 +34,8 @@ export declare class SortedSet<T> extends Set<T> implements IEquivSet<T>, ICompa
|
|
|
33
34
|
* @param opts - config options
|
|
34
35
|
*/
|
|
35
36
|
constructor(values?: Iterable<T> | null, opts?: Partial<SortedSetOpts<T>>);
|
|
36
|
-
[Symbol.iterator]():
|
|
37
|
+
[Symbol.iterator](): SetIterator<T>;
|
|
38
|
+
[Symbol.dispose](): void;
|
|
37
39
|
get [Symbol.species](): typeof SortedSet;
|
|
38
40
|
get [Symbol.toStringTag](): string;
|
|
39
41
|
get size(): number;
|
|
@@ -42,9 +44,9 @@ export declare class SortedSet<T> extends Set<T> implements IEquivSet<T>, ICompa
|
|
|
42
44
|
compare(o: Set<T>): number;
|
|
43
45
|
equiv(o: any): boolean;
|
|
44
46
|
$reduce<R>(rfn: ReductionFn<T, any>, acc: R | Reduced<R>): R | Reduced<R>;
|
|
45
|
-
entries(key?: T, max?: boolean):
|
|
46
|
-
keys(key?: T, max?: boolean):
|
|
47
|
-
values(key?: T, max?: boolean):
|
|
47
|
+
entries(key?: T, max?: boolean): SetIterator<Pair<T, T>>;
|
|
48
|
+
keys(key?: T, max?: boolean): SetIterator<T>;
|
|
49
|
+
values(key?: T, max?: boolean): SetIterator<T>;
|
|
48
50
|
add(key: T): this;
|
|
49
51
|
into(keys: Iterable<T>): this;
|
|
50
52
|
clear(): void;
|
package/sorted-set.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __typeError = (msg) => {
|
|
4
|
+
throw TypeError(msg);
|
|
5
|
+
};
|
|
3
6
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
7
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
8
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -8,14 +11,19 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
8
11
|
if (kind && result) __defProp(target, key, result);
|
|
9
12
|
return result;
|
|
10
13
|
};
|
|
14
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
15
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
16
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
17
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
18
|
+
var _map;
|
|
11
19
|
import { dissoc } from "@thi.ng/associative/dissoc";
|
|
20
|
+
import { __disposableValues } from "@thi.ng/associative/internal/dispose";
|
|
12
21
|
import { __equivSet } from "@thi.ng/associative/internal/equiv";
|
|
13
|
-
import {
|
|
22
|
+
import { __tostringMixin } from "@thi.ng/associative/internal/tostring";
|
|
14
23
|
import { into } from "@thi.ng/associative/into";
|
|
15
24
|
import { compare } from "@thi.ng/compare/compare";
|
|
16
25
|
import { map } from "@thi.ng/transducers/map";
|
|
17
26
|
import { SortedMap } from "./sorted-map.js";
|
|
18
|
-
const __private = /* @__PURE__ */ new WeakMap();
|
|
19
27
|
let SortedSet = class extends Set {
|
|
20
28
|
/**
|
|
21
29
|
* Creates new instance with optional given values and/or
|
|
@@ -27,17 +35,18 @@ let SortedSet = class extends Set {
|
|
|
27
35
|
*/
|
|
28
36
|
constructor(values, opts) {
|
|
29
37
|
super();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
);
|
|
38
|
+
__privateAdd(this, _map);
|
|
39
|
+
__privateSet(this, _map, new SortedMap(
|
|
40
|
+
values ? map((x) => [x, x], values) : null,
|
|
41
|
+
opts
|
|
42
|
+
));
|
|
37
43
|
}
|
|
38
44
|
[Symbol.iterator]() {
|
|
39
45
|
return this.keys();
|
|
40
46
|
}
|
|
47
|
+
// mixin
|
|
48
|
+
[Symbol.dispose]() {
|
|
49
|
+
}
|
|
41
50
|
get [Symbol.species]() {
|
|
42
51
|
return SortedSet;
|
|
43
52
|
}
|
|
@@ -45,7 +54,7 @@ let SortedSet = class extends Set {
|
|
|
45
54
|
return "SortedSet";
|
|
46
55
|
}
|
|
47
56
|
get size() {
|
|
48
|
-
return
|
|
57
|
+
return __privateGet(this, _map).size;
|
|
49
58
|
}
|
|
50
59
|
copy() {
|
|
51
60
|
return new SortedSet(this.keys(), this.opts());
|
|
@@ -73,33 +82,33 @@ let SortedSet = class extends Set {
|
|
|
73
82
|
return __equivSet(this, o);
|
|
74
83
|
}
|
|
75
84
|
$reduce(rfn, acc) {
|
|
76
|
-
return
|
|
85
|
+
return __privateGet(this, _map).$reduce((_acc, x) => rfn(_acc, x[0]), acc);
|
|
77
86
|
}
|
|
78
87
|
entries(key, max = false) {
|
|
79
|
-
return
|
|
88
|
+
return __privateGet(this, _map).entries(key, max);
|
|
80
89
|
}
|
|
81
90
|
keys(key, max = false) {
|
|
82
|
-
return
|
|
91
|
+
return __privateGet(this, _map).keys(key, max);
|
|
83
92
|
}
|
|
84
93
|
values(key, max = false) {
|
|
85
|
-
return
|
|
94
|
+
return __privateGet(this, _map).values(key, max);
|
|
86
95
|
}
|
|
87
96
|
add(key) {
|
|
88
|
-
|
|
97
|
+
__privateGet(this, _map).set(key, key);
|
|
89
98
|
return this;
|
|
90
99
|
}
|
|
91
100
|
into(keys) {
|
|
92
101
|
return into(this, keys);
|
|
93
102
|
}
|
|
94
103
|
clear() {
|
|
95
|
-
|
|
104
|
+
__privateGet(this, _map).clear();
|
|
96
105
|
}
|
|
97
106
|
first() {
|
|
98
|
-
const first =
|
|
107
|
+
const first = __privateGet(this, _map).first();
|
|
99
108
|
return first ? first[0] : void 0;
|
|
100
109
|
}
|
|
101
110
|
delete(key) {
|
|
102
|
-
return
|
|
111
|
+
return __privateGet(this, _map).delete(key);
|
|
103
112
|
}
|
|
104
113
|
disj(keys) {
|
|
105
114
|
return dissoc(this, keys);
|
|
@@ -110,17 +119,19 @@ let SortedSet = class extends Set {
|
|
|
110
119
|
}
|
|
111
120
|
}
|
|
112
121
|
has(key) {
|
|
113
|
-
return
|
|
122
|
+
return __privateGet(this, _map).has(key);
|
|
114
123
|
}
|
|
115
124
|
get(key, notFound) {
|
|
116
|
-
return
|
|
125
|
+
return __privateGet(this, _map).get(key, notFound);
|
|
117
126
|
}
|
|
118
127
|
opts() {
|
|
119
|
-
return
|
|
128
|
+
return __privateGet(this, _map).opts();
|
|
120
129
|
}
|
|
121
130
|
};
|
|
131
|
+
_map = new WeakMap();
|
|
122
132
|
SortedSet = __decorateClass([
|
|
123
|
-
|
|
133
|
+
__disposableValues,
|
|
134
|
+
__tostringMixin
|
|
124
135
|
], SortedSet);
|
|
125
136
|
const defSortedSet = (vals, opts) => new SortedSet(vals, opts);
|
|
126
137
|
export {
|