@blackglory/structures 0.6.5 → 0.6.6
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 +22 -0
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +1239 -749
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +1239 -748
- 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 +1239 -749
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +1239 -748
- 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 +22 -0
- package/lib/es2015/dynamic-typed-array.js +111 -0
- package/lib/es2015/dynamic-typed-array.js.map +1 -0
- package/lib/es2015/index.d.ts +1 -0
- package/lib/es2015/index.js +3 -0
- package/lib/es2015/index.js.map +1 -1
- package/lib/es2018/dynamic-typed-array.d.ts +22 -0
- package/lib/es2018/dynamic-typed-array.js +111 -0
- package/lib/es2018/dynamic-typed-array.js.map +1 -0
- package/lib/es2018/index.d.ts +1 -0
- package/lib/es2018/index.js +3 -0
- package/lib/es2018/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TypedArrayConstructor } from 'justypes';
|
|
2
|
+
interface IDynamicTypedArrayOptions {
|
|
3
|
+
capacity?: number;
|
|
4
|
+
growthFactor?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class DynamicTypedArray<T extends TypedArrayConstructor> {
|
|
7
|
+
private typedArrayConstructor;
|
|
8
|
+
private array;
|
|
9
|
+
private _length;
|
|
10
|
+
private growthFactor;
|
|
11
|
+
get [Symbol.toStringTag](): string;
|
|
12
|
+
get capacity(): number;
|
|
13
|
+
get length(): number;
|
|
14
|
+
constructor(typedArrayConstructor: T, { capacity, growthFactor }?: IDynamicTypedArrayOptions);
|
|
15
|
+
set(index: number, value: number): void;
|
|
16
|
+
get(index: number): number | undefined;
|
|
17
|
+
push(...values: number[]): void;
|
|
18
|
+
pop(): number | undefined;
|
|
19
|
+
private resize;
|
|
20
|
+
}
|
|
21
|
+
export declare function computeNewCapacity(oldCapacity: number, targetLength: number, growthFactor: number): number;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeNewCapacity = exports.DynamicTypedArray = void 0;
|
|
4
|
+
const errors_1 = require("@blackglory/errors");
|
|
5
|
+
class DynamicTypedArray {
|
|
6
|
+
constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
|
|
7
|
+
this.typedArrayConstructor = typedArrayConstructor;
|
|
8
|
+
this._length = 0;
|
|
9
|
+
(0, errors_1.assert)(Number.isInteger(capacity), 'capacity must be an integer');
|
|
10
|
+
(0, errors_1.assert)(capacity >= 0, 'capacity must be greater than or equal to 0');
|
|
11
|
+
(0, errors_1.assert)(growthFactor > 1, 'growthFactory must be greater than or equal to 1');
|
|
12
|
+
this.array = new typedArrayConstructor(capacity);
|
|
13
|
+
this.growthFactor = growthFactor;
|
|
14
|
+
}
|
|
15
|
+
get [Symbol.toStringTag]() {
|
|
16
|
+
return this.constructor.name;
|
|
17
|
+
}
|
|
18
|
+
get capacity() {
|
|
19
|
+
return this.array.length;
|
|
20
|
+
}
|
|
21
|
+
get length() {
|
|
22
|
+
return this._length;
|
|
23
|
+
}
|
|
24
|
+
set(index, value) {
|
|
25
|
+
if (index >= this.capacity) {
|
|
26
|
+
const newCapacity = computeNewCapacity(this.capacity, index + 1, this.growthFactor);
|
|
27
|
+
this.resize(newCapacity);
|
|
28
|
+
}
|
|
29
|
+
if (index >= this._length) {
|
|
30
|
+
this._length = index + 1;
|
|
31
|
+
}
|
|
32
|
+
this.array[index] = value;
|
|
33
|
+
}
|
|
34
|
+
get(index) {
|
|
35
|
+
return index < this._length
|
|
36
|
+
? this.array[index]
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
push(...values) {
|
|
40
|
+
const newLength = this._length + values.length;
|
|
41
|
+
if (newLength > this.capacity) {
|
|
42
|
+
const newCapacity = computeNewCapacity(this.capacity, newLength, this.growthFactor);
|
|
43
|
+
this.resize(newCapacity);
|
|
44
|
+
}
|
|
45
|
+
for (const value of values) {
|
|
46
|
+
this.array[this._length++] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
pop() {
|
|
50
|
+
if (this._length > 0) {
|
|
51
|
+
const value = this.array[this._length - 1];
|
|
52
|
+
this._length--;
|
|
53
|
+
const newCapacity = computeNewCapacity(this.capacity, this.length, this.growthFactor);
|
|
54
|
+
this.resize(newCapacity);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
resize(newCapacity) {
|
|
62
|
+
if (this.array.length === newCapacity) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
else if (this.array.length < newCapacity) {
|
|
66
|
+
const newArray = new this.typedArrayConstructor(newCapacity);
|
|
67
|
+
newArray.set(this.array);
|
|
68
|
+
this.array = newArray;
|
|
69
|
+
}
|
|
70
|
+
else if (this.array.length > newCapacity) {
|
|
71
|
+
const newArray = new this.typedArrayConstructor(newCapacity);
|
|
72
|
+
for (let i = newCapacity; i--;) {
|
|
73
|
+
newArray[i] = this.array[i];
|
|
74
|
+
}
|
|
75
|
+
this.array = newArray;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.DynamicTypedArray = DynamicTypedArray;
|
|
80
|
+
function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
|
|
81
|
+
if (oldCapacity === targetLength) {
|
|
82
|
+
return targetLength;
|
|
83
|
+
}
|
|
84
|
+
else if (oldCapacity < targetLength) {
|
|
85
|
+
let newCapacity = Math.max(oldCapacity, 1);
|
|
86
|
+
while (newCapacity < targetLength) {
|
|
87
|
+
newCapacity *= growthFactor;
|
|
88
|
+
}
|
|
89
|
+
return Math.floor(newCapacity);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (targetLength === 0) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
let newCapacity = oldCapacity;
|
|
97
|
+
while (true) {
|
|
98
|
+
const temp = newCapacity / growthFactor;
|
|
99
|
+
if (temp < targetLength) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
newCapacity = temp;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return Math.floor(newCapacity);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.computeNewCapacity = computeNewCapacity;
|
|
111
|
+
//# sourceMappingURL=dynamic-typed-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-typed-array.js","sourceRoot":"","sources":["../../src/dynamic-typed-array.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAQ3C,MAAa,iBAAiB;IAuB5B,YACU,qBAAwB,EAChC,EACE,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,GAAG,KACW,EAAE;QAJzB,0BAAqB,GAArB,qBAAqB,CAAG;QAtB1B,YAAO,GAAW,CAAC,CAAA;QA4BzB,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,eA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C,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;aAC5B;YACD,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAA;SACtB;IACH,CAAC;CACF;AA/GD,8CA+GC;AAED,SAAgB,kBAAkB,CAChC,WAAmB,EACnB,YAAoB,EACpB,YAAoB;IAEpB,IAAI,WAAW,KAAK,YAAY,EAAE;QAChC,OAAO,YAAY,CAAA;KACpB;SAAM,IAAI,WAAW,GAAG,YAAY,EAAE;QAErC,IAAI,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QAC1C,OAAO,WAAW,GAAG,YAAY,EAAE;YACjC,WAAW,IAAI,YAAY,CAAA;SAC5B;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;KAC/B;SAAM;QAKL,IAAI,YAAY,KAAK,CAAC,EAAE;YACtB,OAAO,CAAC,CAAA;SACT;aAAM;YACL,IAAI,WAAW,GAAG,WAAW,CAAA;YAC7B,OAAO,IAAI,EAAE;gBACX,MAAM,IAAI,GAAG,WAAW,GAAG,YAAY,CAAA;gBACvC,IAAI,IAAI,GAAG,YAAY,EAAE;oBACvB,MAAK;iBACN;qBAAM;oBACL,WAAW,GAAG,IAAI,CAAA;iBACnB;aACF;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;SAC/B;KACF;AACH,CAAC;AAlCD,gDAkCC"}
|
package/lib/es2015/index.d.ts
CHANGED
package/lib/es2015/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DynamicTypedArray = void 0;
|
|
17
18
|
__exportStar(require("./box"), exports);
|
|
18
19
|
__exportStar(require("./cons"), exports);
|
|
19
20
|
__exportStar(require("./emitter"), exports);
|
|
@@ -27,4 +28,6 @@ __exportStar(require("./trie-map"), exports);
|
|
|
27
28
|
__exportStar(require("./finite-state-machine"), exports);
|
|
28
29
|
__exportStar(require("./observable-finite-state-machine"), exports);
|
|
29
30
|
__exportStar(require("./sparse-set"), exports);
|
|
31
|
+
var dynamic_typed_array_1 = require("./dynamic-typed-array");
|
|
32
|
+
Object.defineProperty(exports, "DynamicTypedArray", { enumerable: true, get: function () { return dynamic_typed_array_1.DynamicTypedArray; } });
|
|
30
33
|
//# sourceMappingURL=index.js.map
|
package/lib/es2015/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,yCAAsB;AACtB,4CAAyB;AACzB,6CAA0B;AAC1B,6CAA0B;AAC1B,0CAAuB;AACvB,4CAAyB;AACzB,kDAA+B;AAC/B,6CAA0B;AAC1B,6CAA0B;AAC1B,yDAAsC;AACtC,oEAAiD;AACjD,+CAA4B;AAC5B,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TypedArrayConstructor } from 'justypes';
|
|
2
|
+
interface IDynamicTypedArrayOptions {
|
|
3
|
+
capacity?: number;
|
|
4
|
+
growthFactor?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class DynamicTypedArray<T extends TypedArrayConstructor> {
|
|
7
|
+
private typedArrayConstructor;
|
|
8
|
+
private array;
|
|
9
|
+
private _length;
|
|
10
|
+
private growthFactor;
|
|
11
|
+
get [Symbol.toStringTag](): string;
|
|
12
|
+
get capacity(): number;
|
|
13
|
+
get length(): number;
|
|
14
|
+
constructor(typedArrayConstructor: T, { capacity, growthFactor }?: IDynamicTypedArrayOptions);
|
|
15
|
+
set(index: number, value: number): void;
|
|
16
|
+
get(index: number): number | undefined;
|
|
17
|
+
push(...values: number[]): void;
|
|
18
|
+
pop(): number | undefined;
|
|
19
|
+
private resize;
|
|
20
|
+
}
|
|
21
|
+
export declare function computeNewCapacity(oldCapacity: number, targetLength: number, growthFactor: number): number;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeNewCapacity = exports.DynamicTypedArray = void 0;
|
|
4
|
+
const errors_1 = require("@blackglory/errors");
|
|
5
|
+
class DynamicTypedArray {
|
|
6
|
+
constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
|
|
7
|
+
this.typedArrayConstructor = typedArrayConstructor;
|
|
8
|
+
this._length = 0;
|
|
9
|
+
(0, errors_1.assert)(Number.isInteger(capacity), 'capacity must be an integer');
|
|
10
|
+
(0, errors_1.assert)(capacity >= 0, 'capacity must be greater than or equal to 0');
|
|
11
|
+
(0, errors_1.assert)(growthFactor > 1, 'growthFactory must be greater than or equal to 1');
|
|
12
|
+
this.array = new typedArrayConstructor(capacity);
|
|
13
|
+
this.growthFactor = growthFactor;
|
|
14
|
+
}
|
|
15
|
+
get [Symbol.toStringTag]() {
|
|
16
|
+
return this.constructor.name;
|
|
17
|
+
}
|
|
18
|
+
get capacity() {
|
|
19
|
+
return this.array.length;
|
|
20
|
+
}
|
|
21
|
+
get length() {
|
|
22
|
+
return this._length;
|
|
23
|
+
}
|
|
24
|
+
set(index, value) {
|
|
25
|
+
if (index >= this.capacity) {
|
|
26
|
+
const newCapacity = computeNewCapacity(this.capacity, index + 1, this.growthFactor);
|
|
27
|
+
this.resize(newCapacity);
|
|
28
|
+
}
|
|
29
|
+
if (index >= this._length) {
|
|
30
|
+
this._length = index + 1;
|
|
31
|
+
}
|
|
32
|
+
this.array[index] = value;
|
|
33
|
+
}
|
|
34
|
+
get(index) {
|
|
35
|
+
return index < this._length
|
|
36
|
+
? this.array[index]
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
push(...values) {
|
|
40
|
+
const newLength = this._length + values.length;
|
|
41
|
+
if (newLength > this.capacity) {
|
|
42
|
+
const newCapacity = computeNewCapacity(this.capacity, newLength, this.growthFactor);
|
|
43
|
+
this.resize(newCapacity);
|
|
44
|
+
}
|
|
45
|
+
for (const value of values) {
|
|
46
|
+
this.array[this._length++] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
pop() {
|
|
50
|
+
if (this._length > 0) {
|
|
51
|
+
const value = this.array[this._length - 1];
|
|
52
|
+
this._length--;
|
|
53
|
+
const newCapacity = computeNewCapacity(this.capacity, this.length, this.growthFactor);
|
|
54
|
+
this.resize(newCapacity);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
resize(newCapacity) {
|
|
62
|
+
if (this.array.length === newCapacity) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
else if (this.array.length < newCapacity) {
|
|
66
|
+
const newArray = new this.typedArrayConstructor(newCapacity);
|
|
67
|
+
newArray.set(this.array);
|
|
68
|
+
this.array = newArray;
|
|
69
|
+
}
|
|
70
|
+
else if (this.array.length > newCapacity) {
|
|
71
|
+
const newArray = new this.typedArrayConstructor(newCapacity);
|
|
72
|
+
for (let i = newCapacity; i--;) {
|
|
73
|
+
newArray[i] = this.array[i];
|
|
74
|
+
}
|
|
75
|
+
this.array = newArray;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.DynamicTypedArray = DynamicTypedArray;
|
|
80
|
+
function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
|
|
81
|
+
if (oldCapacity === targetLength) {
|
|
82
|
+
return targetLength;
|
|
83
|
+
}
|
|
84
|
+
else if (oldCapacity < targetLength) {
|
|
85
|
+
let newCapacity = Math.max(oldCapacity, 1);
|
|
86
|
+
while (newCapacity < targetLength) {
|
|
87
|
+
newCapacity *= growthFactor;
|
|
88
|
+
}
|
|
89
|
+
return Math.floor(newCapacity);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (targetLength === 0) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
let newCapacity = oldCapacity;
|
|
97
|
+
while (true) {
|
|
98
|
+
const temp = newCapacity / growthFactor;
|
|
99
|
+
if (temp < targetLength) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
newCapacity = temp;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return Math.floor(newCapacity);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.computeNewCapacity = computeNewCapacity;
|
|
111
|
+
//# sourceMappingURL=dynamic-typed-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-typed-array.js","sourceRoot":"","sources":["../../src/dynamic-typed-array.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAQ3C,MAAa,iBAAiB;IAuB5B,YACU,qBAAwB,EAChC,EACE,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,GAAG,KACW,EAAE;QAJzB,0BAAqB,GAArB,qBAAqB,CAAG;QAtB1B,YAAO,GAAW,CAAC,CAAA;QA4BzB,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,EAAC,YAAY,GAAG,CAAC,EAAE,kDAAkD,CAAC,CAAA;QAE5E,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAqB,CAAC,QAAQ,CAAC,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ACH,CAAC;CACF;AA/GD,8CA+GC;AAED,SAAgB,kBAAkB,CAChC,WAAmB,EACnB,YAAoB,EACpB,YAAoB;IAEpB,IAAI,WAAW,KAAK,YAAY,EAAE;QAChC,OAAO,YAAY,CAAA;KACpB;SAAM,IAAI,WAAW,GAAG,YAAY,EAAE;QAErC,IAAI,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;QAC1C,OAAO,WAAW,GAAG,YAAY,EAAE;YACjC,WAAW,IAAI,YAAY,CAAA;SAC5B;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;KAC/B;SAAM;QAKL,IAAI,YAAY,KAAK,CAAC,EAAE;YACtB,OAAO,CAAC,CAAA;SACT;aAAM;YACL,IAAI,WAAW,GAAG,WAAW,CAAA;YAC7B,OAAO,IAAI,EAAE;gBACX,MAAM,IAAI,GAAG,WAAW,GAAG,YAAY,CAAA;gBACvC,IAAI,IAAI,GAAG,YAAY,EAAE;oBACvB,MAAK;iBACN;qBAAM;oBACL,WAAW,GAAG,IAAI,CAAA;iBACnB;aACF;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;SAC/B;KACF;AACH,CAAC;AAlCD,gDAkCC"}
|
package/lib/es2018/index.d.ts
CHANGED
package/lib/es2018/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DynamicTypedArray = void 0;
|
|
17
18
|
__exportStar(require("./box"), exports);
|
|
18
19
|
__exportStar(require("./cons"), exports);
|
|
19
20
|
__exportStar(require("./emitter"), exports);
|
|
@@ -27,4 +28,6 @@ __exportStar(require("./trie-map"), exports);
|
|
|
27
28
|
__exportStar(require("./finite-state-machine"), exports);
|
|
28
29
|
__exportStar(require("./observable-finite-state-machine"), exports);
|
|
29
30
|
__exportStar(require("./sparse-set"), exports);
|
|
31
|
+
var dynamic_typed_array_1 = require("./dynamic-typed-array");
|
|
32
|
+
Object.defineProperty(exports, "DynamicTypedArray", { enumerable: true, get: function () { return dynamic_typed_array_1.DynamicTypedArray; } });
|
|
30
33
|
//# sourceMappingURL=index.js.map
|
package/lib/es2018/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,yCAAsB;AACtB,4CAAyB;AACzB,6CAA0B;AAC1B,6CAA0B;AAC1B,0CAAuB;AACvB,4CAAyB;AACzB,kDAA+B;AAC/B,6CAA0B;AAC1B,6CAA0B;AAC1B,yDAAsC;AACtC,oEAAiD;AACjD,+CAA4B;AAC5B,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackglory/structures",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@blackglory/errors": "^2.2.1",
|
|
73
|
-
"@blackglory/types": "^1.1
|
|
73
|
+
"@blackglory/types": "^1.2.1",
|
|
74
74
|
"extra-timers": "^0.2.5",
|
|
75
75
|
"iterable-operator": "^1.1.0",
|
|
76
|
-
"justypes": "^2.
|
|
76
|
+
"justypes": "^2.1.0",
|
|
77
77
|
"rxjs": "^7.5.5"
|
|
78
78
|
}
|
|
79
79
|
}
|