@blackglory/structures 0.10.2 → 0.10.3

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,12 @@
1
+ export declare class BitSet {
2
+ private length;
3
+ private array;
4
+ get [Symbol.toStringTag](): string;
5
+ get size(): number;
6
+ has(value: number): boolean;
7
+ add(value: number): void;
8
+ delete(value: number): void;
9
+ clear(): void;
10
+ private getPosition;
11
+ private getMask;
12
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitSet = void 0;
4
+ const dynamic_typed_array_1 = require("./dynamic-typed-array");
5
+ const errors_1 = require("@blackglory/errors");
6
+ class BitSet {
7
+ constructor() {
8
+ this.length = 0;
9
+ this.array = new dynamic_typed_array_1.DynamicTypedArray(Uint8Array);
10
+ }
11
+ get [Symbol.toStringTag]() {
12
+ return this.constructor.name;
13
+ }
14
+ get size() {
15
+ return this.length;
16
+ }
17
+ has(value) {
18
+ var _a;
19
+ const { index, mask } = this.getPosition(value);
20
+ return (((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) & mask) === mask;
21
+ }
22
+ add(value) {
23
+ var _a;
24
+ (0, errors_1.assert)(value >= 0, 'value must be greater than or equal to 0');
25
+ if (value >= this.length) {
26
+ this.length = value + 1;
27
+ }
28
+ const { index, mask } = this.getPosition(value);
29
+ this.array.set(index, ((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) | mask);
30
+ }
31
+ delete(value) {
32
+ var _a;
33
+ const { index, mask } = this.getPosition(value);
34
+ this.array.set(index, ((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) & ~mask);
35
+ }
36
+ clear() {
37
+ for (let i = this.array.length; i--;) {
38
+ this.array.set(i, 0);
39
+ }
40
+ }
41
+ getPosition(value) {
42
+ const bits = Uint8Array.BYTES_PER_ELEMENT * 8;
43
+ const remainder = value % bits;
44
+ const quotient = (value - remainder) / bits;
45
+ const index = Math.max(0, quotient - 1);
46
+ const mask = this.getMask(value);
47
+ return { index, mask };
48
+ }
49
+ getMask(value) {
50
+ return Math.pow(2, value);
51
+ }
52
+ }
53
+ exports.BitSet = BitSet;
54
+ //# sourceMappingURL=bit-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-set.js","sourceRoot":"","sources":["../../src/bit-set.ts"],"names":[],"mappings":";;;AAAA,+DAAyD;AACzD,+CAA2C;AAE3C,MAAa,MAAM;IAAnB;QACU,WAAM,GAAG,CAAC,CAAA;QACV,UAAK,GAAG,IAAI,uCAAiB,CAAC,UAAU,CAAC,CAAA;IAmDnD,CAAC;IAjDC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,GAAG,CAAC,KAAa;;QACf,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QAE/C,OAAO,CAAC,CAAC,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,CAAA;IACvD,CAAC;IAED,GAAG,CAAC,KAAa;;QACf,IAAA,eAAM,EAAC,KAAK,IAAI,CAAC,EAAE,0CAA0C,CAAC,CAAA;QAC9D,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;YACxB,IAAI,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAA;SACxB;QAED,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QAE/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;IAC5D,CAAC;IAED,MAAM,CAAC,KAAa;;QAClB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QAE/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK;QACH,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG;YACpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;SACrB;IACH,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,MAAM,IAAI,GAAG,UAAU,CAAC,iBAAiB,GAAG,CAAC,CAAA;QAC7C,MAAM,SAAS,GAAG,KAAK,GAAG,IAAI,CAAA;QAC9B,MAAM,QAAQ,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,IAAI,CAAA;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAA;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAChC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IACxB,CAAC;IAEO,OAAO,CAAC,KAAa;QAC3B,OAAO,SAAA,CAAC,EAAI,KAAK,CAAA,CAAA;IACnB,CAAC;CACF;AArDD,wBAqDC"}
@@ -16,3 +16,4 @@ export * from './typed-sparse-map';
16
16
  export * from './typed-sparse-set';
17
17
  export { DynamicTypedArray } from './dynamic-typed-array';
18
18
  export * from './sorted-set';
19
+ export * from './bit-set';
@@ -34,4 +34,5 @@ __exportStar(require("./typed-sparse-set"), exports);
34
34
  var dynamic_typed_array_1 = require("./dynamic-typed-array");
35
35
  Object.defineProperty(exports, "DynamicTypedArray", { enumerable: true, get: function () { return dynamic_typed_array_1.DynamicTypedArray; } });
36
36
  __exportStar(require("./sorted-set"), exports);
37
+ __exportStar(require("./bit-set"), exports);
37
38
  //# 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;AAC5B,+CAA4B;AAC5B,qDAAkC;AAClC,qDAAkC;AAClC,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,+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,+CAA4B;AAC5B,qDAAkC;AAClC,qDAAkC;AAClC,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,+CAA4B;AAC5B,4CAAyB"}
@@ -0,0 +1,12 @@
1
+ export declare class BitSet {
2
+ private length;
3
+ private array;
4
+ get [Symbol.toStringTag](): string;
5
+ get size(): number;
6
+ has(value: number): boolean;
7
+ add(value: number): void;
8
+ delete(value: number): void;
9
+ clear(): void;
10
+ private getPosition;
11
+ private getMask;
12
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitSet = void 0;
4
+ const dynamic_typed_array_1 = require("./dynamic-typed-array");
5
+ const errors_1 = require("@blackglory/errors");
6
+ class BitSet {
7
+ constructor() {
8
+ this.length = 0;
9
+ this.array = new dynamic_typed_array_1.DynamicTypedArray(Uint8Array);
10
+ }
11
+ get [Symbol.toStringTag]() {
12
+ return this.constructor.name;
13
+ }
14
+ get size() {
15
+ return this.length;
16
+ }
17
+ has(value) {
18
+ var _a;
19
+ const { index, mask } = this.getPosition(value);
20
+ return (((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) & mask) === mask;
21
+ }
22
+ add(value) {
23
+ var _a;
24
+ (0, errors_1.assert)(value >= 0, 'value must be greater than or equal to 0');
25
+ if (value >= this.length) {
26
+ this.length = value + 1;
27
+ }
28
+ const { index, mask } = this.getPosition(value);
29
+ this.array.set(index, ((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) | mask);
30
+ }
31
+ delete(value) {
32
+ var _a;
33
+ const { index, mask } = this.getPosition(value);
34
+ this.array.set(index, ((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) & ~mask);
35
+ }
36
+ clear() {
37
+ for (let i = this.array.length; i--;) {
38
+ this.array.set(i, 0);
39
+ }
40
+ }
41
+ getPosition(value) {
42
+ const bits = Uint8Array.BYTES_PER_ELEMENT * 8;
43
+ const remainder = value % bits;
44
+ const quotient = (value - remainder) / bits;
45
+ const index = Math.max(0, quotient - 1);
46
+ const mask = this.getMask(value);
47
+ return { index, mask };
48
+ }
49
+ getMask(value) {
50
+ return 2 ** value;
51
+ }
52
+ }
53
+ exports.BitSet = BitSet;
54
+ //# sourceMappingURL=bit-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-set.js","sourceRoot":"","sources":["../../src/bit-set.ts"],"names":[],"mappings":";;;AAAA,+DAAyD;AACzD,+CAA2C;AAE3C,MAAa,MAAM;IAAnB;Q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AAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK;QACH,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG;YACpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;SACrB;IACH,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,MAAM,IAAI,GAAG,UAAU,CAAC,iBAAiB,GAAG,CAAC,CAAA;QAC7C,MAAM,SAAS,GAAG,KAAK,GAAG,IAAI,CAAA;QAC9B,MAAM,QAAQ,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,IAAI,CAAA;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAA;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAChC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IACxB,CAAC;IAEO,OAAO,CAAC,KAAa;QAC3B,OAAO,CAAC,IAAI,KAAK,CAAA;IACnB,CAAC;CACF;AArDD,wBAqDC"}
@@ -16,3 +16,4 @@ export * from './typed-sparse-map';
16
16
  export * from './typed-sparse-set';
17
17
  export { DynamicTypedArray } from './dynamic-typed-array';
18
18
  export * from './sorted-set';
19
+ export * from './bit-set';
@@ -34,4 +34,5 @@ __exportStar(require("./typed-sparse-set"), exports);
34
34
  var dynamic_typed_array_1 = require("./dynamic-typed-array");
35
35
  Object.defineProperty(exports, "DynamicTypedArray", { enumerable: true, get: function () { return dynamic_typed_array_1.DynamicTypedArray; } });
36
36
  __exportStar(require("./sorted-set"), exports);
37
+ __exportStar(require("./bit-set"), exports);
37
38
  //# 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;AAC5B,+CAA4B;AAC5B,qDAAkC;AAClC,qDAAkC;AAClC,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,+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,+CAA4B;AAC5B,qDAAkC;AAClC,qDAAkC;AAClC,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,+CAA4B;AAC5B,4CAAyB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackglory/structures",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "",
5
5
  "files": [
6
6
  "lib",