@isopodlabs/utilities 1.5.6 → 1.5.7
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/dist/bits.d.ts +39 -10
- package/dist/bits.js +15 -3
- package/package.json +1 -1
package/dist/bits.d.ts
CHANGED
|
@@ -7,7 +7,33 @@ export declare function countSet(x: bigint | number): number;
|
|
|
7
7
|
export declare function highestClear(x: number | bigint): number;
|
|
8
8
|
export declare function lowestClear(x: number | bigint): number;
|
|
9
9
|
export declare function countClear(x: bigint | number): number;
|
|
10
|
-
export
|
|
10
|
+
export interface immutableBitSet {
|
|
11
|
+
countSet(): number;
|
|
12
|
+
complement(): this;
|
|
13
|
+
intersect(other: this): this;
|
|
14
|
+
union(other: this): this;
|
|
15
|
+
xor(other: this): this;
|
|
16
|
+
contains(other: this): boolean;
|
|
17
|
+
test(a: number): boolean;
|
|
18
|
+
next(a: number, set: boolean): number;
|
|
19
|
+
where(set: boolean, from?: number): {
|
|
20
|
+
[Symbol.iterator](): Generator<number>;
|
|
21
|
+
};
|
|
22
|
+
ranges(): {
|
|
23
|
+
[Symbol.iterator](): Generator<number[]>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface BitSet extends immutableBitSet {
|
|
27
|
+
set(a: number): void;
|
|
28
|
+
clear(a: number): void;
|
|
29
|
+
setRange(a: number, b: number): this;
|
|
30
|
+
clearRange(a: number, b: number): this;
|
|
31
|
+
selfComplement(): this;
|
|
32
|
+
selfIntersect(other: this): this;
|
|
33
|
+
selfUnion(other: this): this;
|
|
34
|
+
selfXor(other: this): this;
|
|
35
|
+
}
|
|
36
|
+
export declare class ImmutableSparseBits implements immutableBitSet {
|
|
11
37
|
protected bits: number[];
|
|
12
38
|
protected undef: number;
|
|
13
39
|
static whereGenerator(bits: number[], undef: number, set: boolean, from?: number): Generator<number>;
|
|
@@ -24,7 +50,8 @@ export declare class ImmutableSparseBits {
|
|
|
24
50
|
xor(other: ImmutableSparseBits): this;
|
|
25
51
|
clean(): this;
|
|
26
52
|
contains(other: ImmutableSparseBits): boolean;
|
|
27
|
-
|
|
53
|
+
test(a: number): boolean;
|
|
54
|
+
countSet(): number;
|
|
28
55
|
next(a: number, set?: boolean): number;
|
|
29
56
|
toDense(): DenseBits;
|
|
30
57
|
where(set: boolean, from?: number): {
|
|
@@ -35,7 +62,7 @@ export declare class ImmutableSparseBits {
|
|
|
35
62
|
};
|
|
36
63
|
[Symbol.iterator](): Generator<number>;
|
|
37
64
|
}
|
|
38
|
-
export declare class SparseBits extends ImmutableSparseBits {
|
|
65
|
+
export declare class SparseBits extends ImmutableSparseBits implements BitSet {
|
|
39
66
|
private setMask;
|
|
40
67
|
private clearMask;
|
|
41
68
|
selfComplement(): this;
|
|
@@ -44,20 +71,22 @@ export declare class SparseBits extends ImmutableSparseBits {
|
|
|
44
71
|
selfXor(other: SparseBits): this;
|
|
45
72
|
set(a: number): void;
|
|
46
73
|
clear(a: number): void;
|
|
47
|
-
|
|
74
|
+
test(a: number): boolean;
|
|
48
75
|
setRange(a: number, b: number): this;
|
|
49
76
|
clearRange(a: number, b: number): this;
|
|
50
77
|
}
|
|
51
|
-
export declare class ImmutableDenseBits {
|
|
78
|
+
export declare class ImmutableDenseBits implements immutableBitSet {
|
|
52
79
|
protected bits: bigint;
|
|
53
80
|
constructor(bits?: bigint);
|
|
54
81
|
protected create(bits?: bigint): this;
|
|
55
82
|
complement(): this;
|
|
56
|
-
intersect(other:
|
|
57
|
-
union(other:
|
|
58
|
-
xor(other:
|
|
59
|
-
|
|
83
|
+
intersect(other: ImmutableDenseBits): this;
|
|
84
|
+
union(other: ImmutableDenseBits): this;
|
|
85
|
+
xor(other: ImmutableDenseBits): this;
|
|
86
|
+
test(a: number): boolean;
|
|
87
|
+
contains(other: this): boolean;
|
|
60
88
|
next(a: number, set?: boolean): number;
|
|
89
|
+
countSet(): number;
|
|
61
90
|
get length(): number;
|
|
62
91
|
where(set: boolean, from?: number): {
|
|
63
92
|
[Symbol.iterator](): Generator<number>;
|
|
@@ -68,7 +97,7 @@ export declare class ImmutableDenseBits {
|
|
|
68
97
|
[Symbol.iterator](): Generator<number>;
|
|
69
98
|
toSparse(): SparseBits;
|
|
70
99
|
}
|
|
71
|
-
export declare class DenseBits extends ImmutableDenseBits {
|
|
100
|
+
export declare class DenseBits extends ImmutableDenseBits implements BitSet {
|
|
72
101
|
private setMask;
|
|
73
102
|
private clearMask;
|
|
74
103
|
selfComplement(): this;
|
package/dist/bits.js
CHANGED
|
@@ -278,9 +278,15 @@ class ImmutableSparseBits {
|
|
|
278
278
|
}
|
|
279
279
|
return true;
|
|
280
280
|
}
|
|
281
|
-
|
|
281
|
+
test(a) {
|
|
282
282
|
return !!((this.bits[a >> 5] ?? this.undef) & (1 << (a & 0x1f)));
|
|
283
283
|
}
|
|
284
|
+
countSet() {
|
|
285
|
+
let count = 0;
|
|
286
|
+
for (const i in this.bits)
|
|
287
|
+
count += countSet32(this.bits[i]);
|
|
288
|
+
return count;
|
|
289
|
+
}
|
|
284
290
|
next(a, set = true) {
|
|
285
291
|
++a;
|
|
286
292
|
const xor = this.undef;
|
|
@@ -429,7 +435,7 @@ class SparseBits extends ImmutableSparseBits {
|
|
|
429
435
|
clear(a) {
|
|
430
436
|
this.clearMask(a >> 5, 1 << (a & 0x1f));
|
|
431
437
|
}
|
|
432
|
-
|
|
438
|
+
test(a) {
|
|
433
439
|
const i = a >> 5;
|
|
434
440
|
return !!((this.bits[i] ?? this.undef) & (1 << (a & 0x1f)));
|
|
435
441
|
}
|
|
@@ -497,14 +503,20 @@ class ImmutableDenseBits {
|
|
|
497
503
|
xor(other) {
|
|
498
504
|
return this.create(this.bits ^ other.bits);
|
|
499
505
|
}
|
|
500
|
-
|
|
506
|
+
test(a) {
|
|
501
507
|
return !!(this.bits & (1n << BigInt(a)));
|
|
502
508
|
}
|
|
509
|
+
contains(other) {
|
|
510
|
+
return (this.bits & other.bits) === other.bits;
|
|
511
|
+
}
|
|
503
512
|
next(a, set = true) {
|
|
504
513
|
let s = this.bits >> BigInt(a + 1);
|
|
505
514
|
s = set ? s & -s : (s + 1n) & ~s;
|
|
506
515
|
return s ? a + highestSet(s) : -1;
|
|
507
516
|
}
|
|
517
|
+
countSet() {
|
|
518
|
+
return countSet(this.bits);
|
|
519
|
+
}
|
|
508
520
|
get length() {
|
|
509
521
|
return highestSet(this.bits);
|
|
510
522
|
}
|