@blackglory/structures 0.14.15 → 0.15.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.
- package/README.md +661 -92
- package/lib/async-generator-emitter.js +2 -5
- package/lib/async-generator-emitter.js.map +1 -1
- package/lib/big-map.js +1 -3
- package/lib/big-map.js.map +1 -1
- package/lib/big-set.js +1 -3
- package/lib/big-set.js.map +1 -1
- package/lib/{bit-set.d.ts → bit-set/bit-set.d.ts} +5 -2
- package/lib/{bit-set.js → bit-set/bit-set.js} +43 -34
- package/lib/bit-set/bit-set.js.map +1 -0
- package/lib/{typed-bit-set.d.ts → bit-set/dynamic-typed-bit-set.d.ts} +6 -4
- package/lib/bit-set/dynamic-typed-bit-set.js +95 -0
- package/lib/bit-set/dynamic-typed-bit-set.js.map +1 -0
- package/lib/bit-set/index.d.ts +4 -0
- package/lib/bit-set/index.js +5 -0
- package/lib/bit-set/index.js.map +1 -0
- package/lib/bit-set/resizable-typed-bit-set.d.ts +22 -0
- package/lib/{typed-bit-set.js → bit-set/resizable-typed-bit-set.js} +37 -39
- package/lib/bit-set/resizable-typed-bit-set.js.map +1 -0
- package/lib/bit-set/typed-bit-set.d.ts +22 -0
- package/lib/bit-set/typed-bit-set.js +99 -0
- package/lib/bit-set/typed-bit-set.js.map +1 -0
- package/lib/box.js +1 -0
- package/lib/box.js.map +1 -1
- package/lib/disjoint-set.js +2 -4
- package/lib/disjoint-set.js.map +1 -1
- package/lib/dynamic-typed-array.d.ts +12 -9
- package/lib/dynamic-typed-array.js +51 -66
- package/lib/dynamic-typed-array.js.map +1 -1
- package/lib/emitter.js +3 -7
- package/lib/emitter.js.map +1 -1
- package/lib/expirable-map.js +9 -15
- package/lib/expirable-map.js.map +1 -1
- package/lib/generator-emitter.js +2 -5
- package/lib/generator-emitter.js.map +1 -1
- package/lib/hash-map.js +2 -1
- package/lib/hash-map.js.map +1 -1
- package/lib/hash-set.js +2 -1
- package/lib/hash-set.js.map +1 -1
- package/lib/index.d.ts +5 -7
- package/lib/index.js +5 -7
- package/lib/index.js.map +1 -1
- package/lib/lru-map.js +2 -1
- package/lib/lru-map.js.map +1 -1
- package/lib/queue.js +1 -3
- package/lib/queue.js.map +1 -1
- package/lib/radix-tree.js +3 -4
- package/lib/radix-tree.js.map +1 -1
- package/lib/resizable-typed-array.d.ts +32 -0
- package/lib/resizable-typed-array.js +127 -0
- package/lib/resizable-typed-array.js.map +1 -0
- package/lib/sorted-set.js +2 -1
- package/lib/sorted-set.js.map +1 -1
- package/lib/sparse-map/clean-sparse-map.d.ts +18 -0
- package/lib/sparse-map/clean-sparse-map.js +74 -0
- package/lib/sparse-map/clean-sparse-map.js.map +1 -0
- package/lib/sparse-map/dynamic-typed-clean-sparse-map-lite.d.ts +21 -0
- package/lib/sparse-map/dynamic-typed-clean-sparse-map-lite.js +87 -0
- package/lib/sparse-map/dynamic-typed-clean-sparse-map-lite.js.map +1 -0
- package/lib/sparse-map/dynamic-typed-sparse-map-lite.d.ts +21 -0
- package/lib/sparse-map/dynamic-typed-sparse-map-lite.js +94 -0
- package/lib/sparse-map/dynamic-typed-sparse-map-lite.js.map +1 -0
- package/lib/sparse-map/index.d.ts +10 -0
- package/lib/sparse-map/index.js +11 -0
- package/lib/sparse-map/index.js.map +1 -0
- package/lib/sparse-map/resizable-typed-clean-sparse-map-lite.d.ts +21 -0
- package/lib/sparse-map/resizable-typed-clean-sparse-map-lite.js +85 -0
- package/lib/sparse-map/resizable-typed-clean-sparse-map-lite.js.map +1 -0
- package/lib/sparse-map/resizable-typed-sparse-map-lite.d.ts +21 -0
- package/lib/sparse-map/resizable-typed-sparse-map-lite.js +92 -0
- package/lib/sparse-map/resizable-typed-sparse-map-lite.js.map +1 -0
- package/lib/{sparse-map.d.ts → sparse-map/sparse-map.d.ts} +6 -5
- package/lib/sparse-map/sparse-map.js +86 -0
- package/lib/sparse-map/sparse-map.js.map +1 -0
- package/lib/sparse-map/typed-clean-sparse-map-lite.d.ts +21 -0
- package/lib/sparse-map/typed-clean-sparse-map-lite.js +92 -0
- package/lib/sparse-map/typed-clean-sparse-map-lite.js.map +1 -0
- package/lib/sparse-map/typed-clean-sparse-map.d.ts +22 -0
- package/lib/sparse-map/typed-clean-sparse-map.js +117 -0
- package/lib/sparse-map/typed-clean-sparse-map.js.map +1 -0
- package/lib/sparse-map/typed-sparse-map-lite.d.ts +21 -0
- package/lib/sparse-map/typed-sparse-map-lite.js +109 -0
- package/lib/sparse-map/typed-sparse-map-lite.js.map +1 -0
- package/lib/sparse-map/typed-sparse-map.d.ts +21 -0
- package/lib/sparse-map/typed-sparse-map.js +130 -0
- package/lib/sparse-map/typed-sparse-map.js.map +1 -0
- package/lib/sparse-set/clean-sparse-set.d.ts +13 -0
- package/lib/sparse-set/clean-sparse-set.js +57 -0
- package/lib/sparse-set/clean-sparse-set.js.map +1 -0
- package/lib/{typed-sparse-set.d.ts → sparse-set/dynamic-typed-clean-sparse-set-lite.d.ts} +6 -6
- package/lib/sparse-set/dynamic-typed-clean-sparse-set-lite.js +51 -0
- package/lib/sparse-set/dynamic-typed-clean-sparse-set-lite.js.map +1 -0
- package/lib/sparse-set/dynamic-typed-clean-sparse-set.d.ts +16 -0
- package/lib/sparse-set/dynamic-typed-clean-sparse-set.js +82 -0
- package/lib/sparse-set/dynamic-typed-clean-sparse-set.js.map +1 -0
- package/lib/sparse-set/dynamic-typed-sparse-set-lite.d.ts +15 -0
- package/lib/sparse-set/dynamic-typed-sparse-set-lite.js +52 -0
- package/lib/sparse-set/dynamic-typed-sparse-set-lite.js.map +1 -0
- package/lib/sparse-set/dynamic-typed-sparse-set.d.ts +15 -0
- package/lib/sparse-set/dynamic-typed-sparse-set.js +75 -0
- package/lib/sparse-set/dynamic-typed-sparse-set.js.map +1 -0
- package/lib/sparse-set/index.d.ts +14 -0
- package/lib/sparse-set/index.js +15 -0
- package/lib/sparse-set/index.js.map +1 -0
- package/lib/sparse-set/resizable-typed-clean-sparse-set-lite.d.ts +15 -0
- package/lib/sparse-set/resizable-typed-clean-sparse-set-lite.js +51 -0
- package/lib/sparse-set/resizable-typed-clean-sparse-set-lite.js.map +1 -0
- package/lib/sparse-set/resizable-typed-clean-sparse-set.d.ts +16 -0
- package/lib/sparse-set/resizable-typed-clean-sparse-set.js +83 -0
- package/lib/sparse-set/resizable-typed-clean-sparse-set.js.map +1 -0
- package/lib/sparse-set/resizable-typed-sparse-set-lite.d.ts +15 -0
- package/lib/sparse-set/resizable-typed-sparse-set-lite.js +52 -0
- package/lib/sparse-set/resizable-typed-sparse-set-lite.js.map +1 -0
- package/lib/sparse-set/resizable-typed-sparse-set.d.ts +15 -0
- package/lib/sparse-set/resizable-typed-sparse-set.js +76 -0
- package/lib/sparse-set/resizable-typed-sparse-set.js.map +1 -0
- package/lib/{sparse-set.d.ts → sparse-set/sparse-set.d.ts} +3 -4
- package/lib/sparse-set/sparse-set.js +60 -0
- package/lib/sparse-set/sparse-set.js.map +1 -0
- package/lib/sparse-set/typed-clean-sparse-set-lite.d.ts +15 -0
- package/lib/sparse-set/typed-clean-sparse-set-lite.js +55 -0
- package/lib/sparse-set/typed-clean-sparse-set-lite.js.map +1 -0
- package/lib/sparse-set/typed-clean-sparse-set.d.ts +16 -0
- package/lib/sparse-set/typed-clean-sparse-set.js +80 -0
- package/lib/sparse-set/typed-clean-sparse-set.js.map +1 -0
- package/lib/sparse-set/typed-sparse-set-lite.d.ts +15 -0
- package/lib/sparse-set/typed-sparse-set-lite.js +60 -0
- package/lib/sparse-set/typed-sparse-set-lite.js.map +1 -0
- package/lib/sparse-set/typed-sparse-set.d.ts +15 -0
- package/lib/sparse-set/typed-sparse-set.js +81 -0
- package/lib/sparse-set/typed-sparse-set.js.map +1 -0
- package/lib/string-radix-tree.js +3 -4
- package/lib/string-radix-tree.js.map +1 -1
- package/lib/string-trie-map.js +3 -4
- package/lib/string-trie-map.js.map +1 -1
- package/lib/tlru-map.js +6 -6
- package/lib/tlru-map.js.map +1 -1
- package/lib/trie-map.js +3 -4
- package/lib/trie-map.js.map +1 -1
- package/lib/unique-queue.js +1 -3
- package/lib/unique-queue.js.map +1 -1
- package/lib/utils/compute-new-capacity.d.ts +1 -0
- package/lib/utils/compute-new-capacity.js +36 -0
- package/lib/utils/compute-new-capacity.js.map +1 -0
- package/lib/utils/get-max-value-of-unsigned-typed-array.d.ts +3 -0
- package/lib/utils/get-max-value-of-unsigned-typed-array.js +13 -0
- package/lib/utils/get-max-value-of-unsigned-typed-array.js.map +1 -0
- package/lib/utils/skip-list.js +11 -9
- package/lib/utils/skip-list.js.map +1 -1
- package/lib/utils/trailing-zeros.js +1 -1
- package/lib/utils/trailing-zeros.js.map +1 -1
- package/package.json +28 -31
- package/src/{bit-set.ts → bit-set/bit-set.ts} +47 -31
- package/src/bit-set/dynamic-typed-bit-set.ts +131 -0
- package/src/bit-set/index.ts +4 -0
- package/src/{typed-bit-set.ts → bit-set/resizable-typed-bit-set.ts} +38 -36
- package/src/bit-set/typed-bit-set.ts +134 -0
- package/src/dynamic-typed-array.ts +67 -82
- package/src/index.ts +5 -7
- package/src/resizable-typed-array.ts +214 -0
- package/src/sparse-map/clean-sparse-map.ts +84 -0
- package/src/sparse-map/dynamic-typed-clean-sparse-map-lite.ts +109 -0
- package/src/sparse-map/dynamic-typed-sparse-map-lite.ts +124 -0
- package/src/sparse-map/index.ts +11 -0
- package/src/sparse-map/resizable-typed-clean-sparse-map-lite.ts +107 -0
- package/src/sparse-map/resizable-typed-sparse-map-lite.ts +122 -0
- package/src/sparse-map/sparse-map.ts +104 -0
- package/src/sparse-map/typed-clean-sparse-map-lite.ts +116 -0
- package/src/sparse-map/typed-clean-sparse-map.ts +149 -0
- package/src/sparse-map/typed-sparse-map-lite.ts +141 -0
- package/src/sparse-map/typed-sparse-map.ts +169 -0
- package/src/sparse-set/clean-sparse-set.ts +76 -0
- package/src/sparse-set/dynamic-typed-clean-sparse-set-lite.ts +64 -0
- package/src/sparse-set/dynamic-typed-clean-sparse-set.ts +101 -0
- package/src/sparse-set/dynamic-typed-sparse-set-lite.ts +67 -0
- package/src/sparse-set/dynamic-typed-sparse-set.ts +93 -0
- package/src/sparse-set/index.ts +15 -0
- package/src/sparse-set/resizable-typed-clean-sparse-set-lite.ts +64 -0
- package/src/sparse-set/resizable-typed-clean-sparse-set.ts +108 -0
- package/src/sparse-set/resizable-typed-sparse-set-lite.ts +67 -0
- package/src/sparse-set/resizable-typed-sparse-set.ts +97 -0
- package/src/sparse-set/sparse-set.ts +79 -0
- package/src/sparse-set/typed-clean-sparse-set-lite.ts +67 -0
- package/src/sparse-set/typed-clean-sparse-set.ts +100 -0
- package/src/sparse-set/typed-sparse-set-lite.ts +74 -0
- package/src/sparse-set/typed-sparse-set.ts +102 -0
- package/src/utils/compute-new-capacity.ts +39 -0
- package/src/utils/get-max-value-of-unsigned-typed-array.ts +19 -0
- package/src/utils/skip-list.ts +1 -1
- package/src/utils/trailing-zeros.ts +2 -3
- package/lib/bit-set.js.map +0 -1
- package/lib/sparse-map.js +0 -76
- package/lib/sparse-map.js.map +0 -1
- package/lib/sparse-set.js +0 -63
- package/lib/sparse-set.js.map +0 -1
- package/lib/typed-bit-set.js.map +0 -1
- package/lib/typed-sparse-map.d.ts +0 -20
- package/lib/typed-sparse-map.js +0 -83
- package/lib/typed-sparse-map.js.map +0 -1
- package/lib/typed-sparse-set.js +0 -59
- package/lib/typed-sparse-set.js.map +0 -1
- package/src/sparse-map.ts +0 -82
- package/src/sparse-set.ts +0 -74
- package/src/typed-sparse-map.ts +0 -97
- package/src/typed-sparse-set.ts +0 -73
package/lib/typed-sparse-set.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export class TypedSparseSet {
|
|
2
|
-
constructor(array) {
|
|
3
|
-
const valueToIndex = [];
|
|
4
|
-
if (array.length > 0) {
|
|
5
|
-
for (const [index, value] of array.internalTypedArray.entries()) {
|
|
6
|
-
valueToIndex[value] = index;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
this.indexToValue = array;
|
|
10
|
-
this.valueToIndex = valueToIndex;
|
|
11
|
-
}
|
|
12
|
-
get [Symbol.toStringTag]() {
|
|
13
|
-
return this.constructor.name;
|
|
14
|
-
}
|
|
15
|
-
[Symbol.iterator]() {
|
|
16
|
-
return this.values();
|
|
17
|
-
}
|
|
18
|
-
get size() {
|
|
19
|
-
return this.indexToValue.length;
|
|
20
|
-
}
|
|
21
|
-
*values() {
|
|
22
|
-
for (let i = 0; i < this.indexToValue.length; i++) {
|
|
23
|
-
yield this.indexToValue.internalTypedArray[i];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
has(value) {
|
|
27
|
-
return this.valueToIndex[value] !== undefined;
|
|
28
|
-
}
|
|
29
|
-
add(value) {
|
|
30
|
-
if (!this.has(value)) {
|
|
31
|
-
const index = this.indexToValue.length;
|
|
32
|
-
this.indexToValue.push(value);
|
|
33
|
-
this.valueToIndex[value] = index;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
delete(value) {
|
|
37
|
-
if (this.has(value)) {
|
|
38
|
-
const lastValue = this.indexToValue.pop();
|
|
39
|
-
if (value === lastValue) {
|
|
40
|
-
this.valueToIndex[value] = undefined;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const index = this.valueToIndex[value];
|
|
44
|
-
this.indexToValue.internalTypedArray[index] = lastValue;
|
|
45
|
-
this.valueToIndex[lastValue] = index;
|
|
46
|
-
this.valueToIndex[value] = undefined;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
clear() {
|
|
55
|
-
this.valueToIndex.length = 0;
|
|
56
|
-
this.indexToValue.clear();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=typed-sparse-set.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typed-sparse-set.js","sourceRoot":"","sources":["../src/typed-sparse-set.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,cAAc;IAMzB,YAAY,KAA2B;QACrC,MAAM,YAAY,GAA8B,EAAE,CAAA;QAClD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,kBAAkB,CAAC,OAAO,EAAE,EAAE,CAAC;gBAChE,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA;YAC7B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC;QACf,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IACtB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAA;IACjC,CAAC;IAED,CAAE,MAAM;QACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClD,MAAM,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;IAED,GAAG,CAAC,KAAa;QACf,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,SAAS,CAAA;IAC/C,CAAC;IAED,GAAG,CAAC,KAAa;QACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAA;YACtC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC7B,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA;QAClC,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACpB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAG,CAAA;YAC1C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;YACtC,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAE,CAAA;gBACvC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;gBACvD,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAA;gBACpC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;YACtC,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAA;QAC5B,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;CACF"}
|
package/src/sparse-map.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export class SparseMap<T> {
|
|
2
|
-
private keyToIndex: Array<number | undefined> = []
|
|
3
|
-
private indexToKey: number[] = []
|
|
4
|
-
private indexToValue: T[] = []
|
|
5
|
-
|
|
6
|
-
get [Symbol.toStringTag](): string {
|
|
7
|
-
return this.constructor.name
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get size(): number {
|
|
11
|
-
return this.indexToKey.length
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get internalArray(): T[] {
|
|
15
|
-
return this.indexToValue
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
* entries(): IterableIterator<[key: number, value: T]> {
|
|
19
|
-
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
20
|
-
yield [this.indexToKey[i], this.indexToValue[i]]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
keys(): IterableIterator<number> {
|
|
25
|
-
return this.indexToKey.values()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
values(): IterableIterator<T> {
|
|
29
|
-
return this.indexToValue.values()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getInternalIndexOfKey(key: number): number | undefined {
|
|
33
|
-
return this.keyToIndex[key]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
has(key: number): boolean {
|
|
37
|
-
return this.keyToIndex[key] !== undefined
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get(key: number): T | undefined {
|
|
41
|
-
if (this.has(key)) {
|
|
42
|
-
const index = this.keyToIndex[key]!
|
|
43
|
-
return this.indexToValue[index]
|
|
44
|
-
} else {
|
|
45
|
-
return undefined
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
set(key: number, value: T): void {
|
|
50
|
-
if (this.has(key)) {
|
|
51
|
-
const index = this.keyToIndex[key]!
|
|
52
|
-
this.indexToValue[index] = value
|
|
53
|
-
} else {
|
|
54
|
-
const index = this.indexToKey.length
|
|
55
|
-
this.indexToKey.push(key)
|
|
56
|
-
this.indexToValue.push(value)
|
|
57
|
-
this.keyToIndex[key] = index
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
delete(key: number): void {
|
|
62
|
-
if (this.has(key)) {
|
|
63
|
-
const lastKey = this.indexToKey.pop()!
|
|
64
|
-
const lastValue = this.indexToValue.pop()!
|
|
65
|
-
if (key === lastKey) {
|
|
66
|
-
this.keyToIndex[key] = undefined
|
|
67
|
-
} else {
|
|
68
|
-
const index = this.keyToIndex[key]!
|
|
69
|
-
this.indexToKey[index] = lastKey
|
|
70
|
-
this.indexToValue[index] = lastValue
|
|
71
|
-
this.keyToIndex[lastKey] = index
|
|
72
|
-
this.keyToIndex[key] = undefined
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
clear(): void {
|
|
78
|
-
this.keyToIndex.length = 0
|
|
79
|
-
this.indexToKey.length = 0
|
|
80
|
-
this.indexToValue.length = 0
|
|
81
|
-
}
|
|
82
|
-
}
|
package/src/sparse-set.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
export class SparseSet implements Iterable<number> {
|
|
2
|
-
private indexToValue: number[] = []
|
|
3
|
-
private valueToIndex: Array<number | undefined>
|
|
4
|
-
|
|
5
|
-
get [Symbol.toStringTag](): string {
|
|
6
|
-
return this.constructor.name
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
[Symbol.iterator](): IterableIterator<number> {
|
|
10
|
-
return this.indexToValue[Symbol.iterator]()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get size(): number {
|
|
14
|
-
return this.indexToValue.length
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
constructor(array: number[] = []) {
|
|
18
|
-
const valueToIndex: Array<number | undefined> = []
|
|
19
|
-
if (array.length > 0) {
|
|
20
|
-
for (const [index, value] of array.entries()) {
|
|
21
|
-
valueToIndex[value] = index
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.valueToIndex = valueToIndex
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
values(): IterableIterator<number> {
|
|
29
|
-
return this.indexToValue[Symbol.iterator]()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
has(value: number): boolean {
|
|
33
|
-
return this.valueToIndex[value] !== undefined
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
add(value: number): void {
|
|
37
|
-
if (!this.has(value)) {
|
|
38
|
-
const index = this.indexToValue.length
|
|
39
|
-
this.indexToValue.push(value)
|
|
40
|
-
this.valueToIndex[value] = index
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
delete(value: number): boolean {
|
|
45
|
-
if (this.has(value)) {
|
|
46
|
-
const lastValue = this.indexToValue.pop()!
|
|
47
|
-
if (value === lastValue) {
|
|
48
|
-
this.valueToIndex[value] = undefined
|
|
49
|
-
} else {
|
|
50
|
-
const index = this.valueToIndex[value]!
|
|
51
|
-
this.indexToValue[index] = lastValue
|
|
52
|
-
this.valueToIndex[lastValue] = index
|
|
53
|
-
this.valueToIndex[value] = undefined
|
|
54
|
-
}
|
|
55
|
-
return true
|
|
56
|
-
} else {
|
|
57
|
-
return false
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
clear(): void {
|
|
62
|
-
this.indexToValue.length = 0
|
|
63
|
-
this.valueToIndex.length = 0
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
clone(): SparseSet {
|
|
67
|
-
const clone = new SparseSet()
|
|
68
|
-
|
|
69
|
-
clone.indexToValue = [...this.indexToValue]
|
|
70
|
-
clone.valueToIndex = [...this.valueToIndex]
|
|
71
|
-
|
|
72
|
-
return clone
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/typed-sparse-map.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { assert } from '@blackglory/errors'
|
|
2
|
-
import { TypedArrayConstructor, TypedArrayOfConstructor } from 'justypes'
|
|
3
|
-
import { DynamicTypedArray } from './dynamic-typed-array.js'
|
|
4
|
-
|
|
5
|
-
export class TypedSparseMap<T extends TypedArrayConstructor> {
|
|
6
|
-
private keyToIndex: Array<number | undefined> = []
|
|
7
|
-
private indexToKey: number[] = []
|
|
8
|
-
private indexToValue: DynamicTypedArray<T>
|
|
9
|
-
|
|
10
|
-
get [Symbol.toStringTag](): string {
|
|
11
|
-
return this.constructor.name
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get size(): number {
|
|
15
|
-
return this.indexToKey.length
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get internalTypedArray(): TypedArrayOfConstructor<T> {
|
|
19
|
-
return this.indexToValue.internalTypedArray
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
constructor(array: DynamicTypedArray<T>) {
|
|
23
|
-
assert(array.length === 0, 'array should be empty')
|
|
24
|
-
|
|
25
|
-
this.indexToValue = array
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
* entries(): IterableIterator<[key: number, value: number]> {
|
|
29
|
-
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
30
|
-
yield [
|
|
31
|
-
this.indexToKey[i]
|
|
32
|
-
, this.indexToValue.internalTypedArray[i]
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
keys(): IterableIterator<number> {
|
|
38
|
-
return this.indexToKey.values()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
* values(): IterableIterator<number> {
|
|
42
|
-
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
43
|
-
yield this.indexToValue.internalTypedArray[i]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getInternalIndexOfKey(key: number): number | undefined {
|
|
48
|
-
return this.keyToIndex[key]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
has(key: number): boolean {
|
|
52
|
-
return this.keyToIndex[key] !== undefined
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get(key: number): number | undefined {
|
|
56
|
-
if (this.has(key)) {
|
|
57
|
-
const index = this.keyToIndex[key]!
|
|
58
|
-
return this.indexToValue.internalTypedArray[index]
|
|
59
|
-
} else {
|
|
60
|
-
return undefined
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
set(key: number, value: number): void {
|
|
65
|
-
if (this.has(key)) {
|
|
66
|
-
const index = this.keyToIndex[key]!
|
|
67
|
-
this.indexToValue.internalTypedArray[index] = value
|
|
68
|
-
} else {
|
|
69
|
-
const index = this.indexToKey.length
|
|
70
|
-
this.indexToKey.push(key)
|
|
71
|
-
this.indexToValue.push(value)
|
|
72
|
-
this.keyToIndex[key] = index
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
delete(key: number): void {
|
|
77
|
-
if (this.has(key)) {
|
|
78
|
-
const lastKey = this.indexToKey.pop()!
|
|
79
|
-
const lastValue = this.indexToValue.pop()!
|
|
80
|
-
if (key === lastKey) {
|
|
81
|
-
this.keyToIndex[key] = undefined
|
|
82
|
-
} else {
|
|
83
|
-
const index = this.keyToIndex[key]!
|
|
84
|
-
this.indexToKey[index] = lastKey
|
|
85
|
-
this.indexToValue.internalTypedArray[index] = lastValue
|
|
86
|
-
this.keyToIndex[lastKey] = index
|
|
87
|
-
this.keyToIndex[key] = undefined
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
clear(): void {
|
|
93
|
-
this.keyToIndex.length = 0
|
|
94
|
-
this.indexToKey.length = 0
|
|
95
|
-
this.indexToValue.clear()
|
|
96
|
-
}
|
|
97
|
-
}
|
package/src/typed-sparse-set.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { UnsignedTypedArrayConstructor } from 'justypes'
|
|
2
|
-
import { DynamicTypedArray } from './dynamic-typed-array.js'
|
|
3
|
-
|
|
4
|
-
export class TypedSparseSet<
|
|
5
|
-
T extends UnsignedTypedArrayConstructor
|
|
6
|
-
> implements Iterable<number> {
|
|
7
|
-
private valueToIndex: Array<number | undefined>
|
|
8
|
-
private indexToValue: DynamicTypedArray<T>
|
|
9
|
-
|
|
10
|
-
constructor(array: DynamicTypedArray<T>) {
|
|
11
|
-
const valueToIndex: Array<number | undefined> = []
|
|
12
|
-
if (array.length > 0) {
|
|
13
|
-
for (const [index, value] of array.internalTypedArray.entries()) {
|
|
14
|
-
valueToIndex[value] = index
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
this.indexToValue = array
|
|
19
|
-
this.valueToIndex = valueToIndex
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get [Symbol.toStringTag](): string {
|
|
23
|
-
return this.constructor.name
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
[Symbol.iterator](): IterableIterator<number> {
|
|
27
|
-
return this.values()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get size(): number {
|
|
31
|
-
return this.indexToValue.length
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
* values(): IterableIterator<number> {
|
|
35
|
-
for (let i = 0; i < this.indexToValue.length; i++) {
|
|
36
|
-
yield this.indexToValue.internalTypedArray[i]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
has(value: number): boolean {
|
|
41
|
-
return this.valueToIndex[value] !== undefined
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
add(value: number): void {
|
|
45
|
-
if (!this.has(value)) {
|
|
46
|
-
const index = this.indexToValue.length
|
|
47
|
-
this.indexToValue.push(value)
|
|
48
|
-
this.valueToIndex[value] = index
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
delete(value: number): boolean {
|
|
53
|
-
if (this.has(value)) {
|
|
54
|
-
const lastValue = this.indexToValue.pop()!
|
|
55
|
-
if (value === lastValue) {
|
|
56
|
-
this.valueToIndex[value] = undefined
|
|
57
|
-
} else {
|
|
58
|
-
const index = this.valueToIndex[value]!
|
|
59
|
-
this.indexToValue.internalTypedArray[index] = lastValue
|
|
60
|
-
this.valueToIndex[lastValue] = index
|
|
61
|
-
this.valueToIndex[value] = undefined
|
|
62
|
-
}
|
|
63
|
-
return true
|
|
64
|
-
} else {
|
|
65
|
-
return false
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
clear(): void {
|
|
70
|
-
this.valueToIndex.length = 0
|
|
71
|
-
this.indexToValue.clear()
|
|
72
|
-
}
|
|
73
|
-
}
|