@blackglory/structures
Advanced tools
Comparing version 0.10.20 to 0.10.21
@@ -5,4 +5,5 @@ "use strict"; | ||
const errors_1 = require("@blackglory/errors"); | ||
const trailing_zeros_1 = require("./utils/trailing-zeros"); | ||
class BitSet { | ||
constructor(bitsPerElement = 32) { | ||
constructor(bitsPerElement = 31) { | ||
this.bitsPerElement = bitsPerElement; | ||
@@ -14,3 +15,3 @@ this.array = []; | ||
(0, errors_1.assert)(bitsPerElement > 0, 'The parameter bitsPerElement must be greater than 0'); | ||
(0, errors_1.assert)(bitsPerElement <= 32, 'The mask of bitsPerElement must be less than or equal to 32'); | ||
(0, errors_1.assert)(bitsPerElement <= 31, 'The mask of bitsPerElement must be less than or equal to 31'); | ||
} | ||
@@ -28,22 +29,13 @@ get [Symbol.toStringTag]() { | ||
if (this.length > 0) { | ||
const maxArrayLength = Math.ceil(this.length / this.bitsPerElement); | ||
const remainder = this.bitsPerElement | ||
- (maxArrayLength * this.bitsPerElement - this.length); | ||
const lastIndex = maxArrayLength - 1; | ||
for (let index = 0; index < lastIndex; index++) { | ||
const maxArrayLength = ~~(this.length / this.bitsPerElement) + 1; | ||
for (let index = 0; index < maxArrayLength; index++) { | ||
let element = this.array[index]; | ||
for (let bit = 0; bit < this.bitsPerElement; bit++) { | ||
if (element & 1) { | ||
yield index * this.bitsPerElement + bit; | ||
} | ||
element >>= 1; | ||
let offset = 0; | ||
let indexOfBit; | ||
while ((indexOfBit = (0, trailing_zeros_1.trailingZeros)(element)) !== 32) { | ||
yield index * this.bitsPerElement + offset + indexOfBit; | ||
offset += indexOfBit + 1; | ||
element >>= indexOfBit + 1; | ||
} | ||
} | ||
let lastElement = this.array[maxArrayLength - 1]; | ||
for (let bit = 0; bit < remainder; bit++) { | ||
if (lastElement & 1) { | ||
yield lastIndex * this.bitsPerElement + bit; | ||
} | ||
lastElement >>= 1; | ||
} | ||
} | ||
@@ -50,0 +42,0 @@ } |
@@ -27,3 +27,3 @@ "use strict"; | ||
if (this.length > 0) { | ||
const maxArrayLength = Math.ceil(this.length / this.bitsPerElement); | ||
const maxArrayLength = ~~(this.length / this.bitsPerElement) + 1; | ||
const remainder = this.bitsPerElement | ||
@@ -35,3 +35,3 @@ - (maxArrayLength * this.bitsPerElement - this.length); | ||
for (let bit = 0; bit < this.bitsPerElement; bit++) { | ||
if (element & 1) { | ||
if (element % 2) { | ||
yield index * this.bitsPerElement + bit; | ||
@@ -44,3 +44,3 @@ } | ||
for (let bit = 0; bit < remainder; bit++) { | ||
if (lastElement & 1) { | ||
if (lastElement % 2) { | ||
yield lastIndex * this.bitsPerElement + bit; | ||
@@ -47,0 +47,0 @@ } |
@@ -5,4 +5,5 @@ "use strict"; | ||
const errors_1 = require("@blackglory/errors"); | ||
const trailing_zeros_1 = require("./utils/trailing-zeros"); | ||
class BitSet { | ||
constructor(bitsPerElement = 32) { | ||
constructor(bitsPerElement = 31) { | ||
this.bitsPerElement = bitsPerElement; | ||
@@ -14,3 +15,3 @@ this.array = []; | ||
(0, errors_1.assert)(bitsPerElement > 0, 'The parameter bitsPerElement must be greater than 0'); | ||
(0, errors_1.assert)(bitsPerElement <= 32, 'The mask of bitsPerElement must be less than or equal to 32'); | ||
(0, errors_1.assert)(bitsPerElement <= 31, 'The mask of bitsPerElement must be less than or equal to 31'); | ||
} | ||
@@ -28,22 +29,13 @@ get [Symbol.toStringTag]() { | ||
if (this.length > 0) { | ||
const maxArrayLength = Math.ceil(this.length / this.bitsPerElement); | ||
const remainder = this.bitsPerElement | ||
- (maxArrayLength * this.bitsPerElement - this.length); | ||
const lastIndex = maxArrayLength - 1; | ||
for (let index = 0; index < lastIndex; index++) { | ||
const maxArrayLength = ~~(this.length / this.bitsPerElement) + 1; | ||
for (let index = 0; index < maxArrayLength; index++) { | ||
let element = this.array[index]; | ||
for (let bit = 0; bit < this.bitsPerElement; bit++) { | ||
if (element & 1) { | ||
yield index * this.bitsPerElement + bit; | ||
} | ||
element >>= 1; | ||
let offset = 0; | ||
let indexOfBit; | ||
while ((indexOfBit = (0, trailing_zeros_1.trailingZeros)(element)) !== 32) { | ||
yield index * this.bitsPerElement + offset + indexOfBit; | ||
offset += indexOfBit + 1; | ||
element >>= indexOfBit + 1; | ||
} | ||
} | ||
let lastElement = this.array[maxArrayLength - 1]; | ||
for (let bit = 0; bit < remainder; bit++) { | ||
if (lastElement & 1) { | ||
yield lastIndex * this.bitsPerElement + bit; | ||
} | ||
lastElement >>= 1; | ||
} | ||
} | ||
@@ -50,0 +42,0 @@ } |
@@ -27,3 +27,3 @@ "use strict"; | ||
if (this.length > 0) { | ||
const maxArrayLength = Math.ceil(this.length / this.bitsPerElement); | ||
const maxArrayLength = ~~(this.length / this.bitsPerElement) + 1; | ||
const remainder = this.bitsPerElement | ||
@@ -35,3 +35,3 @@ - (maxArrayLength * this.bitsPerElement - this.length); | ||
for (let bit = 0; bit < this.bitsPerElement; bit++) { | ||
if (element & 1) { | ||
if (element % 2) { | ||
yield index * this.bitsPerElement + bit; | ||
@@ -44,3 +44,3 @@ } | ||
for (let bit = 0; bit < remainder; bit++) { | ||
if (lastElement & 1) { | ||
if (lastElement % 2) { | ||
yield lastIndex * this.bitsPerElement + bit; | ||
@@ -47,0 +47,0 @@ } |
{ | ||
"name": "@blackglory/structures", | ||
"version": "0.10.20", | ||
"version": "0.10.21", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -374,3 +374,3 @@ # structures | ||
constructor(bitsPerElement: number = 8) {} | ||
constructor(bitsPerElement: number = 31) | ||
@@ -377,0 +377,0 @@ values(): IterableIterator<number> |
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
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
4682445
169
28770