@blackglory/structures 0.6.5 → 0.6.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.
@@ -0,0 +1,23 @@
1
+ import { TypedArrayConstructor, TypedArrayOfConstructor } 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 internalTypedArray(): TypedArrayOfConstructor<T>;
12
+ get [Symbol.toStringTag](): string;
13
+ get capacity(): number;
14
+ get length(): number;
15
+ constructor(typedArrayConstructor: T, { capacity, growthFactor }?: IDynamicTypedArrayOptions);
16
+ set(index: number, value: number): void;
17
+ get(index: number): number | undefined;
18
+ push(...values: number[]): void;
19
+ pop(): number | undefined;
20
+ private resize;
21
+ }
22
+ export declare function computeNewCapacity(oldCapacity: number, targetLength: number, growthFactor: number): number;
23
+ export {};
@@ -0,0 +1,114 @@
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 internalTypedArray() {
16
+ return this.array;
17
+ }
18
+ get [Symbol.toStringTag]() {
19
+ return this.constructor.name;
20
+ }
21
+ get capacity() {
22
+ return this.array.length;
23
+ }
24
+ get length() {
25
+ return this._length;
26
+ }
27
+ set(index, value) {
28
+ if (index >= this.capacity) {
29
+ const newCapacity = computeNewCapacity(this.capacity, index + 1, this.growthFactor);
30
+ this.resize(newCapacity);
31
+ }
32
+ if (index >= this._length) {
33
+ this._length = index + 1;
34
+ }
35
+ this.array[index] = value;
36
+ }
37
+ get(index) {
38
+ return index < this._length
39
+ ? this.array[index]
40
+ : undefined;
41
+ }
42
+ push(...values) {
43
+ const newLength = this._length + values.length;
44
+ if (newLength > this.capacity) {
45
+ const newCapacity = computeNewCapacity(this.capacity, newLength, this.growthFactor);
46
+ this.resize(newCapacity);
47
+ }
48
+ for (const value of values) {
49
+ this.array[this._length++] = value;
50
+ }
51
+ }
52
+ pop() {
53
+ if (this._length > 0) {
54
+ const value = this.array[this._length - 1];
55
+ this._length--;
56
+ const newCapacity = computeNewCapacity(this.capacity, this.length, this.growthFactor);
57
+ this.resize(newCapacity);
58
+ return value;
59
+ }
60
+ else {
61
+ return undefined;
62
+ }
63
+ }
64
+ resize(newCapacity) {
65
+ if (this.array.length === newCapacity) {
66
+ return;
67
+ }
68
+ else if (this.array.length < newCapacity) {
69
+ const newArray = new this.typedArrayConstructor(newCapacity);
70
+ newArray.set(this.array);
71
+ this.array = newArray;
72
+ }
73
+ else if (this.array.length > newCapacity) {
74
+ const newArray = new this.typedArrayConstructor(newCapacity);
75
+ for (let i = newCapacity; i--;) {
76
+ newArray[i] = this.array[i];
77
+ }
78
+ this.array = newArray;
79
+ }
80
+ }
81
+ }
82
+ exports.DynamicTypedArray = DynamicTypedArray;
83
+ function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
84
+ if (oldCapacity === targetLength) {
85
+ return targetLength;
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
+ else {
95
+ if (targetLength === 0) {
96
+ return 0;
97
+ }
98
+ else {
99
+ let newCapacity = oldCapacity;
100
+ while (true) {
101
+ const temp = newCapacity / growthFactor;
102
+ if (temp < targetLength) {
103
+ break;
104
+ }
105
+ else {
106
+ newCapacity = temp;
107
+ }
108
+ }
109
+ return Math.floor(newCapacity);
110
+ }
111
+ }
112
+ }
113
+ exports.computeNewCapacity = computeNewCapacity;
114
+ //# 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;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,EAAC,YAAY,GAAG,CAAC,EAAE,kDAAkD,CAAC,CAAA;QAE5E,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAqB,CAAC,QAAQ,CAA+B,CAAA;QAC9E,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAnCD,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAKD,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;IAC1B,CAAC;IAKD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAiBD,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AAW,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"}
@@ -11,3 +11,4 @@ export * from './trie-map';
11
11
  export * from './finite-state-machine';
