@blackglory/structures 0.10.17 → 0.10.19

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.
@@ -6218,12 +6218,13 @@ class BitSet {
6218
6218
  this.bitsPerElement = bitsPerElement;
6219
6219
  this.array = [];
6220
6220
  this.length = 0;
6221
+ this._size = 0;
6221
6222
  }
6222
6223
  get [Symbol.toStringTag]() {
6223
6224
  return this.constructor.name;
6224
6225
  }
6225
6226
  get size() {
6226
- return this.length;
6227
+ return this._size;
6227
6228
  }
6228
6229
  [Symbol.iterator]() {
6229
6230
  return this.values();
@@ -6235,20 +6236,20 @@ class BitSet {
6235
6236
  - (maxArrayLength * this.bitsPerElement - this.length);
6236
6237
  const lastIndex = maxArrayLength - 1;
6237
6238
  for (let index = 0; index < lastIndex; index++) {
6238
- const element = this.array[index];
6239
+ let element = this.array[index];
6239
6240
  for (let bit = 0; bit < this.bitsPerElement; bit++) {
6240
- const mask = this.getMask(bit);
6241
- if ((element & mask) === mask) {
6241
+ if (element & 1) {
6242
6242
  yield index * this.bitsPerElement + bit;
6243
6243
  }
6244
+ element >>= 1;
6244
6245
  }
6245
6246
  }
6246
- const lastElement = this.array[maxArrayLength - 1];
6247
+ let lastElement = this.array[maxArrayLength - 1];
6247
6248
  for (let bit = 0; bit < remainder; bit++) {
6248
- const mask = this.getMask(bit);
6249
- if ((lastElement & mask) === mask) {
6249
+ if (lastElement & 1) {
6250
6250
  yield lastIndex * this.bitsPerElement + bit;
6251
6251
  }
6252
+ lastElement >>= 1;
6252
6253
  }
6253
6254
  }
6254
6255
  }
@@ -6277,14 +6278,23 @@ class BitSet {
6277
6278
  this.length = value + 1;
6278
6279
  }
6279
6280
  const [index, mask] = this.getPosition(value);
6280
- this.array[index] = ((_a = this.array[index]) !== null && _a !== void 0 ? _a : 0) | mask;
6281
+ const element = (_a = this.array[index]) !== null && _a !== void 0 ? _a : 0;
6282
+ this.array[index] = element | mask;
6283
+ const added = (element & mask) !== mask;
6284
+ if (added) {
6285
+ this._size++;
6286
+ }
6281
6287
  }
6282
6288
  delete(value) {
6283
6289
  var _a;
6284
6290
  const [index, mask] = this.getPosition(value);
6285
6291
  const element = ((_a = this.array[index]) !== null && _a !== void 0 ? _a : 0);
6286
6292
  this.array[index] = element & ~mask;
6287
- return (element & mask) === mask;
6293
+ const deleted = (element & mask) === mask;
6294
+ if (deleted) {
6295
+ this._size--;
6296
+ }
6297
+ return deleted;
6288
6298
  }
6289
6299
  clear() {
6290
6300
  for (let i = this.array.length; i--;) {
@@ -6309,12 +6319,13 @@ class TypedBitSet {
6309
6319
  this.array = array;
6310
6320
  this.bitsPerElement = this.array.internalTypedArray.BYTES_PER_ELEMENT * 8;
6311
6321
  this.length = 0;
6322
+ this._size = 0;
6312
6323
  }
6313
6324
  get [Symbol.toStringTag]() {
6314
6325
  return this.constructor.name;
6315
6326
  }
6316
6327
  get size() {
6317
- return this.length;
6328
+ return this._size;
6318
6329
  }
6319
6330
  [Symbol.iterator]() {
6320
6331
  return this.values();
@@ -6326,20 +6337,20 @@ class TypedBitSet {
6326
6337
  - (maxArrayLength * this.bitsPerElement - this.length);
6327
6338
  const lastIndex = maxArrayLength - 1;
6328
6339
  for (let index = 0; index < lastIndex; index++) {
6329
- const element = this.array.internalTypedArray[index];
6340
+ let element = this.array.internalTypedArray[index];
6330
6341
  for (let bit = 0; bit < this.bitsPerElement; bit++) {
6331
- const mask = this.getMask(bit);
6332
- if ((element & mask) === mask) {
6342
+ if (element & 1) {
6333
6343
  yield index * this.bitsPerElement + bit;
6334
6344
  }
6345
+ element >>= 1;
6335
6346
  }
6336
6347
  }
6337
- const lastElement = this.array.internalTypedArray[maxArrayLength - 1];
6348
+ let lastElement = this.array.internalTypedArray[maxArrayLength - 1];
6338
6349
  for (let bit = 0; bit < remainder; bit++) {
6339
- const mask = this.getMask(bit);
6340
- if ((lastElement & mask) === mask) {
6350
+ if (lastElement & 1) {
6341
6351
  yield lastIndex * this.bitsPerElement + bit;
6342
6352
  }
6353
+ lastElement >>= 1;
6343
6354
  }
6344
6355
  }
6345
6356
  }
@@ -6368,14 +6379,23 @@ class TypedBitSet {
6368
6379
  this.length = value + 1;
6369
6380
  }
6370
6381
  const [index, mask] = this.getPosition(value);
6371
- this.array.set(index, ((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) | mask);
6382
+ const element = (_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0;
6383
+ this.array.set(index, element | mask);
6384
+ const added = (element & mask) !== mask;
6385
+ if (added) {
6386
+ this._size++;
6387
+ }
6372
6388
  }
6373
6389
  delete(value) {
6374
6390
  var _a;
6375
6391
  const [index, mask] = this.getPosition(value);
6376
6392
  const element = ((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0);
6377
6393
  this.array.set(index, element & ~mask);
6378
- return (element & mask) === mask;
6394
+ const deleted = (element & mask) === mask;
6395
+ if (deleted) {
6396
+ this._size--;
6397
+ }
6398
+ return deleted;
6379
6399
  }
6380
6400
  clear() {
6381
6401
  for (let i = this.array.length; i--;) {