@naturalcycles/js-lib 15.66.0 → 15.67.0
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.
|
@@ -19,7 +19,9 @@ export interface KeySortedMapOptions<K> {
|
|
|
19
19
|
*
|
|
20
20
|
* @experimental
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export interface KeySortedMap<K, V> extends Map<K, V> {
|
|
23
|
+
}
|
|
24
|
+
export declare class KeySortedMap<K, V> {
|
|
23
25
|
#private;
|
|
24
26
|
private readonly map;
|
|
25
27
|
constructor(entries?: [K, V][], opt?: KeySortedMapOptions<K>);
|
|
@@ -52,7 +54,7 @@ export declare class KeySortedMap<K, V> implements Map<K, V> {
|
|
|
52
54
|
entries(): MapIterator<[K, V]>;
|
|
53
55
|
[Symbol.iterator](): MapIterator<[K, V]>;
|
|
54
56
|
toString(): string;
|
|
55
|
-
[Symbol.toStringTag]
|
|
57
|
+
readonly [Symbol.toStringTag] = "KeySortedMap";
|
|
56
58
|
/**
|
|
57
59
|
* Zero-allocation callbacks over sorted data (faster than spreading to arrays).
|
|
58
60
|
*/
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import { _assert } from '../error/index.js';
|
|
2
|
-
|
|
3
|
-
* Maintains sorted array of keys.
|
|
4
|
-
* Sorts **on insertion**, not on retrieval.
|
|
5
|
-
*
|
|
6
|
-
* - set(): O(log n) search + O(n) splice only when inserting a NEW key
|
|
7
|
-
* - get/has: O(1)
|
|
8
|
-
* - delete: O(log n) search + O(n) splice if present
|
|
9
|
-
* - iteration: O(n) over pre-sorted keys (no sorting at iteration time)
|
|
10
|
-
*
|
|
11
|
-
* @experimental
|
|
12
|
-
*/
|
|
2
|
+
// oxlint-disable-next-line no-unsafe-declaration-merging -- Map<K,V> workaround for oxlint TS2420 false positive
|
|
13
3
|
export class KeySortedMap {
|
|
14
4
|
map;
|
|
15
5
|
#sortedKeys;
|
|
@@ -14,7 +14,9 @@ export interface LazyKeySortedMapOptions<K> {
|
|
|
14
14
|
*
|
|
15
15
|
* @experimental
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export interface LazyKeySortedMap<K, V> extends Map<K, V> {
|
|
18
|
+
}
|
|
19
|
+
export declare class LazyKeySortedMap<K, V> {
|
|
18
20
|
#private;
|
|
19
21
|
private readonly map;
|
|
20
22
|
private readonly maybeSortedKeys;
|
|
@@ -48,7 +50,7 @@ export declare class LazyKeySortedMap<K, V> implements Map<K, V> {
|
|
|
48
50
|
values(): MapIterator<V>;
|
|
49
51
|
entries(): MapIterator<[K, V]>;
|
|
50
52
|
[Symbol.iterator](): MapIterator<[K, V]>;
|
|
51
|
-
[Symbol.toStringTag]
|
|
53
|
+
readonly [Symbol.toStringTag] = "KeySortedMap";
|
|
52
54
|
/**
|
|
53
55
|
* Zero-allocation callbacks over sorted data (faster than spreading to arrays).
|
|
54
56
|
*/
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { _assert } from '../error/index.js';
|
|
2
|
-
|
|
3
|
-
* Maintains sorted array of keys.
|
|
4
|
-
* Sorts **data access**, not on insertion.
|
|
5
|
-
*
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
2
|
+
// oxlint-disable-next-line no-unsafe-declaration-merging -- Map<K,V> workaround for oxlint TS2420 false positive
|
|
8
3
|
export class LazyKeySortedMap {
|
|
9
4
|
map;
|
|
10
5
|
maybeSortedKeys;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.67.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2"
|
|
7
7
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@typescript/native-preview": "7.0.0-dev.20260201.1",
|
|
25
25
|
"crypto-js": "^4",
|
|
26
26
|
"dayjs": "^1",
|
|
27
|
-
"@naturalcycles/dev-lib": "
|
|
27
|
+
"@naturalcycles/dev-lib": "20.36.0"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
".": "./dist/index.js",
|
|
@@ -22,7 +22,11 @@ export interface KeySortedMapOptions<K> {
|
|
|
22
22
|
*
|
|
23
23
|
* @experimental
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
// oxlint-disable-next-line no-unsafe-declaration-merging -- Map<K,V> workaround for oxlint TS2420 false positive
|
|
26
|
+
export interface KeySortedMap<K, V> extends Map<K, V> {}
|
|
27
|
+
|
|
28
|
+
// oxlint-disable-next-line no-unsafe-declaration-merging -- Map<K,V> workaround for oxlint TS2420 false positive
|
|
29
|
+
export class KeySortedMap<K, V> {
|
|
26
30
|
private readonly map: Map<K, V>
|
|
27
31
|
readonly #sortedKeys: K[]
|
|
28
32
|
|
|
@@ -140,7 +144,7 @@ export class KeySortedMap<K, V> implements Map<K, V> {
|
|
|
140
144
|
return 'abc'
|
|
141
145
|
}
|
|
142
146
|
|
|
143
|
-
[Symbol.toStringTag] = 'KeySortedMap'
|
|
147
|
+
readonly [Symbol.toStringTag] = 'KeySortedMap'
|
|
144
148
|
|
|
145
149
|
/**
|
|
146
150
|
* Zero-allocation callbacks over sorted data (faster than spreading to arrays).
|
|
@@ -148,7 +152,7 @@ export class KeySortedMap<K, V> implements Map<K, V> {
|
|
|
148
152
|
forEach(cb: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {
|
|
149
153
|
const { map } = this
|
|
150
154
|
for (const k of this.#sortedKeys) {
|
|
151
|
-
cb.call(thisArg, map.get(k)!, k, this)
|
|
155
|
+
cb.call(thisArg, map.get(k)!, k, this as unknown as Map<K, V>)
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
|
|
@@ -17,7 +17,11 @@ export interface LazyKeySortedMapOptions<K> {
|
|
|
17
17
|
*
|
|
18
18
|
* @experimental
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
// oxlint-disable-next-line no-unsafe-declaration-merging -- Map<K,V> workaround for oxlint TS2420 false positive
|
|
21
|
+
export interface LazyKeySortedMap<K, V> extends Map<K, V> {}
|
|
22
|
+
|
|
23
|
+
// oxlint-disable-next-line no-unsafe-declaration-merging -- Map<K,V> workaround for oxlint TS2420 false positive
|
|
24
|
+
export class LazyKeySortedMap<K, V> {
|
|
21
25
|
private readonly map: Map<K, V>
|
|
22
26
|
private readonly maybeSortedKeys: K[]
|
|
23
27
|
private keysAreSorted = false
|
|
@@ -117,7 +121,7 @@ export class LazyKeySortedMap<K, V> implements Map<K, V> {
|
|
|
117
121
|
return this.entries()
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
[Symbol.toStringTag] = 'KeySortedMap'
|
|
124
|
+
readonly [Symbol.toStringTag] = 'KeySortedMap'
|
|
121
125
|
|
|
122
126
|
/**
|
|
123
127
|
* Zero-allocation callbacks over sorted data (faster than spreading to arrays).
|
|
@@ -125,7 +129,7 @@ export class LazyKeySortedMap<K, V> implements Map<K, V> {
|
|
|
125
129
|
forEach(cb: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void {
|
|
126
130
|
const { map } = this
|
|
127
131
|
for (const k of this.getSortedKeys()) {
|
|
128
|
-
cb.call(thisArg, map.get(k)!, k, this)
|
|
132
|
+
cb.call(thisArg, map.get(k)!, k, this as unknown as Map<K, V>)
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
|