@rhombus-toolkit/collections 2.0.0 → 2.0.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/dist/bundle/index.d.ts +5 -8
- package/dist/bundle/index.js +14 -13
- package/package.json +1 -1
package/dist/bundle/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* exactly what it held however much is added or removed afterwards.
|
|
2
|
+
* A persistent singly-linked list — extending shares everything already there.
|
|
4
3
|
*
|
|
5
4
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
* leaves the tail the same link it already was — so a list knows what it ends with without ever
|
|
8
|
-
* walking to find out. {@link tailToHead} is settled once per list and answered from then on, which
|
|
9
|
-
* is what lets a list be read from its tail as often as wanted without paying to reverse it.
|
|
5
|
+
* {@link tail} is O(1); {@link tailToHead} reverses once and caches the result.
|
|
10
6
|
*/
|
|
11
7
|
declare class ImmutableLinkedList<T> implements Iterable<T> {
|
|
12
8
|
#private;
|
|
@@ -32,7 +28,7 @@ declare class ImmutableLinkedList<T> implements Iterable<T> {
|
|
|
32
28
|
tailToHead(): readonly T[];
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
declare class KindaWeakMap<K, V extends
|
|
31
|
+
declare class KindaWeakMap<K, V extends WeakKey> {
|
|
36
32
|
#private;
|
|
37
33
|
set(key: K, value: V): this;
|
|
38
34
|
delete(key: K): boolean;
|
|
@@ -40,10 +36,11 @@ declare class KindaWeakMap<K, V extends object> {
|
|
|
40
36
|
has(key: K): boolean;
|
|
41
37
|
clear(): void;
|
|
42
38
|
forEach(callbackfn: (value: V, key: K, map: this) => void, thisArg?: any): void;
|
|
39
|
+
/** Counts only entries whose value is still alive, so it walks every ref. */
|
|
43
40
|
get size(): number;
|
|
44
41
|
entries(): MapIterator<[K, V]>;
|
|
45
42
|
keys(): MapIterator<K>;
|
|
46
|
-
values(): MapIterator<V
|
|
43
|
+
values(): MapIterator<V>;
|
|
47
44
|
[Symbol.iterator](): MapIterator<[K, V]>;
|
|
48
45
|
readonly [Symbol.toStringTag]: "KindaWeakMap";
|
|
49
46
|
}
|
package/dist/bundle/index.js
CHANGED
|
@@ -66,28 +66,28 @@ class KindaWeakMap {
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
set(key, value) {
|
|
69
|
-
|
|
70
|
-
this.delete(key);
|
|
71
|
-
}
|
|
69
|
+
this.delete(key);
|
|
72
70
|
this.#registry.register(value, key, value);
|
|
73
71
|
this.#map.set(key, new WeakRef(value));
|
|
74
72
|
return this;
|
|
75
73
|
}
|
|
76
74
|
delete(key) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const value = this.get(key);
|
|
76
|
+
this.#map.delete(key);
|
|
77
|
+
if (value === undefined) {
|
|
78
|
+
return false;
|
|
80
79
|
}
|
|
81
|
-
|
|
80
|
+
this.#registry.unregister(value);
|
|
81
|
+
return true;
|
|
82
82
|
}
|
|
83
83
|
get(key) {
|
|
84
84
|
return this.#map.get(key)?.deref();
|
|
85
85
|
}
|
|
86
86
|
has(key) {
|
|
87
|
-
return this
|
|
87
|
+
return this.get(key) !== undefined;
|
|
88
88
|
}
|
|
89
89
|
clear() {
|
|
90
|
-
this.values().
|
|
90
|
+
this.values().forEach((value) => this.#registry.unregister(value));
|
|
91
91
|
this.#map.clear();
|
|
92
92
|
}
|
|
93
93
|
forEach(callbackfn, thisArg) {
|
|
@@ -96,16 +96,17 @@ class KindaWeakMap {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
get size() {
|
|
99
|
-
return this
|
|
99
|
+
return this.entries().reduce((count) => count + 1, 0);
|
|
100
100
|
}
|
|
101
101
|
entries() {
|
|
102
|
-
|
|
102
|
+
const held = this.#map.entries().map(([key, ref]) => [key, ref.deref()]);
|
|
103
|
+
return held.filter((entry) => entry[1] !== undefined);
|
|
103
104
|
}
|
|
104
105
|
keys() {
|
|
105
|
-
return this
|
|
106
|
+
return this.entries().map(([key]) => key);
|
|
106
107
|
}
|
|
107
108
|
values() {
|
|
108
|
-
return this
|
|
109
|
+
return this.entries().map(([, value]) => value);
|
|
109
110
|
}
|
|
110
111
|
[Symbol.iterator]() {
|
|
111
112
|
return this.entries();
|
package/package.json
CHANGED