12
12
  export * from './observable-finite-state-machine';
13
13
  export * from './sparse-set';
14
+ export { DynamicTypedArray } from './dynamic-typed-array';
@@ -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
@@ -1 +1 @@
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"}
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"}
@@ -16,7 +16,10 @@ class SparseSet {
16
16
  }
17
17
  }
18
18
  has(value) {
19
- return (0, types_1.isntUndefined)(this.valueToValueIndex[value]);
19
+ const index = this.valueToValueIndex[value];
20
+ return (0, types_1.isUndefined)(index)
21
+ ? false
22
+ : this.values[index] === value;
20
23
  }
21
24
  add(value) {
22
25
  if (!this.has(value)) {
@@ -32,7 +35,6 @@ class SparseSet {
32
35
  const indexOfValue = this.valueToValueIndex[value];
33
36
  this.values[indexOfValue] = lastValue;
34
37
  this.valueToValueIndex[lastValue] = indexOfValue;
35
- this.valueToValueIndex[value] = undefined;
36
38
  }
37
39
  }
38
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAEjD,MAAa,SAAS;IAAtB;QACU,WAAM,GAAa,EAAE,CAAA;QACrB,sBAAiB,GAA8B,EAAE,CAAA;IAqC3D,CAAC;IAnCC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,I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ypedArrayOfConstructor } 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 internalTypedArray(): TypedArrayOfConstructor<T>;
12
+ get [Symbol.toStringTag](): string;
13
+ get capacity(): number;
14
+ get length(): number;
15
+ constructor(typedArrayConstructor: T, { capacity, growthFactor }?: IDynamicTypedArrayOptions);
16
+ set(index: number, value: number): void;
17
+ get(index: number): number | undefined;
18
+ push(...values: number[]): void;
19
+ pop(): number | undefined;
20
+ private resize;
21
+ }
22
+ export declare function computeNewCapacity(oldCapacity: number, targetLength: number, growthFactor: number): number;
23
+ export {};
@@ -0,0 +1,114 @@
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 internalTypedArray() {
16
+ return this.array;
17
+ }
18
+ get [Symbol.toStringTag]() {
19
+ return this.constructor.name;
20
+ }
21
+ get capacity() {
22
+ return this.array.length;
23
+ }
24
+ get length() {
25
+ return this._length;
26
+ }
27
+ set(index, value) {
28
+ if (index >= this.capacity) {
29
+ const newCapacity = computeNewCapacity(this.capacity, index + 1, this.growthFactor);
30
+ this.resize(newCapacity);
31
+ }
32
+ if (index >= this._length) {
33
+ this._length = index + 1;
34
+ }
35
+ this.array[index] = value;
36
+ }
37
+ get(index) {
38
+ return index < this._length
39
+ ? this.array[index]
40
+ : undefined;
41
+ }
42
+ push(...values) {
43
+ const newLength = this._length + values.length;
44
+ if (newLength > this.capacity) {
45
+ const newCapacity = computeNewCapacity(this.capacity, newLength, this.growthFactor);
46
+ this.resize(newCapacity);
47
+ }
48
+ for (const value of values) {
49
+ this.array[this._length++] = value;
50
+ }
51
+ }
52
+ pop() {
53
+ if (this._length > 0) {
54
+ const value = this.array[this._length - 1];
55
+ this._length--;
56
+ const newCapacity = computeNewCapacity(this.capacity, this.length, this.growthFactor);
57
+ this.resize(newCapacity);
58
+ return value;
59
+ }
60
+ else {
61
+ return undefined;
62
+ }
63
+ }
64
+ resize(newCapacity) {
65
+ if (this.array.length === newCapacity) {
66
+ return;
67
+ }
68
+ else if (this.array.length < newCapacity) {
69
+ const newArray = new this.typedArrayConstructor(newCapacity);
70
+ newArray.set(this.array);
71
+ this.array = newArray;
72
+ }
73
+ else if (this.array.length > newCapacity) {
74
+ const newArray = new this.typedArrayConstructor(newCapacity);
75
+ for (let i = newCapacity; i--;) {
76
+ newArray[i] = this.array[i];
77
+ }
78
+ this.array = newArray;
79
+ }
80
+ }
81
+ }
82
+ exports.DynamicTypedArray = DynamicTypedArray;
83
+ function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
84
+ if (oldCapacity === targetLength) {
85
+ return targetLength;
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
+ else {
95
+ if (targetLength === 0) {
96
+ return 0;
97
+ }
98
+ else {
99
+ let newCapacity = oldCapacity;
100
+ while (true) {
101
+ const temp = newCapacity / growthFactor;
102
+ if (temp < targetLength) {
103
+ break;
104
+ }
105
+ else {
106
+ newCapacity = temp;
107
+ }
108
+ }
109
+ return Math.floor(newCapacity);
110
+ }
111
+ }
112
+ }
113
+ exports.computeNewCapacity = computeNewCapacity;
114
+ //# 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;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,EAAC,YAAY,GAAG,CAAC,EAAE,kDAAkD,CAAC,CAAA;QAE5E,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAqB,CAAC,QAAQ,CAA+B,CAAA;QAC9E,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAnCD,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAKD,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;IAC1B,CAAC;IAKD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAiBD,GAAG,CAAC,KAAa,EAAE,KAAa;QAC9B,IAAI,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC1B,MAAM,WAAW,GAAG,kBAAkB,CACpC,IAAI,CAAC,QAAQ,EACb,KAAK,G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AAA;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"}
@@ -11,3 +11,4 @@ export * from './trie-map';
11
11
  export * from './finite-state-machine';
