@blackglory/structures 0.6.8 → 0.7.0

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.
@@ -9641,44 +9641,6 @@ class ObservableFiniteStateMachine extends FiniteStateMachine {
9641
9641
  }
9642
9642
  }
9643
9643
 
9644
- class SparseSet {
9645
- constructor() {
9646
- this.values = [];
9647
- this.valueToValueIndex = [];
9648
- }
9649
- get [Symbol.toStringTag]() {
9650
- return this.constructor.name;
9651
- }
9652
- *[Symbol.iterator]() {
9653
- for (const value of this.values) {
9654
- yield value;
9655
- }
9656
- }
9657
- has(value) {
9658
- const index = this.valueToValueIndex[value];
9659
- return es2018$e.isUndefined(index)
9660
- ? false
9661
- : this.values[index] === value;
9662
- }
9663
- add(value) {
9664
- if (!this.has(value)) {
9665
- const index = this.values.length;
9666
- this.values.push(value);
9667
- this.valueToValueIndex[value] = index;
9668
- }
9669
- }
9670
- remove(value) {
9671
- if (this.has(value)) {
9672
- const lastValue = this.values.pop();
9673
- if (value !== lastValue) {
9674
- const indexOfValue = this.valueToValueIndex[value];
9675
- this.values[indexOfValue] = lastValue;
9676
- this.valueToValueIndex[lastValue] = indexOfValue;
9677
- }
9678
- }
9679
- }
9680
- }
9681
-
9682
9644
  // 相关提案: https://github.com/tc39/proposal-resizablearraybuffer
9683
9645
  class DynamicTypedArray {
9684
9646
  constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
@@ -9799,5 +9761,101 @@ function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
9799
9761
  }
9800
9762
  }
9801
9763
 
9802
- export { BadEventError, Box, DynamicTypedArray, Emitter, ExpirableMap, FiniteStateMachine, HashMap, HashSet, LRUMap, ObservableFiniteStateMachine, Queue, SparseSet, TLRUMap, TrieMap, convertArrayToCons, convertConsToArray };
9764
+ class SparseSet {
9765
+ constructor() {
9766
+ this.indexToValue = new DynamicTypedArray(Uint32Array);
9767
+ this.valueToIndex = new DynamicTypedArray(Uint32Array);
9768
+ }
9769
+ get [Symbol.toStringTag]() {
9770
+ return this.constructor.name;
9771
+ }
9772
+ [Symbol.iterator]() {
9773
+ return this.indexToValue.internalTypedArray[Symbol.iterator]();
9774
+ }
9775
+ has(value) {
9776
+ const index = this.valueToIndex.internalTypedArray[value];
9777
+ return this.indexToValue.internalTypedArray[index] === value;
9778
+ }
9779
+ add(value) {
9780
+ if (!this.has(value)) {
9781
+ const index = this.indexToValue.length;
9782
+ this.indexToValue.push(value);
9783
+ this.valueToIndex.set(value, index);
9784
+ }
9785
+ }
9786
+ delete(value) {
9787
+ const index = this.valueToIndex.internalTypedArray[value];
9788
+ if (this.indexToValue.internalTypedArray[index] === value) {
9789
+ const lastValue = this.indexToValue.pop();
9790
+ if (value !== lastValue) {
9791
+ this.indexToValue.internalTypedArray[index] = lastValue;
9792
+ this.valueToIndex.internalTypedArray[lastValue] = index;
9793
+ }
9794
+ }
9795
+ }
9796
+ }
9797
+
9798
+ class SparseMap {
9799
+ constructor() {
9800
+ this.keyToIndex = new DynamicTypedArray(Uint32Array);
9801
+ this.indexToKey = new DynamicTypedArray(Uint32Array);
9802
+ this.indexToValue = new DynamicTypedArray(Uint32Array);
9803
+ }
9804
+ get [Symbol.toStringTag]() {
9805
+ return this.constructor.name;
9806
+ }
9807
+ *entries() {
9808
+ for (let i = 0; i < this.indexToKey.length; i++) {
9809
+ yield [
9810
+ this.indexToKey.internalTypedArray[i],
9811
+ this.indexToValue.internalTypedArray[i]
9812
+ ];
9813
+ }
9814
+ }
9815
+ keys() {
9816
+ return this.indexToKey.internalTypedArray.values();
9817
+ }
9818
+ values() {
9819
+ return this.indexToValue.internalTypedArray.values();
9820
+ }
9821
+ has(key) {
9822
+ const index = this.keyToIndex.internalTypedArray[key];
9823
+ return this.indexToKey.internalTypedArray[index] === key;
9824
+ }
9825
+ get(key) {
9826
+ const index = this.keyToIndex.internalTypedArray[key];
9827
+ if (this.indexToKey.internalTypedArray[index] === key) {
9828
+ return this.indexToValue.internalTypedArray[index];
9829
+ }
9830
+ else {
9831
+ return undefined;
9832
+ }
9833
+ }
9834
+ set(key, value) {
9835
+ const index = this.keyToIndex.internalTypedArray[key];
9836
+ if (this.indexToKey.internalTypedArray[index] === key) {
9837
+ this.indexToValue.internalTypedArray[index] = value;
9838
+ }
9839
+ else {
9840
+ const index = this.indexToKey.length;
9841
+ this.indexToKey.push(key);
9842
+ this.indexToValue.push(value);
9843
+ this.keyToIndex.set(key, index);
9844
+ }
9845
+ }
9846
+ delete(key) {
9847
+ const index = this.keyToIndex.internalTypedArray[key];
9848
+ if (this.indexToKey.internalTypedArray[index] === key) {
9849
+ const lastKey = this.indexToKey.pop();
9850
+ const lastValue = this.indexToValue.pop();
9851
+ if (key !== lastKey) {
9852
+ this.indexToKey.internalTypedArray[index] = lastKey;
9853
+ this.indexToValue.internalTypedArray[index] = lastValue;
9854
+ this.keyToIndex.internalTypedArray[lastKey] = index;
9855
+ }
9856
+ }
9857
+ }
9858
+ }
9859
+
9860
+ export { BadEventError, Box, DynamicTypedArray, Emitter, ExpirableMap, FiniteStateMachine, HashMap, HashSet, LRUMap, ObservableFiniteStateMachine, Queue, SparseMap, SparseSet, TLRUMap, TrieMap, convertArrayToCons, convertConsToArray };
9803
9861
  //# sourceMappingURL=index.mjs.map