@tstdl/base 0.83.7 → 0.83.9
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/.eslintrc.cjs +1 -1
- package/data-structures/multi-key-map.d.ts +15 -14
- package/data-structures/multi-key-map.js +50 -53
- package/package.json +1 -1
package/.eslintrc.cjs
CHANGED
|
@@ -66,7 +66,7 @@ module.exports = {
|
|
|
66
66
|
|
|
67
67
|
/** import */
|
|
68
68
|
'import/no-duplicates': ['warn', { 'prefer-inline': true }],
|
|
69
|
-
'import/no-cycle': ['
|
|
69
|
+
'import/no-cycle': ['off', { ignoreExternal: true }],
|
|
70
70
|
'import/no-self-import': ['error'],
|
|
71
71
|
'import/no-extraneous-dependencies': ['error', { devDependencies: false, includeTypes: true }],
|
|
72
72
|
'import/no-empty-named-blocks': ['error'],
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dictionary } from './dictionary.js';
|
|
2
2
|
type Node = {
|
|
3
3
|
nodeKey: any;
|
|
4
4
|
parentNode: Node | undefined;
|
|
5
|
-
|
|
6
|
-
children: Map<any, Node>;
|
|
5
|
+
children: Map<any, Node> | undefined;
|
|
7
6
|
hasValue: boolean;
|
|
8
7
|
value: any;
|
|
9
8
|
};
|
|
10
9
|
type NewMapProvider = () => Map<any, Node>;
|
|
11
|
-
export declare class MultiKeyMap<K extends any[],
|
|
10
|
+
export declare class MultiKeyMap<K extends any[], V> extends Dictionary<K, V, MultiKeyMap<K, V>> {
|
|
12
11
|
private readonly newMapProvider;
|
|
13
12
|
private rootNode;
|
|
14
13
|
readonly [Symbol.toStringTag]: string;
|
|
15
14
|
constructor(newMapProvider?: NewMapProvider);
|
|
16
|
-
includes([key, value]: [K,
|
|
17
|
-
add(value: [K,
|
|
18
|
-
addMany(values: Iterable<[K,
|
|
19
|
-
|
|
15
|
+
includes([key, value]: [K, V]): boolean;
|
|
16
|
+
add(value: [K, V]): void;
|
|
17
|
+
addMany(values: Iterable<[K, V]>): void;
|
|
18
|
+
setFlat(...keyAndValue: [...key: K, value: V]): void;
|
|
19
|
+
set(key: K, value: V): void;
|
|
20
|
+
hasFlat(...key: K): boolean;
|
|
20
21
|
has(key: K): boolean;
|
|
21
|
-
|
|
22
|
+
getFlat(...key: K): V | undefined;
|
|
23
|
+
get(key: K): V | undefined;
|
|
24
|
+
deleteFlat(...key: K): boolean;
|
|
22
25
|
delete(key: K): boolean;
|
|
23
|
-
clone(): MultiKeyMap<K,
|
|
24
|
-
forEach(callback: (value: T, key: K, map: MultiKeyMap<K, T>) => void, thisArg?: any): void;
|
|
25
|
-
entries(): IterableIterator<[K, T]>;
|
|
26
|
+
clone(): MultiKeyMap<K, V>;
|
|
26
27
|
keys(): IterableIterator<K>;
|
|
27
|
-
values(): IterableIterator<
|
|
28
|
-
items(): IterableIterator<[K,
|
|
28
|
+
values(): IterableIterator<V>;
|
|
29
|
+
items(): IterableIterator<[K, V]>;
|
|
29
30
|
protected _clear(): void;
|
|
30
31
|
private getNode;
|
|
31
32
|
private deleteNodeIfEmpty;
|
|
@@ -21,18 +21,17 @@ __export(multi_key_map_exports, {
|
|
|
21
21
|
MultiKeyMap: () => MultiKeyMap
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(multi_key_map_exports);
|
|
24
|
-
var import_lazy_property = require("../utils/object/lazy-property.js");
|
|
25
24
|
var import_type_guards = require("../utils/type-guards.js");
|
|
26
25
|
var import_circular_buffer = require("./circular-buffer.js");
|
|
27
|
-
var
|
|
28
|
-
class MultiKeyMap extends
|
|
26
|
+
var import_dictionary = require("./dictionary.js");
|
|
27
|
+
class MultiKeyMap extends import_dictionary.Dictionary {
|
|
29
28
|
newMapProvider;
|
|
30
29
|
rootNode;
|
|
31
30
|
[Symbol.toStringTag] = "MultiKeyMap";
|
|
32
31
|
constructor(newMapProvider = () => /* @__PURE__ */ new Map()) {
|
|
33
32
|
super();
|
|
34
33
|
this.newMapProvider = newMapProvider;
|
|
35
|
-
this.rootNode = createNode(void 0, void 0
|
|
34
|
+
this.rootNode = createNode(void 0, void 0);
|
|
36
35
|
}
|
|
37
36
|
includes([key, value]) {
|
|
38
37
|
if (!this.has(key)) {
|
|
@@ -48,29 +47,40 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
48
47
|
this.set(value[0], value[1]);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
50
|
+
setFlat(...keyAndValue) {
|
|
51
|
+
const key = keyAndValue.slice(0, -1);
|
|
52
|
+
this.set(key, keyAndValue[keyAndValue.length - 1]);
|
|
53
|
+
}
|
|
51
54
|
set(key, value) {
|
|
52
55
|
const node = this.getNode(key, true);
|
|
53
|
-
const hasValue = node.hasValue;
|
|
54
|
-
node.hasValue = true;
|
|
55
56
|
node.value = value;
|
|
56
|
-
if (!hasValue) {
|
|
57
|
+
if (!node.hasValue) {
|
|
58
|
+
node.hasValue = true;
|
|
57
59
|
this.incrementSize();
|
|
58
60
|
}
|
|
59
|
-
|
|
61
|
+
}
|
|
62
|
+
hasFlat(...key) {
|
|
63
|
+
return this.has(key);
|
|
60
64
|
}
|
|
61
65
|
has(key) {
|
|
62
|
-
const node = this.getNode(key
|
|
66
|
+
const node = this.getNode(key);
|
|
63
67
|
return (0, import_type_guards.isDefined)(node) && node.hasValue;
|
|
64
68
|
}
|
|
69
|
+
getFlat(...key) {
|
|
70
|
+
return this.get(key);
|
|
71
|
+
}
|
|
65
72
|
get(key) {
|
|
66
|
-
const node = this.getNode(key
|
|
73
|
+
const node = this.getNode(key);
|
|
67
74
|
if ((0, import_type_guards.isUndefined)(node)) {
|
|
68
75
|
return void 0;
|
|
69
76
|
}
|
|
70
77
|
return node.value;
|
|
71
78
|
}
|
|
79
|
+
deleteFlat(...key) {
|
|
80
|
+
return this.delete(key);
|
|
81
|
+
}
|
|
72
82
|
delete(key) {
|
|
73
|
-
const node = this.getNode(key
|
|
83
|
+
const node = this.getNode(key);
|
|
74
84
|
if ((0, import_type_guards.isUndefined)(node)) {
|
|
75
85
|
return false;
|
|
76
86
|
}
|
|
@@ -88,15 +98,6 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
88
98
|
clone.addMany(this);
|
|
89
99
|
return clone;
|
|
90
100
|
}
|
|
91
|
-
forEach(callback, thisArg) {
|
|
92
|
-
const boundCallback = callback.bind(thisArg);
|
|
93
|
-
for (const item of this) {
|
|
94
|
-
boundCallback(item[1], item[0], this);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
entries() {
|
|
98
|
-
return this.items();
|
|
99
|
-
}
|
|
100
101
|
*keys() {
|
|
101
102
|
for (const item of this) {
|
|
102
103
|
yield item[0];
|
|
@@ -115,7 +116,7 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
115
116
|
if (node.hasValue) {
|
|
116
117
|
yield [key, node.value];
|
|
117
118
|
}
|
|
118
|
-
if (node.
|
|
119
|
+
if ((0, import_type_guards.isDefined)(node.children)) {
|
|
119
120
|
for (const innerNode of node.children.values()) {
|
|
120
121
|
queue.add([[...key, innerNode.nodeKey], innerNode]);
|
|
121
122
|
}
|
|
@@ -123,48 +124,44 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
_clear() {
|
|
126
|
-
this.rootNode = createNode(void 0, void 0
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
this.rootNode = createNode(void 0, void 0);
|
|
128
|
+
this.setSize(0);
|
|
129
|
+
}
|
|
130
|
+
getNode(key, create = false) {
|
|
131
|
+
let node = this.rootNode;
|
|
132
|
+
for (const nodeKey of key) {
|
|
133
|
+
if ((0, import_type_guards.isUndefined)(node.children)) {
|
|
134
|
+
if (!create) {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
node.children = this.newMapProvider();
|
|
133
138
|
}
|
|
134
|
-
|
|
139
|
+
let childNode = node.children.get(nodeKey);
|
|
140
|
+
if ((0, import_type_guards.isUndefined)(childNode)) {
|
|
141
|
+
if (!create) {
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
childNode = createNode(nodeKey, node);
|
|
145
|
+
node.children.set(nodeKey, childNode);
|
|
146
|
+
}
|
|
147
|
+
node = childNode;
|
|
135
148
|
}
|
|
136
149
|
return node;
|
|
137
150
|
}
|
|
138
151
|
deleteNodeIfEmpty(node) {
|
|
139
|
-
if (node.hasValue || node.
|
|
152
|
+
if (node.hasValue || (0, import_type_guards.isDefined)(node.children) && node.children.size > 0 || (0, import_type_guards.isUndefined)(node.parentNode)) {
|
|
140
153
|
return;
|
|
141
154
|
}
|
|
142
155
|
node.parentNode.children.delete(node.nodeKey);
|
|
143
156
|
this.deleteNodeIfEmpty(node.parentNode);
|
|
144
157
|
}
|
|
145
158
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const newNode = createNode(key, node, newMapProvider);
|
|
152
|
-
node.children.set(key, newNode);
|
|
153
|
-
return newNode;
|
|
154
|
-
}
|
|
155
|
-
function createNode(nodeKey, parentNode, newMapProvider) {
|
|
156
|
-
return (0, import_lazy_property.lazyObject)({
|
|
157
|
-
nodeKey: { value: nodeKey },
|
|
158
|
-
parentNode: { value: parentNode },
|
|
159
|
-
hasInnerMap: false,
|
|
160
|
-
children() {
|
|
161
|
-
return getChildren(this, newMapProvider);
|
|
162
|
-
},
|
|
159
|
+
function createNode(nodeKey, parentNode) {
|
|
160
|
+
return {
|
|
161
|
+
nodeKey,
|
|
162
|
+
parentNode,
|
|
163
|
+
children: void 0,
|
|
163
164
|
hasValue: false,
|
|
164
|
-
value:
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function getChildren(node, newMapProvider) {
|
|
168
|
-
node.hasInnerMap = true;
|
|
169
|
-
return newMapProvider();
|
|
165
|
+
value: void 0
|
|
166
|
+
};
|
|
170
167
|
}
|