@blackglory/structures
Advanced tools
Comparing version 0.10.4 to 0.10.5
export declare class BitSet { | ||
private static bitsPerElement; | ||
private array; | ||
private length; | ||
private array; | ||
get [Symbol.toStringTag](): string; | ||
@@ -8,2 +9,3 @@ get size(): number; | ||
values(): IterableIterator<number>; | ||
_dumpBinaryStrings(): string[]; | ||
has(value: number): boolean; | ||
@@ -10,0 +12,0 @@ add(value: number): void; |
@@ -8,4 +8,4 @@ "use strict"; | ||
constructor() { | ||
this.array = new dynamic_typed_array_1.DynamicTypedArray(Uint8Array); | ||
this.length = 0; | ||
this.array = new dynamic_typed_array_1.DynamicTypedArray(Uint8Array); | ||
} | ||
@@ -22,8 +22,38 @@ get [Symbol.toStringTag]() { | ||
*values() { | ||
for (let i = 0; i < this.length; i++) { | ||
if (this.has(i)) { | ||
yield i; | ||
if (this.length > 0) { | ||
const maxArrayLength = Math.ceil(this.length / BitSet.bitsPerElement); | ||
const remainder = BitSet.bitsPerElement - (maxArrayLength * BitSet.bitsPerElement - this.length); | ||
const lastIndex = maxArrayLength - 1; | ||
for (let index = 0; index < lastIndex; index++) { | ||
const element = this.array.internalTypedArray[index]; | ||
for (let bit = 0; bit < BitSet.bitsPerElement; bit++) { | ||
const mask = this.getMask(bit); | ||
if ((element & mask) === mask) { | ||
yield index * 8 + bit; | ||
} | ||
} | ||
} | ||
const lastElement = this.array.internalTypedArray[maxArrayLength - 1]; | ||
for (let bit = 0; bit < remainder; bit++) { | ||
const mask = this.getMask(bit); | ||
if ((lastElement & mask) === mask) { | ||
yield lastIndex * 8 + bit; | ||
} | ||
} | ||
} | ||
} | ||
_dumpBinaryStrings() { | ||
const result = []; | ||
const expectedBinaryStringLength = Uint8Array.BYTES_PER_ELEMENT * 8; | ||
for (let i = 0; i < this.array.length; i++) { | ||
const binary = this.array.internalTypedArray[i].toString(2); | ||
if (binary.length < expectedBinaryStringLength) { | ||
result.push('0'.repeat(expectedBinaryStringLength - binary.length) + binary); | ||
} | ||
else { | ||
result.push(binary); | ||
} | ||
} | ||
return result; | ||
} | ||
has(value) { | ||
@@ -54,7 +84,6 @@ var _a; | ||
getPosition(value) { | ||
const bits = Uint8Array.BYTES_PER_ELEMENT * 8; | ||
const remainder = value % bits; | ||
const quotient = (value - remainder) / bits; | ||
const index = Math.max(0, quotient - 1); | ||
const mask = this.getMask(value); | ||
const remainder = value % BitSet.bitsPerElement; | ||
const quotient = (value - remainder) / BitSet.bitsPerElement; | ||
const index = quotient; | ||
const mask = this.getMask(remainder); | ||
return { index, mask }; | ||
@@ -67,2 +96,3 @@ } | ||
exports.BitSet = BitSet; | ||
BitSet.bitsPerElement = Uint8Array.BYTES_PER_ELEMENT * 8; | ||
//# sourceMappingURL=bit-set.js.map |
export declare class BitSet { | ||
private static bitsPerElement; | ||
private array; | ||
private length; | ||
private array; | ||
get [Symbol.toStringTag](): string; | ||
@@ -8,2 +9,3 @@ get size(): number; | ||
values(): IterableIterator<number>; | ||
_dumpBinaryStrings(): string[]; | ||
has(value: number): boolean; | ||
@@ -10,0 +12,0 @@ add(value: number): void; |
@@ -8,4 +8,4 @@ "use strict"; | ||
constructor() { | ||
this.array = new dynamic_typed_array_1.DynamicTypedArray(Uint8Array); | ||
this.length = 0; | ||
this.array = new dynamic_typed_array_1.DynamicTypedArray(Uint8Array); | ||
} | ||
@@ -22,8 +22,38 @@ get [Symbol.toStringTag]() { | ||
*values() { | ||
for (let i = 0; i < this.length; i++) { | ||
if (this.has(i)) { | ||
yield i; | ||
if (this.length > 0) { | ||
const maxArrayLength = Math.ceil(this.length / BitSet.bitsPerElement); | ||
const remainder = BitSet.bitsPerElement - (maxArrayLength * BitSet.bitsPerElement - this.length); | ||
const lastIndex = maxArrayLength - 1; | ||
for (let index = 0; index < lastIndex; index++) { | ||
const element = this.array.internalTypedArray[index]; | ||
for (let bit = 0; bit < BitSet.bitsPerElement; bit++) { | ||
const mask = this.getMask(bit); | ||
if ((element & mask) === mask) { | ||
yield index * 8 + bit; | ||
} | ||
} | ||
} | ||
const lastElement = this.array.internalTypedArray[maxArrayLength - 1]; | ||
for (let bit = 0; bit < remainder; bit++) { | ||
const mask = this.getMask(bit); | ||
if ((lastElement & mask) === mask) { | ||
yield lastIndex * 8 + bit; | ||
} | ||
} | ||
} | ||
} | ||
_dumpBinaryStrings() { | ||
const result = []; | ||
const expectedBinaryStringLength = Uint8Array.BYTES_PER_ELEMENT * 8; | ||
for (let i = 0; i < this.array.length; i++) { | ||
const binary = this.array.internalTypedArray[i].toString(2); | ||
if (binary.length < expectedBinaryStringLength) { | ||
result.push('0'.repeat(expectedBinaryStringLength - binary.length) + binary); | ||
} | ||
else { | ||
result.push(binary); | ||
} | ||
} | ||
return result; | ||
} | ||
has(value) { | ||
@@ -54,7 +84,6 @@ var _a; | ||
getPosition(value) { | ||
const bits = Uint8Array.BYTES_PER_ELEMENT * 8; | ||
const remainder = value % bits; | ||
const quotient = (value - remainder) / bits; | ||
const index = Math.max(0, quotient - 1); | ||
const mask = this.getMask(value); | ||
const remainder = value % BitSet.bitsPerElement; | ||
const quotient = (value - remainder) / BitSet.bitsPerElement; | ||
const index = quotient; | ||
const mask = this.getMask(remainder); | ||
return { index, mask }; | ||
@@ -67,2 +96,3 @@ } | ||
exports.BitSet = BitSet; | ||
BitSet.bitsPerElement = Uint8Array.BYTES_PER_ELEMENT * 8; | ||
//# sourceMappingURL=bit-set.js.map |
{ | ||
"name": "@blackglory/structures", | ||
"version": "0.10.4", | ||
"version": "0.10.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11896088
68676