@blackglory/structures 0.9.0 → 0.10.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 +34 -41
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +139 -117
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +139 -117
- package/dist/es2015/index.umd.js.map +1 -1
- package/dist/es2015/index.umd.min.js +2 -2
- package/dist/es2015/index.umd.min.js.map +1 -1
- package/dist/es2018/index.min.mjs +2 -2
- package/dist/es2018/index.min.mjs.map +1 -1
- package/dist/es2018/index.mjs +139 -117
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +139 -117
- package/dist/es2018/index.umd.js.map +1 -1
- package/dist/es2018/index.umd.min.js +2 -2
- package/dist/es2018/index.umd.min.js.map +1 -1
- package/lib/es2015/dynamic-typed-array.d.ts +1 -1
- package/lib/es2015/dynamic-typed-array.js +25 -20
- package/lib/es2015/dynamic-typed-array.js.map +1 -1
- package/lib/es2015/sparse-set.d.ts +1 -0
- package/lib/es2015/sparse-set.js +3 -0
- package/lib/es2015/sparse-set.js.map +1 -1
- package/lib/es2015/typed-sparse-map.d.ts +5 -9
- package/lib/es2015/typed-sparse-map.js +23 -20
- package/lib/es2015/typed-sparse-map.js.map +1 -1
- package/lib/es2015/typed-sparse-set.d.ts +3 -5
- package/lib/es2015/typed-sparse-set.js +19 -9
- package/lib/es2015/typed-sparse-set.js.map +1 -1
- package/lib/es2018/dynamic-typed-array.d.ts +1 -1
- package/lib/es2018/dynamic-typed-array.js +25 -20
- package/lib/es2018/dynamic-typed-array.js.map +1 -1
- package/lib/es2018/sparse-set.d.ts +1 -0
- package/lib/es2018/sparse-set.js +3 -0
- package/lib/es2018/sparse-set.js.map +1 -1
- package/lib/es2018/typed-sparse-map.d.ts +5 -9
- package/lib/es2018/typed-sparse-map.js +23 -20
- package/lib/es2018/typed-sparse-map.js.map +1 -1
- package/lib/es2018/typed-sparse-set.d.ts +3 -5
- package/lib/es2018/typed-sparse-set.js +19 -9
- package/lib/es2018/typed-sparse-set.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ export declare class DynamicTypedArray<T extends TypedArrayConstructor> {
|
|
|
7
7
|
private typedArrayConstructor;
|
|
8
8
|
private array;
|
|
9
9
|
private _length;
|
|
10
|
-
|
|
10
|
+
readonly growthFactor: number;
|
|
11
11
|
get internalTypedArray(): TypedArrayOfConstructor<T>;
|
|
12
12
|
get [Symbol.toStringTag](): string;
|
|
13
13
|
get capacity(): number;
|
|
@@ -8,7 +8,7 @@ class DynamicTypedArray {
|
|
|
8
8
|
this._length = 0;
|
|
9
9
|
(0, errors_1.assert)(Number.isInteger(capacity), 'capacity must be an integer');
|
|
10
10
|
(0, errors_1.assert)(capacity >= 0, 'capacity must be greater than or equal to 0');
|
|
11
|
-
(0, errors_1.assert)(growthFactor
|
|
11
|
+
(0, errors_1.assert)(growthFactor >= 1, 'growthFactory must be greater than or equal to 1');
|
|
12
12
|
this.array = new typedArrayConstructor(capacity);
|
|
13
13
|
this.growthFactor = growthFactor;
|
|
14
14
|
}
|
|
@@ -81,32 +81,37 @@ class DynamicTypedArray {
|
|
|
81
81
|
}
|
|
82
82
|
exports.DynamicTypedArray = DynamicTypedArray;
|
|
83
83
|
function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
|
|
84
|
-
if (
|
|
84
|
+
if (growthFactor === 1) {
|
|
85
85
|
return targetLength;
|
|
86
86
|
}
|
|
87
|
-
else if (oldCapacity < targetLength) {
|
|
88
|
-
let newCapacity = Math.max(oldCapacity, 1);
|
|
89
|
-
while (newCapacity < targetLength) {
|
|
90
|
-
newCapacity *= growthFactor;
|
|
91
|
-
}
|
|
92
|
-
return Math.floor(newCapacity);
|
|
93
|
-
}
|
|
94
87
|
else {
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
88
|
+
if (oldCapacity === targetLength) {
|
|
89
|
+
return targetLength;
|
|
90
|
+
}
|
|
91
|
+
else if (oldCapacity < targetLength) {
|
|
92
|
+
let newCapacity = Math.max(oldCapacity, 1);
|
|
93
|
+
while (newCapacity < targetLength) {
|
|
94
|
+
newCapacity *= growthFactor;
|
|
95
|
+
}
|
|
96
|
+
return Math.floor(newCapacity);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
if (targetLength === 0) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
let newCapacity = oldCapacity;
|
|
104
|
+
while (true) {
|
|
105
|
+
const temp = newCapacity / growthFactor;
|
|
106
|
+
if (temp < targetLength) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
newCapacity = temp;
|
|
111
|
+
}
|
|
107
112
|
}
|
|
113
|
+
return Math.floor(newCapacity);
|
|
108
114
|
}
|
|
109
|
-
return Math.floor(newCapacity);
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-typed-array.js","sourceRoot":"","sources":["../../src/dynamic-typed-array.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAQ3C,MAAa,iBAAiB;IA2B5B,YACU,qBAAwB,EAChC,EACE,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,GAAG,KACW,EAAE;QAJzB,0BAAqB,GAArB,qBAAqB,CAAG;QA1B1B,YAAO,GAAW,CAAC,CAAA;QAgCzB,IAAA,eAAM,EAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,6BAA6B,CAAC,CAAA;QACjE,IAAA,eAAM,EAAC,QAAQ,IAAI,CAAC,EAAE,6CAA6C,CAAC,CAAA;QACpE,IAAA,eAAM,EAA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GAAG,WAAW,CAAA;gBAC7B,OAAO,IAAI,EAAE;oBACX,MAAM,IAAI,GAAG,WAAW,GAAG,YAAY,CAAA;oBACvC,IAAI,IAAI,GAAG,YAAY,EAAE;wBACvB,MAAK;qBACN;yBAAM;wBACL,WAAW,GAAG,IAAI,CAAA;qBACnB;iBACF;gBACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;aAC/B;SACF;KACF;AACH,CAAC;AAtCD,gDAsCC"}
|
|
@@ -3,6 +3,7 @@ export declare class SparseSet implements Iterable<number> {
|
|
|
3
3
|
private valueToIndex;
|
|
4
4
|
get [Symbol.toStringTag](): string;
|
|
5
5
|
[Symbol.iterator](): IterableIterator<number>;
|
|
6
|
+
values(): Iterable<number>;
|
|
6
7
|
has(value: number): boolean;
|
|
7
8
|
add(value: number): void;
|
|
8
9
|
delete(value: number): void;
|
package/lib/es2015/sparse-set.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAAtB;QACU,iBAAY,GAAa,EAAE,CAAA;QAC3B,iBAAY,GAA8B,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAAtB;QACU,iBAAY,GAAa,EAAE,CAAA;QAC3B,iBAAY,GAA8B,EAAE,CAAA;IAyCtD,CAAC;IAvCC,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,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;IAC7C,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;IAC7C,CAAC;IAED,GAAG,CAAC,KAAa;QAEf,OAAO,KAAK,IAAI,IAAI,CAAC,YAAY,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,KAAa;QACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACpB,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;SACjC;IACH,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAG,CAAA;YAC1C,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;aAChC;iBAAM;gBACL,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAE,CAAA;gBACvC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;gBACpC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAA;gBAEpC,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;aAChC;SACF;IACH,CAAC;CACF;AA3CD,8BA2CC"}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { TypedArrayConstructor } from 'justypes';
|
|
2
|
-
|
|
3
|
-
capacity?: number;
|
|
4
|
-
growthFactor?: number;
|
|
5
|
-
}
|
|
2
|
+
import { DynamicTypedArray } from './dynamic-typed-array';
|
|
6
3
|
export declare class TypedSparseMap<T extends TypedArrayConstructor> {
|
|
7
4
|
private keyToIndex;
|
|
8
5
|
private indexToKey;
|
|
9
6
|
private indexToValue;
|
|
10
7
|
get [Symbol.toStringTag](): string;
|
|
11
|
-
constructor(
|
|
12
|
-
entries():
|
|
13
|
-
keys():
|
|
14
|
-
values():
|
|
8
|
+
constructor(array: DynamicTypedArray<T>);
|
|
9
|
+
entries(): IterableIterator<[key: number, value: number]>;
|
|
10
|
+
keys(): IterableIterator<number>;
|
|
11
|
+
values(): IterableIterator<number>;
|
|
15
12
|
has(key: number): boolean;
|
|
16
13
|
get(key: number): number | undefined;
|
|
17
14
|
set(key: number, value: number): void;
|
|
18
15
|
delete(key: number): void;
|
|
19
16
|
}
|
|
20
|
-
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypedSparseMap = void 0;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("@blackglory/errors");
|
|
5
5
|
class TypedSparseMap {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
|
|
6
|
+
constructor(array) {
|
|
7
|
+
this.keyToIndex = [];
|
|
8
|
+
this.indexToKey = [];
|
|
9
|
+
(0, errors_1.assert)(array.length === 0, 'array should be empty');
|
|
10
|
+
this.indexToValue = array;
|
|
10
11
|
}
|
|
11
12
|
get [Symbol.toStringTag]() {
|
|
12
13
|
return this.constructor.name;
|
|
@@ -14,24 +15,26 @@ class TypedSparseMap {
|
|
|
14
15
|
*entries() {
|
|
15
16
|
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
16
17
|
yield [
|
|
17
|
-
this.indexToKey
|
|
18
|
+
this.indexToKey[i],
|
|
18
19
|
this.indexToValue.internalTypedArray[i]
|
|
19
20
|
];
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
keys() {
|
|
23
|
-
return this.indexToKey.
|
|
24
|
+
return this.indexToKey.values();
|
|
24
25
|
}
|
|
25
|
-
values() {
|
|
26
|
-
|
|
26
|
+
*values() {
|
|
27
|
+
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
28
|
+
yield this.indexToValue.internalTypedArray[i];
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
31
|
has(key) {
|
|
29
|
-
const index = this.keyToIndex
|
|
30
|
-
return this.indexToKey
|
|
32
|
+
const index = this.keyToIndex[key];
|
|
33
|
+
return this.indexToKey[index] === key;
|
|
31
34
|
}
|
|
32
35
|
get(key) {
|
|
33
|
-
const index = this.keyToIndex
|
|
34
|
-
if (this.indexToKey
|
|
36
|
+
const index = this.keyToIndex[key];
|
|
37
|
+
if (this.indexToKey[index] === key) {
|
|
35
38
|
return this.indexToValue.internalTypedArray[index];
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
@@ -39,26 +42,26 @@ class TypedSparseMap {
|
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
set(key, value) {
|
|
42
|
-
const index = this.keyToIndex
|
|
43
|
-
if (this.indexToKey
|
|
45
|
+
const index = this.keyToIndex[key];
|
|
46
|
+
if (this.indexToKey[index] === key) {
|
|
44
47
|
this.indexToValue.internalTypedArray[index] = value;
|
|
45
48
|
}
|
|
46
49
|
else {
|
|
47
50
|
const index = this.indexToKey.length;
|
|
48
51
|
this.indexToKey.push(key);
|
|
49
52
|
this.indexToValue.push(value);
|
|
50
|
-
this.keyToIndex
|
|
53
|
+
this.keyToIndex[key] = index;
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
delete(key) {
|
|
54
|
-
const index = this.keyToIndex
|
|
55
|
-
if (this.indexToKey
|
|
57
|
+
const index = this.keyToIndex[key];
|
|
58
|
+
if (this.indexToKey[index] === key) {
|
|
56
59
|
const lastKey = this.indexToKey.pop();
|
|
57
60
|
const lastValue = this.indexToValue.pop();
|
|
58
61
|
if (key !== lastKey) {
|
|
59
|
-
this.indexToKey
|
|
62
|
+
this.indexToKey[index] = lastKey;
|
|
60
63
|
this.indexToValue.internalTypedArray[index] = lastValue;
|
|
61
|
-
this.keyToIndex
|
|
64
|
+
this.keyToIndex[lastKey] = index;
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-sparse-map.js","sourceRoot":"","sources":["../../src/typed-sparse-map.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"typed-sparse-map.js","sourceRoot":"","sources":["../../src/typed-sparse-map.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAI3C,MAAa,cAAc;IASzB,YAAY,KAA2B;QAR/B,eAAU,GAA8B,EAAE,CAAA;QAC1C,eAAU,GAAa,EAAE,CAAA;QAQ/B,IAAA,eAAM,EAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,uBAAuB,CAAC,CAAA;QAEnD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;IAC3B,CAAC;IARD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAQD,CAAE,OAAO;QACP,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,MAAM;gBACJ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBAClB,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC;aACxC,CAAA;SACF;IACH,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAA;IACjC,CAAC;IAED,CAAE,MAAM;QACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,MAAM,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAA;SAC9C;IACH,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,KAAK,GAAG,IAAI,CAA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AAI,CAAC,UAAU,CAAC,KAAM,CAAC,GAAG,OAAO,CAAA;gBACjC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,KAAM,CAAC,GAAG,SAAS,CAAA;gBACxD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,KAAK,CAAA;aACjC;SACF;IACH,CAAC;CACF;AAxED,wCAwEC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { UnsignedTypedArrayConstructor } from 'justypes';
|
|
2
|
-
|
|
3
|
-
capacity?: number;
|
|
4
|
-
growthFactor?: number;
|
|
5
|
-
}
|
|
2
|
+
import { DynamicTypedArray } from './dynamic-typed-array';
|
|
6
3
|
export declare class TypedSparseSet<T extends UnsignedTypedArrayConstructor> implements Iterable<number> {
|
|
7
4
|
private valueToIndex;
|
|
8
5
|
private indexToValue;
|
|
9
|
-
constructor(
|
|
6
|
+
constructor(array: DynamicTypedArray<T>);
|
|
10
7
|
get [Symbol.toStringTag](): string;
|
|
11
8
|
[Symbol.iterator](): IterableIterator<number>;
|
|
9
|
+
values(): IterableIterator<number>;
|
|
12
10
|
has(value: number): boolean;
|
|
13
11
|
add(value: number): void;
|
|
14
12
|
delete(value: number): void;
|
|
@@ -1,36 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypedSparseSet = void 0;
|
|
4
|
-
const dynamic_typed_array_1 = require("./dynamic-typed-array");
|
|
5
4
|
class TypedSparseSet {
|
|
6
|
-
constructor(
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
constructor(array) {
|
|
6
|
+
const valueToIndex = [];
|
|
7
|
+
if (array.length > 0) {
|
|
8
|
+
for (const [index, value] of array.internalTypedArray.entries()) {
|
|
9
|
+
valueToIndex[value] = index;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
this.indexToValue = array;
|
|
13
|
+
this.valueToIndex = valueToIndex;
|
|
9
14
|
}
|
|
10
15
|
get [Symbol.toStringTag]() {
|
|
11
16
|
return this.constructor.name;
|
|
12
17
|
}
|
|
13
18
|
[Symbol.iterator]() {
|
|
14
|
-
return this.
|
|
19
|
+
return this.values();
|
|
20
|
+
}
|
|
21
|
+
*values() {
|
|
22
|
+
for (let i = 0; i < this.indexToValue.length; i++) {
|
|
23
|
+
yield this.indexToValue.internalTypedArray[i];
|
|
24
|
+
}
|
|
15
25
|
}
|
|
16
26
|
has(value) {
|
|
17
|
-
const index = this.valueToIndex
|
|
27
|
+
const index = this.valueToIndex[value];
|
|
18
28
|
return this.indexToValue.internalTypedArray[index] === value;
|
|
19
29
|
}
|
|
20
30
|
add(value) {
|
|
21
31
|
if (!this.has(value)) {
|
|
22
32
|
const index = this.indexToValue.length;
|
|
23
33
|
this.indexToValue.push(value);
|
|
24
|
-
this.valueToIndex
|
|
34
|
+
this.valueToIndex[value] = index;
|
|
25
35
|
}
|
|
26
36
|
}
|
|
27
37
|
delete(value) {
|
|
28
|
-
const index = this.valueToIndex
|
|
38
|
+
const index = this.valueToIndex[value];
|
|
29
39
|
if (this.indexToValue.internalTypedArray[index] === value) {
|
|
30
40
|
const lastValue = this.indexToValue.pop();
|
|
31
41
|
if (value !== lastValue) {
|
|
32
42
|
this.indexToValue.internalTypedArray[index] = lastValue;
|
|
33
|
-
this.valueToIndex
|
|
43
|
+
this.valueToIndex[lastValue] = index;
|
|
34
44
|
}
|
|
35
45
|
}
|
|
36
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-sparse-set.js","sourceRoot":"","sources":["../../src/typed-sparse-set.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"typed-sparse-set.js","sourceRoot":"","sources":["../../src/typed-sparse-set.ts"],"names":[],"mappings":";;;AAGA,MAAa,cAAc;IAMzB,YAAY,KAA2B;QACrC,MAAM,YAAY,GAA8B,EAAE,CAAA;QAClD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAC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AAY,CAAC,kBAAkB,CAAC,KAAM,CAAC,KAAK,KAAK,EAAE;YAC1D,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAG,CAAA;YAC1C,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,KAAM,CAAC,GAAG,SAAS,CAAA;gBACxD,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAA;aACrC;SACF;IACH,CAAC;CACF;AAvDD,wCAuDC"}
|
|
@@ -7,7 +7,7 @@ export declare class DynamicTypedArray<T extends TypedArrayConstructor> {
|
|
|
7
7
|
private typedArrayConstructor;
|
|
8
8
|
private array;
|
|
9
9
|
private _length;
|
|
10
|
-
|
|
10
|
+
readonly growthFactor: number;
|
|
11
11
|
get internalTypedArray(): TypedArrayOfConstructor<T>;
|
|
12
12
|
get [Symbol.toStringTag](): string;
|
|
13
13
|
get capacity(): number;
|
|
@@ -8,7 +8,7 @@ class DynamicTypedArray {
|
|
|
8
8
|
this._length = 0;
|
|
9
9
|
(0, errors_1.assert)(Number.isInteger(capacity), 'capacity must be an integer');
|
|
10
10
|
(0, errors_1.assert)(capacity >= 0, 'capacity must be greater than or equal to 0');
|
|
11
|
-
(0, errors_1.assert)(growthFactor
|
|
11
|
+
(0, errors_1.assert)(growthFactor >= 1, 'growthFactory must be greater than or equal to 1');
|
|
12
12
|
this.array = new typedArrayConstructor(capacity);
|
|
13
13
|
this.growthFactor = growthFactor;
|
|
14
14
|
}
|
|
@@ -81,32 +81,37 @@ class DynamicTypedArray {
|
|
|
81
81
|
}
|
|
82
82
|
exports.DynamicTypedArray = DynamicTypedArray;
|
|
83
83
|
function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
|
|
84
|
-
if (
|
|
84
|
+
if (growthFactor === 1) {
|
|
85
85
|
return targetLength;
|
|
86
86
|
}
|
|
87
|
-
else if (oldCapacity < targetLength) {
|
|
88
|
-
let newCapacity = Math.max(oldCapacity, 1);
|
|
89
|
-
while (newCapacity < targetLength) {
|
|
90
|
-
newCapacity *= growthFactor;
|
|
91
|
-
}
|
|
92
|
-
return Math.floor(newCapacity);
|
|
93
|
-
}
|
|
94
87
|
else {
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
88
|
+
if (oldCapacity === targetLength) {
|
|
89
|
+
return targetLength;
|
|
90
|
+
}
|
|
91
|
+
else if (oldCapacity < targetLength) {
|
|
92
|
+
let newCapacity = Math.max(oldCapacity, 1);
|
|
93
|
+
while (newCapacity < targetLength) {
|
|
94
|
+
newCapacity *= growthFactor;
|
|
95
|
+
}
|
|
96
|
+
return Math.floor(newCapacity);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
if (targetLength === 0) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
let newCapacity = oldCapacity;
|
|
104
|
+
while (true) {
|
|
105
|
+
const temp = newCapacity / growthFactor;
|
|
106
|
+
if (temp < targetLength) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
newCapacity = temp;
|
|
111
|
+
}
|
|
107
112
|
}
|
|
113
|
+
return Math.floor(newCapacity);
|
|
108
114
|
}
|
|
109
|
-
return Math.floor(newCapacity);
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-typed-array.js","sourceRoot":"","sources":["../../src/dynamic-typed-array.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAQ3C,MAAa,iBAAiB;IA2B5B,YACU,qBAAwB,EAChC,EACE,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,GAAG,KACW,EAAE;QAJzB,0BAAqB,GAArB,qBAAqB,CAAG;QA1B1B,YAAO,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AE;gBACjC,WAAW,IAAI,YAAY,CAAA;aAC5B;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;SAC/B;aAAM;YAKL,IAAI,YAAY,KAAK,CAAC,EAAE;gBACtB,OAAO,CAAC,CAAA;aACT;iBAAM;gBACL,IAAI,WAAW,GAAG,WAAW,CAAA;gBAC7B,OAAO,IAAI,EAAE;oBACX,MAAM,IAAI,GAAG,WAAW,GAAG,YAAY,CAAA;oBACvC,IAAI,IAAI,GAAG,YAAY,EAAE;wBACvB,MAAK;qBACN;yBAAM;wBACL,WAAW,GAAG,IAAI,CAAA;qBACnB;iBACF;gBACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;aAC/B;SACF;KACF;AACH,CAAC;AAtCD,gDAsCC"}
|
|
@@ -3,6 +3,7 @@ export declare class SparseSet implements Iterable<number> {
|
|
|
3
3
|
private valueToIndex;
|
|
4
4
|
get [Symbol.toStringTag](): string;
|
|
5
5
|
[Symbol.iterator](): IterableIterator<number>;
|
|
6
|
+
values(): Iterable<number>;
|
|
6
7
|
has(value: number): boolean;
|
|
7
8
|
add(value: number): void;
|
|
8
9
|
delete(value: number): void;
|
package/lib/es2018/sparse-set.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAAtB;QACU,iBAAY,GAAa,EAAE,CAAA;QAC3B,iBAAY,GAA8B,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAAtB;QACU,iBAAY,GAAa,EAAE,CAAA;QAC3B,iBAAY,GAA8B,EAAE,CAAA;IAyCtD,CAAC;IAvCC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAA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acity?: number;
|
|
4
|
-
growthFactor?: number;
|
|
5
|
-
}
|
|
2
|
+
import { DynamicTypedArray } from './dynamic-typed-array';
|
|
6
3
|
export declare class TypedSparseMap<T extends TypedArrayConstructor> {
|
|
7
4
|
private keyToIndex;
|
|
8
5
|
private indexToKey;
|
|
9
6
|
private indexToValue;
|
|
10
7
|
get [Symbol.toStringTag](): string;
|
|
11
|
-
constructor(
|
|
12
|
-
entries():
|
|
13
|
-
keys():
|
|
14
|
-
values():
|
|
8
|
+
constructor(array: DynamicTypedArray<T>);
|
|
9
|
+
entries(): IterableIterator<[key: number, value: number]>;
|
|
10
|
+
keys(): IterableIterator<number>;
|
|
11
|
+
values(): IterableIterator<number>;
|
|
15
12
|
has(key: number): boolean;
|
|
16
13
|
get(key: number): number | undefined;
|
|
17
14
|
set(key: number, value: number): void;
|
|
18
15
|
delete(key: number): void;
|
|
19
16
|
}
|
|
20
|
-
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypedSparseMap = void 0;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("@blackglory/errors");
|
|
5
5
|
class TypedSparseMap {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
|
|
6
|
+
constructor(array) {
|
|
7
|
+
this.keyToIndex = [];
|
|
8
|
+
this.indexToKey = [];
|
|
9
|
+
(0, errors_1.assert)(array.length === 0, 'array should be empty');
|
|
10
|
+
this.indexToValue = array;
|
|
10
11
|
}
|
|
11
12
|
get [Symbol.toStringTag]() {
|
|
12
13
|
return this.constructor.name;
|
|
@@ -14,24 +15,26 @@ class TypedSparseMap {
|
|
|
14
15
|
*entries() {
|
|
15
16
|
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
16
17
|
yield [
|
|
17
|
-
this.indexToKey
|
|
18
|
+
this.indexToKey[i],
|
|
18
19
|
this.indexToValue.internalTypedArray[i]
|
|
19
20
|
];
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
keys() {
|
|
23
|
-
return this.indexToKey.
|
|
24
|
+
return this.indexToKey.values();
|
|
24
25
|
}
|
|
25
|
-
values() {
|
|
26
|
-
|
|
26
|
+
*values() {
|
|
27
|
+
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
28
|
+
yield this.indexToValue.internalTypedArray[i];
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
31
|
has(key) {
|
|
29
|
-
const index = this.keyToIndex
|
|
30
|
-
return this.indexToKey
|
|
32
|
+
const index = this.keyToIndex[key];
|
|
33
|
+
return this.indexToKey[index] === key;
|
|
31
34
|
}
|
|
32
35
|
get(key) {
|
|
33
|
-
const index = this.keyToIndex
|
|
34
|
-
if (this.indexToKey
|
|
36
|
+
const index = this.keyToIndex[key];
|
|
37
|
+
if (this.indexToKey[index] === key) {
|
|
35
38
|
return this.indexToValue.internalTypedArray[index];
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
@@ -39,26 +42,26 @@ class TypedSparseMap {
|
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
set(key, value) {
|
|
42
|
-
const index = this.keyToIndex
|
|
43
|
-
if (this.indexToKey
|
|
45
|
+
const index = this.keyToIndex[key];
|
|
46
|
+
if (this.indexToKey[index] === key) {
|
|
44
47
|
this.indexToValue.internalTypedArray[index] = value;
|
|
45
48
|
}
|
|
46
49
|
else {
|
|
47
50
|
const index = this.indexToKey.length;
|
|
48
51
|
this.indexToKey.push(key);
|
|
49
52
|
this.indexToValue.push(value);
|
|
50
|
-
this.keyToIndex
|
|
53
|
+
this.keyToIndex[key] = index;
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
delete(key) {
|
|
54
|
-
const index = this.keyToIndex
|
|
55
|
-
if (this.indexToKey
|
|
57
|
+
const index = this.keyToIndex[key];
|
|
58
|
+
if (this.indexToKey[index] === key) {
|
|
56
59
|
const lastKey = this.indexToKey.pop();
|
|
57
60
|
const lastValue = this.indexToValue.pop();
|
|
58
61
|
if (key !== lastKey) {
|
|
59
|
-
this.indexToKey
|
|
62
|
+
this.indexToKey[index] = lastKey;
|
|
60
63
|
this.indexToValue.internalTypedArray[index] = lastValue;
|
|
61
|
-
this.keyToIndex
|
|
64
|
+
this.keyToIndex[lastKey] = index;
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-sparse-map.js","sourceRoot":"","sources":["../../src/typed-sparse-map.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"typed-sparse-map.js","sourceRoot":"","sources":["../../src/typed-sparse-map.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAI3C,MAAa,cAAc;IASzB,YAAY,KAA2B;QAR/B,eAAU,GAA8B,EAAE,CAAA;QAC1C,eAAU,GAAa,EAAE,CAAA;QAQ/B,IAAA,eAAM,EAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,uBAAuB,CAAC,CAAA;QAEnD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;IAC3B,CAAC;IARD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAQD,CAAE,OAAO;QACP,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,MAAM;gBACJ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBAClB,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC;aACxC,CAAA;SACF;IACH,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAA;IACjC,CAAC;IAED,CAAE,MAAM;QACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAA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AC,KAAK,GAAG,EAAE;YACnC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAG,CAAA;YACtC,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAG,CAAA;YAC1C,IAAI,GAAG,KAAK,OAAO,EAAE;gBACnB,IAAI,CAAC,UAAU,CAAC,KAAM,CAAC,GAAG,OAAO,CAAA;gBACjC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,KAAM,CAAC,GAAG,SAAS,CAAA;gBACxD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,KAAK,CAAA;aACjC;SACF;IACH,CAAC;CACF;AAxED,wCAwEC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { UnsignedTypedArrayConstructor } from 'justypes';
|
|
2
|
-
|
|
3
|
-
capacity?: number;
|
|
4
|
-
growthFactor?: number;
|
|
5
|
-
}
|
|
2
|
+
import { DynamicTypedArray } from './dynamic-typed-array';
|
|
6
3
|
export declare class TypedSparseSet<T extends UnsignedTypedArrayConstructor> implements Iterable<number> {
|
|
7
4
|
private valueToIndex;
|
|
8
5
|
private indexToValue;
|
|
9
|
-
constructor(
|
|
6
|
+
constructor(array: DynamicTypedArray<T>);
|
|
10
7
|
get [Symbol.toStringTag](): string;
|
|
11
8
|
[Symbol.iterator](): IterableIterator<number>;
|
|
9
|
+
values(): IterableIterator<number>;
|
|
12
10
|
has(value: number): boolean;
|
|
13
11
|
add(value: number): void;
|
|
14
12
|
delete(value: number): void;
|