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