@blackglory/structures 0.10.4 → 0.10.5

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.
@@ -16955,8 +16955,8 @@ class SortedSet {
16955
16955
 
16956
16956
  class BitSet {
16957
16957
  constructor() {
16958
+ this.array = new DynamicTypedArray(Uint8Array);
16958
16959
  this.length = 0;
16959
- this.array = new DynamicTypedArray(Uint8Array); // 经测试, 比Uint32Array快
16960
16960
  }
16961
16961
  get [Symbol.toStringTag]() {
16962
16962
  return this.constructor.name;
@@ -16968,12 +16968,42 @@ class BitSet {
16968
16968
  return this.values();
16969
16969
  }
16970
16970
  *values() {
16971
- for (let i = 0; i < this.length; i++) {
16972
- if (this.has(i)) {
16973
- yield i;
16971
+ if (this.length > 0) {
16972
+ const maxArrayLength = Math.ceil(this.length / BitSet.bitsPerElement);
16973
+ const remainder = BitSet.bitsPerElement - (maxArrayLength * BitSet.bitsPerElement - this.length);
16974
+ const lastIndex = maxArrayLength - 1;
16975
+ for (let index = 0; index < lastIndex; index++) {
16976
+ const element = this.array.internalTypedArray[index];
16977
+ for (let bit = 0; bit < BitSet.bitsPerElement; bit++) {
16978
+ const mask = this.getMask(bit);
16979
+ if ((element & mask) === mask) {
16980
+ yield index * 8 + bit;
16981
+ }
16982
+ }
16983
+ }
16984
+ const lastElement = this.array.internalTypedArray[maxArrayLength - 1];
16985
+ for (let bit = 0; bit < remainder; bit++) {
16986
+ const mask = this.getMask(bit);
16987
+ if ((lastElement & mask) === mask) {
16988
+ yield lastIndex * 8 + bit;
16989
+ }
16974
16990
  }
16975
16991
  }
16976
16992
  }
16993
+ _dumpBinaryStrings() {
16994
+ const result = [];
16995
+ const expectedBinaryStringLength = Uint8Array.BYTES_PER_ELEMENT * 8;
16996
+ for (let i = 0; i < this.array.length; i++) {
16997
+ const binary = this.array.internalTypedArray[i].toString(2);
16998
+ if (binary.length < expectedBinaryStringLength) {
16999
+ result.push('0'.repeat(expectedBinaryStringLength - binary.length) + binary);
17000
+ }
17001
+ else {
17002
+ result.push(binary);
17003
+ }
17004
+ }
17005
+ return result;
17006
+ }
16977
17007
  has(value) {
16978
17008
  var _a;
16979
17009
  const { index, mask } = this.getPosition(value);
@@ -16999,17 +17029,18 @@ class BitSet {
16999
17029
  }
17000
17030
  }
17001
17031
  getPosition(value) {
17002
- const bits = Uint8Array.BYTES_PER_ELEMENT * 8;
17003
- const remainder = value % bits;
17004
- const quotient = (value - remainder) / bits;
17005
- const index = Math.max(0, quotient - 1);
17006
- const mask = this.getMask(value);
17032
+ const remainder = value % BitSet.bitsPerElement;
17033
+ const quotient = (value - remainder) / BitSet.bitsPerElement;
17034
+ const index = quotient;
17035
+ const mask = this.getMask(remainder);
17007
17036
  return { index, mask };
17008
17037
  }
17038
+ // 输入一定是一个小于bitsPerElement的值, 取值范围是[0, bitsPerElement)
17009
17039
  getMask(value) {
17010
17040
  return Math.pow(2, value);
17011
17041
  }
17012
17042
  }
17043
+ BitSet.bitsPerElement = Uint8Array.BYTES_PER_ELEMENT * 8;
17013
17044
 
17014
17045
  export { BadEventError, BitSet, Box, DynamicTypedArray, Emitter, ExpirableMap, FiniteStateMachine, HashMap, HashSet, LRUMap, ObservableFiniteStateMachine, Queue, SortedSet, SparseMap, SparseSet, TLRUMap, TrieMap, TypedSparseMap, TypedSparseSet, convertArrayToCons, convertConsToArray };
17015
17046
  //# sourceMappingURL=index.mjs.map