@blackglory/structures 0.10.18 → 0.10.20

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.
@@ -5912,6 +5912,9 @@ class DynamicTypedArray {
5912
5912
  get [Symbol.toStringTag]() {
5913
5913
  return this.constructor.name;
5914
5914
  }
5915
+ get BYTES_PER_ELEMENT() {
5916
+ return this.typedArrayConstructor.BYTES_PER_ELEMENT;
5917
+ }
5915
5918
  /**
5916
5919
  * 数组当前的容量.
5917
5920
  */
@@ -6214,11 +6217,15 @@ class SortedSet {
6214
6217
  }
6215
6218
 
6216
6219
  class BitSet {
6217
- constructor(bitsPerElement = 8) {
6220
+ constructor(bitsPerElement = 32) {
6218
6221
  this.bitsPerElement = bitsPerElement;
6219
6222
  this.array = [];
6220
6223
  this.length = 0;
6221
6224
  this._size = 0;
6225
+ es2018Exports$1.assert(Number.isInteger(bitsPerElement), 'The parameter bitsPerElement must be an integer');
6226
+ es2018Exports$1.assert(bitsPerElement > 0, 'The parameter bitsPerElement must be greater than 0');
6227
+ // `32`是该数据结构中能够处理的最大值
6228
+ es2018Exports$1.assert(bitsPerElement <= 32, 'The mask of bitsPerElement must be less than or equal to 32');
6222
6229
  }
6223
6230
  get [Symbol.toStringTag]() {
6224
6231
  return this.constructor.name;
@@ -6236,20 +6243,20 @@ class BitSet {
6236
6243
  - (maxArrayLength * this.bitsPerElement - this.length);
6237
6244
  const lastIndex = maxArrayLength - 1;
6238
6245
  for (let index = 0; index < lastIndex; index++) {
6239
- const element = this.array[index];
6246
+ let element = this.array[index];
6240
6247
  for (let bit = 0; bit < this.bitsPerElement; bit++) {
6241
- const mask = this.getMask(bit);
6242
- if ((element & mask) === mask) {
6248
+ if (element & 1) {
6243
6249
  yield index * this.bitsPerElement + bit;
6244
6250
  }
6251
+ element >>= 1;
6245
6252
  }
6246
6253
  }
6247
- const lastElement = this.array[maxArrayLength - 1];
6254
+ let lastElement = this.array[maxArrayLength - 1];
6248
6255
  for (let bit = 0; bit < remainder; bit++) {
6249
- const mask = this.getMask(bit);
6250
- if ((lastElement & mask) === mask) {
6256
+ if (lastElement & 1) {
6251
6257
  yield lastIndex * this.bitsPerElement + bit;
6252
6258
  }
6259
+ lastElement >>= 1;
6253
6260
  }
6254
6261
  }
6255
6262
  }
@@ -6317,9 +6324,14 @@ class BitSet {
6317
6324
  class TypedBitSet {
6318
6325
  constructor(array) {
6319
6326
  this.array = array;
6320
- this.bitsPerElement = this.array.internalTypedArray.BYTES_PER_ELEMENT * 8;
6321
6327
  this.length = 0;
6322
6328
  this._size = 0;
6329
+ const bitsPerElement = array.BYTES_PER_ELEMENT * 8;
6330
+ es2018Exports$1.assert(Number.isInteger(bitsPerElement), 'The parameter bitsPerElement must be an integer');
6331
+ es2018Exports$1.assert(bitsPerElement > 0, 'The parameter bitsPerElement must be greater than 0');
6332
+ // `32`是该数据结构中能够处理的最大值
6333
+ es2018Exports$1.assert(bitsPerElement <= 32, 'The mask of bitsPerElement must be less than or equal to 32');
6334
+ this.bitsPerElement = bitsPerElement;
6323
6335
  }
6324
6336
  get [Symbol.toStringTag]() {
6325
6337
  return this.constructor.name;
@@ -6337,20 +6349,20 @@ class TypedBitSet {
6337
6349
  - (maxArrayLength * this.bitsPerElement - this.length);
6338
6350
  const lastIndex = maxArrayLength - 1;
6339
6351
  for (let index = 0; index < lastIndex; index++) {
6340
- const element = this.array.internalTypedArray[index];
6352
+ let element = this.array.internalTypedArray[index];
6341
6353
  for (let bit = 0; bit < this.bitsPerElement; bit++) {
6342
- const mask = this.getMask(bit);
6343
- if ((element & mask) === mask) {
6354
+ if (element & 1) {
6344
6355
  yield index * this.bitsPerElement + bit;
6345
6356
  }
6357
+ element >>= 1;
6346
6358
  }
6347
6359
  }
6348
- const lastElement = this.array.internalTypedArray[maxArrayLength - 1];
6360
+ let lastElement = this.array.internalTypedArray[maxArrayLength - 1];
6349
6361
  for (let bit = 0; bit < remainder; bit++) {
6350
- const mask = this.getMask(bit);
6351
- if ((lastElement & mask) === mask) {
6362
+ if (lastElement & 1) {
6352
6363
  yield lastIndex * this.bitsPerElement + bit;
6353
6364
  }
6365
+ lastElement >>= 1;
6354
6366
  }
6355
6367
  }
6356
6368
  }