@tstdl/base 0.83.6 → 0.83.8
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 +2 -2
- package/data-structures/array-dictionary.d.ts +20 -0
- package/data-structures/array-dictionary.js +118 -0
- package/data-structures/collection.d.ts +10 -10
- package/data-structures/collection.js +10 -10
- package/data-structures/dictionary.d.ts +29 -0
- package/data-structures/dictionary.js +78 -0
- package/data-structures/index.d.ts +3 -1
- package/data-structures/index.js +3 -1
- package/data-structures/map-dictionary.d.ts +19 -0
- package/data-structures/{map.js → map-dictionary.js} +25 -32
- package/data-structures/multi-key-map.d.ts +14 -12
- package/data-structures/multi-key-map.js +15 -12
- package/package.json +3 -3
- package/utils/array/array.js +3 -5
- package/data-structures/map.d.ts +0 -21
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'],
|
|
@@ -102,7 +102,7 @@ module.exports = {
|
|
|
102
102
|
'lines-between-class-members': 'off',
|
|
103
103
|
'max-classes-per-file': 'off',
|
|
104
104
|
'max-len': ['off', { code: 150 }],
|
|
105
|
-
'max-lines-per-function': ['
|
|
105
|
+
'max-lines-per-function': ['off', { 'max': 100, 'skipBlankLines': true, 'skipComments': true }],
|
|
106
106
|
'max-lines': 'off',
|
|
107
107
|
'max-params': 'off',
|
|
108
108
|
'max-statements': 'off',
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Dictionary } from './dictionary.js';
|
|
2
|
+
export declare class ArrayDictionary<K, V> extends Dictionary<K, V, ArrayDictionary<K, V>> {
|
|
3
|
+
private keyArray;
|
|
4
|
+
private valueArray;
|
|
5
|
+
readonly [Symbol.toStringTag]: string;
|
|
6
|
+
constructor(items?: Iterable<readonly [K, V]>);
|
|
7
|
+
has(key: K): boolean;
|
|
8
|
+
get(key: K): V | undefined;
|
|
9
|
+
set(key: K, value: V): void;
|
|
10
|
+
delete(key: K): boolean;
|
|
11
|
+
includes([key, value]: [K, V]): boolean;
|
|
12
|
+
add(item: [K, V]): void;
|
|
13
|
+
addMany(items: Iterable<readonly [K, V]>): void;
|
|
14
|
+
clone(): ArrayDictionary<K, V>;
|
|
15
|
+
items(): IterableIterator<[K, V]>;
|
|
16
|
+
keys(): IterableIterator<K>;
|
|
17
|
+
values(): IterableIterator<V>;
|
|
18
|
+
protected _clear(): void;
|
|
19
|
+
private updateSize;
|
|
20
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var array_dictionary_exports = {};
|
|
20
|
+
__export(array_dictionary_exports, {
|
|
21
|
+
ArrayDictionary: () => ArrayDictionary
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(array_dictionary_exports);
|
|
24
|
+
var import_type_guards = require("../utils/type-guards.js");
|
|
25
|
+
var import_dictionary = require("./dictionary.js");
|
|
26
|
+
class ArrayDictionary extends import_dictionary.Dictionary {
|
|
27
|
+
keyArray;
|
|
28
|
+
valueArray;
|
|
29
|
+
[Symbol.toStringTag] = "ArrayDictionary";
|
|
30
|
+
constructor(items) {
|
|
31
|
+
super();
|
|
32
|
+
this.keyArray = [];
|
|
33
|
+
this.valueArray = [];
|
|
34
|
+
if ((0, import_type_guards.isDefined)(items)) {
|
|
35
|
+
this.addMany(items);
|
|
36
|
+
this.updateSize();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
has(key) {
|
|
40
|
+
return this.keyArray.includes(key);
|
|
41
|
+
}
|
|
42
|
+
get(key) {
|
|
43
|
+
const index = this.keyArray.indexOf(key);
|
|
44
|
+
if (index == -1) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
return this.valueArray[index];
|
|
48
|
+
}
|
|
49
|
+
set(key, value) {
|
|
50
|
+
const index = this.keyArray.indexOf(key);
|
|
51
|
+
if (index == -1) {
|
|
52
|
+
this.keyArray.push(key);
|
|
53
|
+
this.valueArray.push(value);
|
|
54
|
+
} else {
|
|
55
|
+
this.valueArray[index] = value;
|
|
56
|
+
}
|
|
57
|
+
this.updateSize();
|
|
58
|
+
}
|
|
59
|
+
delete(key) {
|
|
60
|
+
const index = this.keyArray.indexOf(key);
|
|
61
|
+
if (index == -1) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
this.keyArray[index] = this.keyArray[this.keyArray.length - 1];
|
|
65
|
+
this.valueArray[index] = this.valueArray[this.valueArray.length - 1];
|
|
66
|
+
this.keyArray.length -= 1;
|
|
67
|
+
this.valueArray.length -= 1;
|
|
68
|
+
this.updateSize();
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
includes([key, value]) {
|
|
72
|
+
const index = this.keyArray.indexOf(key);
|
|
73
|
+
if (index == -1) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return this.valueArray[index] == value;
|
|
77
|
+
}
|
|
78
|
+
add(item) {
|
|
79
|
+
this.set(item[0], item[1]);
|
|
80
|
+
}
|
|
81
|
+
addMany(items) {
|
|
82
|
+
for (const [key, value] of items) {
|
|
83
|
+
const index = this.keyArray.indexOf(key);
|
|
84
|
+
if (index == -1) {
|
|
85
|
+
this.keyArray.push(key);
|
|
86
|
+
this.valueArray.push(value);
|
|
87
|
+
} else {
|
|
88
|
+
this.valueArray[index] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this.updateSize();
|
|
92
|
+
}
|
|
93
|
+
clone() {
|
|
94
|
+
const arrayDictionary = new ArrayDictionary();
|
|
95
|
+
arrayDictionary.keyArray = [...this.keyArray];
|
|
96
|
+
arrayDictionary.valueArray = [...this.valueArray];
|
|
97
|
+
arrayDictionary.updateSize();
|
|
98
|
+
return arrayDictionary;
|
|
99
|
+
}
|
|
100
|
+
*items() {
|
|
101
|
+
for (let i = 0; i < this.keyArray.length; i++) {
|
|
102
|
+
yield [this.keyArray[i], this.valueArray[i]];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
keys() {
|
|
106
|
+
return this.keyArray[Symbol.iterator]();
|
|
107
|
+
}
|
|
108
|
+
values() {
|
|
109
|
+
return this.valueArray[Symbol.iterator]();
|
|
110
|
+
}
|
|
111
|
+
_clear() {
|
|
112
|
+
this.keyArray = [];
|
|
113
|
+
this.valueArray = [];
|
|
114
|
+
}
|
|
115
|
+
updateSize() {
|
|
116
|
+
this.setSize(this.keyArray.length / 2);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -6,28 +6,28 @@ export declare abstract class Collection<T, TThis extends Collection<T, TThis> =
|
|
|
6
6
|
private readonly clearSubject;
|
|
7
7
|
/** emits collection on subscribe and change */
|
|
8
8
|
readonly observe$: Observable<TThis>;
|
|
9
|
-
/** emits size of
|
|
9
|
+
/** emits size of collection */
|
|
10
10
|
readonly size$: Observable<number>;
|
|
11
11
|
/** emits collection on change */
|
|
12
12
|
readonly change$: Observable<TThis>;
|
|
13
13
|
readonly clear$: Observable<TThis>;
|
|
14
|
-
/** emits when the
|
|
14
|
+
/** emits when the collection is empty */
|
|
15
15
|
readonly onEmpty$: Observable<void>;
|
|
16
|
-
/** emits when the
|
|
16
|
+
/** emits when the collection has items */
|
|
17
17
|
readonly onItems$: Observable<void>;
|
|
18
|
-
/** emits whether the
|
|
18
|
+
/** emits whether the collection is empty */
|
|
19
19
|
readonly isEmpty$: Observable<boolean>;
|
|
20
|
-
/** emits whether the
|
|
20
|
+
/** emits whether the collection has items */
|
|
21
21
|
readonly hasItems$: Observable<boolean>;
|
|
22
|
-
/** resolves when the
|
|
22
|
+
/** resolves when the collection is empty */
|
|
23
23
|
get $onEmpty(): Promise<void>;
|
|
24
|
-
/** resolves when the
|
|
24
|
+
/** resolves when the collection has items */
|
|
25
25
|
get $onItems(): Promise<void>;
|
|
26
|
-
/** size of
|
|
26
|
+
/** size of collection */
|
|
27
27
|
get size(): number;
|
|
28
|
-
/** whether the
|
|
28
|
+
/** whether the collection is empty */
|
|
29
29
|
get isEmpty(): boolean;
|
|
30
|
-
/** whether the
|
|
30
|
+
/** whether the collection has items */
|
|
31
31
|
get hasItems(): boolean;
|
|
32
32
|
constructor();
|
|
33
33
|
[Symbol.iterator](): IterableIterator<T>;
|
|
@@ -28,37 +28,37 @@ class Collection {
|
|
|
28
28
|
clearSubject;
|
|
29
29
|
/** emits collection on subscribe and change */
|
|
30
30
|
observe$;
|
|
31
|
-
/** emits size of
|
|
31
|
+
/** emits size of collection */
|
|
32
32
|
size$;
|
|
33
33
|
/** emits collection on change */
|
|
34
34
|
change$;
|
|
35
35
|
/* emits collection on clear */
|
|
36
36
|
clear$;
|
|
37
|
-
/** emits when the
|
|
37
|
+
/** emits when the collection is empty */
|
|
38
38
|
onEmpty$;
|
|
39
|
-
/** emits when the
|
|
39
|
+
/** emits when the collection has items */
|
|
40
40
|
onItems$;
|
|
41
|
-
/** emits whether the
|
|
41
|
+
/** emits whether the collection is empty */
|
|
42
42
|
isEmpty$;
|
|
43
|
-
/** emits whether the
|
|
43
|
+
/** emits whether the collection has items */
|
|
44
44
|
hasItems$;
|
|
45
|
-
/** resolves when the
|
|
45
|
+
/** resolves when the collection is empty */
|
|
46
46
|
get $onEmpty() {
|
|
47
47
|
return (0, import_rxjs.firstValueFrom)(this.onEmpty$);
|
|
48
48
|
}
|
|
49
|
-
/** resolves when the
|
|
49
|
+
/** resolves when the collection has items */
|
|
50
50
|
get $onItems() {
|
|
51
51
|
return (0, import_rxjs.firstValueFrom)(this.onItems$);
|
|
52
52
|
}
|
|
53
|
-
/** size of
|
|
53
|
+
/** size of collection */
|
|
54
54
|
get size() {
|
|
55
55
|
return this.sizeSubject.value;
|
|
56
56
|
}
|
|
57
|
-
/** whether the
|
|
57
|
+
/** whether the collection is empty */
|
|
58
58
|
get isEmpty() {
|
|
59
59
|
return this.size == 0;
|
|
60
60
|
}
|
|
61
|
-
/** whether the
|
|
61
|
+
/** whether the collection has items */
|
|
62
62
|
get hasItems() {
|
|
63
63
|
return this.size > 0;
|
|
64
64
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Collection } from './collection.js';
|
|
2
|
+
export declare abstract class Dictionary<K, V, TThis extends Dictionary<K, V, TThis> = Dictionary<K, V, any>> extends Collection<[K, V], TThis> {
|
|
3
|
+
/** Creates a new map and copies the items */
|
|
4
|
+
toMap(): Map<K, V>;
|
|
5
|
+
/** Returns an adapter that has the same interface as {@link Map}. No copying of data involved. */
|
|
6
|
+
asMap(): Map<K, V>;
|
|
7
|
+
abstract has(key: K): boolean;
|
|
8
|
+
abstract get(key: K): V | undefined;
|
|
9
|
+
abstract set(key: K, value: V): void;
|
|
10
|
+
abstract delete(key: K): boolean;
|
|
11
|
+
abstract keys(): IterableIterator<K>;
|
|
12
|
+
abstract values(): IterableIterator<V>;
|
|
13
|
+
}
|
|
14
|
+
export declare class DictionaryAdapter<K, V> implements Map<K, V> {
|
|
15
|
+
private readonly dictionary;
|
|
16
|
+
readonly [Symbol.toStringTag] = "DictionaryAdapter";
|
|
17
|
+
get size(): number;
|
|
18
|
+
constructor(dictionary: Dictionary<K, V, any>);
|
|
19
|
+
clear(): void;
|
|
20
|
+
delete(key: K): boolean;
|
|
21
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
22
|
+
get(key: K): V | undefined;
|
|
23
|
+
has(key: K): boolean;
|
|
24
|
+
set(key: K, value: V): this;
|
|
25
|
+
entries(): IterableIterator<[K, V]>;
|
|
26
|
+
keys(): IterableIterator<K>;
|
|
27
|
+
values(): IterableIterator<V>;
|
|
28
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var dictionary_exports = {};
|
|
20
|
+
__export(dictionary_exports, {
|
|
21
|
+
Dictionary: () => Dictionary,
|
|
22
|
+
DictionaryAdapter: () => DictionaryAdapter
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(dictionary_exports);
|
|
25
|
+
var import_collection = require("./collection.js");
|
|
26
|
+
class Dictionary extends import_collection.Collection {
|
|
27
|
+
/** Creates a new map and copies the items */
|
|
28
|
+
toMap() {
|
|
29
|
+
return new Map(this);
|
|
30
|
+
}
|
|
31
|
+
/** Returns an adapter that has the same interface as {@link Map}. No copying of data involved. */
|
|
32
|
+
asMap() {
|
|
33
|
+
return new DictionaryAdapter(this);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class DictionaryAdapter {
|
|
37
|
+
dictionary;
|
|
38
|
+
[Symbol.toStringTag] = "DictionaryAdapter";
|
|
39
|
+
get size() {
|
|
40
|
+
return this.dictionary.size;
|
|
41
|
+
}
|
|
42
|
+
constructor(dictionary) {
|
|
43
|
+
this.dictionary = dictionary;
|
|
44
|
+
}
|
|
45
|
+
clear() {
|
|
46
|
+
this.dictionary.clear();
|
|
47
|
+
}
|
|
48
|
+
delete(key) {
|
|
49
|
+
return this.dictionary.delete(key);
|
|
50
|
+
}
|
|
51
|
+
forEach(callbackfn, thisArg) {
|
|
52
|
+
for (const [key, value] of this.dictionary) {
|
|
53
|
+
callbackfn.call(thisArg, value, key, this);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
get(key) {
|
|
57
|
+
return this.dictionary.get(key);
|
|
58
|
+
}
|
|
59
|
+
has(key) {
|
|
60
|
+
return this.dictionary.has(key);
|
|
61
|
+
}
|
|
62
|
+
set(key, value) {
|
|
63
|
+
this.dictionary.set(key, value);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
entries() {
|
|
67
|
+
return this.dictionary.items();
|
|
68
|
+
}
|
|
69
|
+
keys() {
|
|
70
|
+
return this.dictionary.keys();
|
|
71
|
+
}
|
|
72
|
+
values() {
|
|
73
|
+
return this.dictionary.values();
|
|
74
|
+
}
|
|
75
|
+
[Symbol.iterator]() {
|
|
76
|
+
return this.dictionary[Symbol.iterator]();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
export * from './array-dictionary.js';
|
|
1
2
|
export * from './array-list.js';
|
|
2
3
|
export * from './circular-buffer.js';
|
|
3
4
|
export * from './collection.js';
|
|
5
|
+
export * from './dictionary.js';
|
|
4
6
|
export * from './index-out-of-bounds.error.js';
|
|
5
7
|
export * from './iterable-weak-map.js';
|
|
6
8
|
export * from './linked-list.js';
|
|
7
9
|
export * from './list.js';
|
|
8
|
-
export * from './map.js';
|
|
10
|
+
export * from './map-dictionary.js';
|
|
9
11
|
export * from './multi-key-map.js';
|
|
10
12
|
export * from './set.js';
|
|
11
13
|
export * from './sorted-array-list.js';
|
package/data-structures/index.js
CHANGED
|
@@ -15,14 +15,16 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var data_structures_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(data_structures_exports);
|
|
18
|
+
__reExport(data_structures_exports, require("./array-dictionary.js"), module.exports);
|
|
18
19
|
__reExport(data_structures_exports, require("./array-list.js"), module.exports);
|
|
19
20
|
__reExport(data_structures_exports, require("./circular-buffer.js"), module.exports);
|
|
20
21
|
__reExport(data_structures_exports, require("./collection.js"), module.exports);
|
|
22
|
+
__reExport(data_structures_exports, require("./dictionary.js"), module.exports);
|
|
21
23
|
__reExport(data_structures_exports, require("./index-out-of-bounds.error.js"), module.exports);
|
|
22
24
|
__reExport(data_structures_exports, require("./iterable-weak-map.js"), module.exports);
|
|
23
25
|
__reExport(data_structures_exports, require("./linked-list.js"), module.exports);
|
|
24
26
|
__reExport(data_structures_exports, require("./list.js"), module.exports);
|
|
25
|
-
__reExport(data_structures_exports, require("./map.js"), module.exports);
|
|
27
|
+
__reExport(data_structures_exports, require("./map-dictionary.js"), module.exports);
|
|
26
28
|
__reExport(data_structures_exports, require("./multi-key-map.js"), module.exports);
|
|
27
29
|
__reExport(data_structures_exports, require("./set.js"), module.exports);
|
|
28
30
|
__reExport(data_structures_exports, require("./sorted-array-list.js"), module.exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Dictionary } from './dictionary.js';
|
|
2
|
+
export declare class MapDictionary<K, V> extends Dictionary<K, V, MapDictionary<K, V>> {
|
|
3
|
+
private readonly backingMap;
|
|
4
|
+
readonly [Symbol.toStringTag]: string;
|
|
5
|
+
constructor(items?: Iterable<readonly [K, V]>);
|
|
6
|
+
has(key: K): boolean;
|
|
7
|
+
get(key: K): V | undefined;
|
|
8
|
+
set(key: K, value: V): void;
|
|
9
|
+
delete(key: K): boolean;
|
|
10
|
+
includes([key, value]: [K, V]): boolean;
|
|
11
|
+
add(item: [K, V]): void;
|
|
12
|
+
addMany(items: Iterable<readonly [K, V]>): void;
|
|
13
|
+
clone(): MapDictionary<K, V>;
|
|
14
|
+
items(): IterableIterator<[K, V]>;
|
|
15
|
+
keys(): IterableIterator<K>;
|
|
16
|
+
values(): IterableIterator<V>;
|
|
17
|
+
protected _clear(): void;
|
|
18
|
+
private updateSize;
|
|
19
|
+
}
|
|
@@ -16,33 +16,43 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var map_dictionary_exports = {};
|
|
20
|
+
__export(map_dictionary_exports, {
|
|
21
|
+
MapDictionary: () => MapDictionary
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
var
|
|
25
|
-
class
|
|
23
|
+
module.exports = __toCommonJS(map_dictionary_exports);
|
|
24
|
+
var import_dictionary = require("./dictionary.js");
|
|
25
|
+
class MapDictionary extends import_dictionary.Dictionary {
|
|
26
26
|
backingMap;
|
|
27
|
-
[Symbol.toStringTag] = "
|
|
27
|
+
[Symbol.toStringTag] = "MapDictionary";
|
|
28
28
|
constructor(items) {
|
|
29
29
|
super();
|
|
30
|
-
this.backingMap = new
|
|
30
|
+
this.backingMap = new Map(items);
|
|
31
31
|
this.updateSize();
|
|
32
32
|
}
|
|
33
|
+
has(key) {
|
|
34
|
+
return this.backingMap.has(key);
|
|
35
|
+
}
|
|
36
|
+
get(key) {
|
|
37
|
+
return this.backingMap.get(key);
|
|
38
|
+
}
|
|
39
|
+
set(key, value) {
|
|
40
|
+
this.backingMap.set(key, value);
|
|
41
|
+
this.updateSize();
|
|
42
|
+
}
|
|
43
|
+
delete(key) {
|
|
44
|
+
const result = this.backingMap.delete(key);
|
|
45
|
+
this.updateSize();
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
33
48
|
includes([key, value]) {
|
|
34
49
|
if (!this.has(key)) {
|
|
35
50
|
return false;
|
|
36
51
|
}
|
|
37
52
|
return this.get(key) == value;
|
|
38
53
|
}
|
|
39
|
-
set(key, value) {
|
|
40
|
-
this.backingMap.set(key, value);
|
|
41
|
-
this.updateSize();
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
54
|
add(item) {
|
|
45
|
-
|
|
55
|
+
this.set(item[0], item[1]);
|
|
46
56
|
}
|
|
47
57
|
addMany(items) {
|
|
48
58
|
for (const item of items) {
|
|
@@ -50,29 +60,12 @@ class Map extends import_collection.Collection {
|
|
|
50
60
|
}
|
|
51
61
|
this.updateSize();
|
|
52
62
|
}
|
|
53
|
-
get(key) {
|
|
54
|
-
return this.backingMap.get(key);
|
|
55
|
-
}
|
|
56
63
|
clone() {
|
|
57
|
-
return new
|
|
64
|
+
return new MapDictionary(this);
|
|
58
65
|
}
|
|
59
66
|
items() {
|
|
60
67
|
return this.backingMap.entries();
|
|
61
68
|
}
|
|
62
|
-
delete(key) {
|
|
63
|
-
const result = this.backingMap.delete(key);
|
|
64
|
-
this.updateSize();
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
forEach(callbackfn, thisArg) {
|
|
68
|
-
this.backingMap.forEach(callbackfn, thisArg);
|
|
69
|
-
}
|
|
70
|
-
has(key) {
|
|
71
|
-
return this.backingMap.has(key);
|
|
72
|
-
}
|
|
73
|
-
entries() {
|
|
74
|
-
return this.backingMap.entries();
|
|
75
|
-
}
|
|
76
69
|
keys() {
|
|
77
70
|
return this.backingMap.keys();
|
|
78
71
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dictionary } from './dictionary.js';
|
|
2
2
|
type Node = {
|
|
3
3
|
nodeKey: any;
|
|
4
4
|
parentNode: Node | undefined;
|
|
@@ -8,24 +8,26 @@ type Node = {
|
|
|
8
8
|
value: any;
|
|
9
9
|
};
|
|
10
10
|
type NewMapProvider = () => Map<any, Node>;
|
|
11
|
-
export declare class MultiKeyMap<K extends any[],
|
|
11
|
+
export declare class MultiKeyMap<K extends any[], V> extends Dictionary<K, V, MultiKeyMap<K, V>> {
|
|
12
12
|
private readonly newMapProvider;
|
|
13
13
|
private rootNode;
|
|
14
14
|
readonly [Symbol.toStringTag]: string;
|
|
15
15
|
constructor(newMapProvider?: NewMapProvider);
|
|
16
|
-
includes([key, value]: [K,
|
|
17
|
-
add(value: [K,
|
|
18
|
-
addMany(values: Iterable<[K,
|
|
19
|
-
|
|
16
|
+
includes([key, value]: [K, V]): boolean;
|
|
17
|
+
add(value: [K, V]): void;
|
|
18
|
+
addMany(values: Iterable<[K, V]>): void;
|
|
19
|
+
setFlat(...keyAndValue: [...key: K, value: V]): void;
|
|
20
|
+
set(key: K, value: V): void;
|
|
21
|
+
hasFlat(...key: K): boolean;
|
|
20
22
|
has(key: K): boolean;
|
|
21
|
-
|
|
23
|
+
getFlat(...key: K): V | undefined;
|
|
24
|
+
get(key: K): V | undefined;
|
|
25
|
+
deleteFlat(...key: K): boolean;
|
|
22
26
|
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]>;
|
|
27
|
+
clone(): MultiKeyMap<K, V>;
|
|
26
28
|
keys(): IterableIterator<K>;
|
|
27
|
-
values(): IterableIterator<
|
|
28
|
-
items(): IterableIterator<[K,
|
|
29
|
+
values(): IterableIterator<V>;
|
|
30
|
+
items(): IterableIterator<[K, V]>;
|
|
29
31
|
protected _clear(): void;
|
|
30
32
|
private getNode;
|
|
31
33
|
private deleteNodeIfEmpty;
|
|
@@ -24,8 +24,8 @@ module.exports = __toCommonJS(multi_key_map_exports);
|
|
|
24
24
|
var import_lazy_property = require("../utils/object/lazy-property.js");
|
|
25
25
|
var import_type_guards = require("../utils/type-guards.js");
|
|
26
26
|
var import_circular_buffer = require("./circular-buffer.js");
|
|
27
|
-
var
|
|
28
|
-
class MultiKeyMap extends
|
|
27
|
+
var import_dictionary = require("./dictionary.js");
|
|
28
|
+
class MultiKeyMap extends import_dictionary.Dictionary {
|
|
29
29
|
newMapProvider;
|
|
30
30
|
rootNode;
|
|
31
31
|
[Symbol.toStringTag] = "MultiKeyMap";
|
|
@@ -48,6 +48,10 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
48
48
|
this.set(value[0], value[1]);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
setFlat(...keyAndValue) {
|
|
52
|
+
const key = keyAndValue.slice(0, -1);
|
|
53
|
+
this.set(key, keyAndValue[keyAndValue.length - 1]);
|
|
54
|
+
}
|
|
51
55
|
set(key, value) {
|
|
52
56
|
const node = this.getNode(key, true);
|
|
53
57
|
const hasValue = node.hasValue;
|
|
@@ -56,12 +60,17 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
56
60
|
if (!hasValue) {
|
|
57
61
|
this.incrementSize();
|
|
58
62
|
}
|
|
59
|
-
|
|
63
|
+
}
|
|
64
|
+
hasFlat(...key) {
|
|
65
|
+
return this.has(key);
|
|
60
66
|
}
|
|
61
67
|
has(key) {
|
|
62
68
|
const node = this.getNode(key, false);
|
|
63
69
|
return (0, import_type_guards.isDefined)(node) && node.hasValue;
|
|
64
70
|
}
|
|
71
|
+
getFlat(...key) {
|
|
72
|
+
return this.get(key);
|
|
73
|
+
}
|
|
65
74
|
get(key) {
|
|
66
75
|
const node = this.getNode(key, false);
|
|
67
76
|
if ((0, import_type_guards.isUndefined)(node)) {
|
|
@@ -69,6 +78,9 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
69
78
|
}
|
|
70
79
|
return node.value;
|
|
71
80
|
}
|
|
81
|
+
deleteFlat(...key) {
|
|
82
|
+
return this.delete(key);
|
|
83
|
+
}
|
|
72
84
|
delete(key) {
|
|
73
85
|
const node = this.getNode(key, false);
|
|
74
86
|
if ((0, import_type_guards.isUndefined)(node)) {
|
|
@@ -88,15 +100,6 @@ class MultiKeyMap extends import_collection.Collection {
|
|
|
88
100
|
clone.addMany(this);
|
|
89
101
|
return clone;
|
|
90
102
|
}
|
|
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
103
|
*keys() {
|
|
101
104
|
for (const item of this) {
|
|
102
105
|
yield item[0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.83.
|
|
3
|
+
"version": "0.83.8",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@types/mjml": "4.7",
|
|
32
32
|
"@types/node": "18",
|
|
33
33
|
"@types/nodemailer": "6.4",
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
35
|
-
"@typescript-eslint/parser": "5.
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "5.56",
|
|
35
|
+
"@typescript-eslint/parser": "5.56",
|
|
36
36
|
"concurrently": "7.6",
|
|
37
37
|
"eslint": "8.36",
|
|
38
38
|
"eslint-import-resolver-typescript": "3.5",
|
package/utils/array/array.js
CHANGED
|
@@ -42,11 +42,9 @@ function extractValueOfArrayIfSingleElement(value) {
|
|
|
42
42
|
return value;
|
|
43
43
|
}
|
|
44
44
|
function createArray(length, valueProvider) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
return array;
|
|
45
|
+
const arr = [];
|
|
46
|
+
arr.length = length;
|
|
47
|
+
return arr.fill(void 0).map((_, index) => valueProvider(index));
|
|
50
48
|
}
|
|
51
49
|
function shuffle(items) {
|
|
52
50
|
const cloned = [...items];
|
package/data-structures/map.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Collection } from './collection.js';
|
|
2
|
-
export declare class Map<K, V> extends Collection<[K, V], Map<K, V>> implements globalThis.Map<K, V> {
|
|
3
|
-
private readonly backingMap;
|
|
4
|
-
readonly [Symbol.toStringTag]: string;
|
|
5
|
-
constructor(items?: Iterable<[K, V]>);
|
|
6
|
-
includes([key, value]: [K, V]): boolean;
|
|
7
|
-
set(key: K, value: V): this;
|
|
8
|
-
add(item: [K, V]): this;
|
|
9
|
-
addMany(items: Iterable<[K, V]>): void;
|
|
10
|
-
get(key: K): V | undefined;
|
|
11
|
-
clone(): Map<K, V>;
|
|
12
|
-
items(): IterableIterator<[K, V]>;
|
|
13
|
-
delete(key: K): boolean;
|
|
14
|
-
forEach(callbackfn: (value: V, key: K, set: globalThis.Map<K, V>) => void, thisArg?: any): void;
|
|
15
|
-
has(key: K): boolean;
|
|
16
|
-
entries(): IterableIterator<[K, V]>;
|
|
17
|
-
keys(): IterableIterator<K>;
|
|
18
|
-
values(): IterableIterator<V>;
|
|
19
|
-
protected _clear(): void;
|
|
20
|
-
private updateSize;
|
|
21
|
-
}
|