12
12
  export * from './observable-finite-state-machine';
13
13
  export * from './sparse-set';
14
+ export { DynamicTypedArray } from './dynamic-typed-array';
@@ -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
@@ -1 +1 @@
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"}
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"}
@@ -16,7 +16,10 @@ class SparseSet {
16
16
  }
17
17
  }
18
18
  has(value) {
19
- return (0, types_1.isntUndefined)(this.valueToValueIndex[value]);
19
+ const index = this.valueToValueIndex[value];
20
+ return (0, types_1.isUndefined)(index)
21
+ ? false
22
+ : this.values[index] === value;
20
23
  }
21
24
  add(value) {
22
25
  if (!this.has(value)) {
@@ -32,7 +35,6 @@ class SparseSet {
32
35
  const indexOfValue = this.valueToValueIndex[value];
33
36
  this.values[indexOfValue] = lastValue;
34
37
  this.valueToValueIndex[lastValue] = indexOfValue;
35
- this.valueToValueIndex[value] = undefined;
36
38
  }
37
39
  }
38
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sparse-set.js","sourceRoot":"","sources":["../../src/sparse-set.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAEjD,MAAa,SAAS;IAAtB;QACU,WAAM,GAAa,EAAE,CAAA;QACrB,sBAAiB,GAA8B,EAAE,CAAA;IAqC3D,CAAC;IAnCC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;YAC/B,MAAM,KAAK,CAAA;SACZ;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;QAChB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;YAC/B,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;IAED,GAAG,CAAC,KAAa;QACf,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;QAC3C,OAAO,IAAA,mBAAW,EAAC,KAAK,CAAC;YACpB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,CAAA;IACrC,CAAC;IAED,GAAG,CAAC,KAAa;QACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACpB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAA;YAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACvB,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA;SACtC;IACH,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YACnB,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAG,CAAA;YACpC,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAE,CAAA;gBACnD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAAA;gBACrC,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,YAAY,CAAA;aACjD;SACF;IACH,CAAC;CACF;AAvCD,8BAuCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackglory/structures",
3
- "version": "0.6.5",
3
+ "version": "0.6.8",
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.0",
73
+ "@blackglory/types": "^1.2.1",
74
74
  "extra-timers": "^0.2.5",
75
75
  "iterable-operator": "^1.1.0",
76
- "justypes": "^2.0.0",
76
+ "justypes": "^2.1.0",
77
77
  "rxjs": "^7.5.5"
78
78
  }
79
79
  }