@blackglory/structures 0.6.10 → 0.9.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.
Files changed (48) hide show
  1. package/README.md +64 -4
  2. package/dist/es2015/index.min.mjs +2 -2
  3. package/dist/es2015/index.min.mjs.map +1 -1
  4. package/dist/es2015/index.mjs +174 -15
  5. package/dist/es2015/index.mjs.map +1 -1
  6. package/dist/es2015/index.umd.js +176 -14
  7. package/dist/es2015/index.umd.js.map +1 -1
  8. package/dist/es2015/index.umd.min.js +2 -2
  9. package/dist/es2015/index.umd.min.js.map +1 -1
  10. package/dist/es2018/index.min.mjs +2 -2
  11. package/dist/es2018/index.min.mjs.map +1 -1
  12. package/dist/es2018/index.mjs +174 -15
  13. package/dist/es2018/index.mjs.map +1 -1
  14. package/dist/es2018/index.umd.js +176 -14
  15. package/dist/es2018/index.umd.js.map +1 -1
  16. package/dist/es2018/index.umd.min.js +2 -2
  17. package/dist/es2018/index.umd.min.js.map +1 -1
  18. package/lib/es2015/index.d.ts +3 -0
  19. package/lib/es2015/index.js +3 -0
  20. package/lib/es2015/index.js.map +1 -1
  21. package/lib/es2015/sparse-map.d.ts +13 -0
  22. package/lib/es2015/sparse-map.js +66 -0
  23. package/lib/es2015/sparse-map.js.map +1 -0
  24. package/lib/es2015/sparse-set.d.ts +3 -3
  25. package/lib/es2015/sparse-set.js +14 -15
  26. package/lib/es2015/sparse-set.js.map +1 -1
  27. package/lib/es2015/typed-sparse-map.d.ts +20 -0
  28. package/lib/es2015/typed-sparse-map.js +67 -0
  29. package/lib/es2015/typed-sparse-map.js.map +1 -0
  30. package/lib/es2015/typed-sparse-set.d.ts +15 -0
  31. package/lib/es2015/typed-sparse-set.js +39 -0
  32. package/lib/es2015/typed-sparse-set.js.map +1 -0
  33. package/lib/es2018/index.d.ts +3 -0
  34. package/lib/es2018/index.js +3 -0
  35. package/lib/es2018/index.js.map +1 -1
  36. package/lib/es2018/sparse-map.d.ts +13 -0
  37. package/lib/es2018/sparse-map.js +66 -0
  38. package/lib/es2018/sparse-map.js.map +1 -0
  39. package/lib/es2018/sparse-set.d.ts +3 -3
  40. package/lib/es2018/sparse-set.js +14 -15
  41. package/lib/es2018/sparse-set.js.map +1 -1
  42. package/lib/es2018/typed-sparse-map.d.ts +20 -0
  43. package/lib/es2018/typed-sparse-map.js +67 -0
  44. package/lib/es2018/typed-sparse-map.js.map +1 -0
  45. package/lib/es2018/typed-sparse-set.d.ts +15 -0
  46. package/lib/es2018/typed-sparse-set.js +39 -0
  47. package/lib/es2018/typed-sparse-set.js.map +1 -0
  48. package/package.json +2 -2
@@ -9649,38 +9649,101 @@
9649
9649
 
9650
9650
  class SparseSet {
9651
9651
  constructor() {
9652
- this.values = [];
9653
- this.valueToValueIndex = [];
9652
+ this.indexToValue = [];
9653
+ this.valueToIndex = [];
9654
9654
  }
9655
9655
  get [Symbol.toStringTag]() {
9656
9656
  return this.constructor.name;
9657
9657
  }
9658
9658
  [Symbol.iterator]() {
9659
- return this.values[Symbol.iterator]();
9659
+ return this.indexToValue[Symbol.iterator]();
9660
9660
  }
9661
9661
  has(value) {
9662
9662
  // 跟一般的实现不同, 不需要访问values数组.
9663
- return es2018$e.isntUndefined(this.valueToValueIndex[value]);
9663
+ return value in this.valueToIndex;
9664
9664
  }
9665
9665
  add(value) {
9666
9666
  if (!this.has(value)) {
9667
- const index = this.values.length;
9668
- this.values.push(value);
9669
- this.valueToValueIndex[value] = index;
9667
+ const index = this.indexToValue.length;
9668
+ this.indexToValue.push(value);
9669
+ this.valueToIndex[value] = index;
9670
9670
  }
9671
9671
  }
9672
- remove(value) {
9672
+ delete(value) {
9673
9673
  if (this.has(value)) {
9674
- const lastValue = this.values.pop();
9674
+ const lastValue = this.indexToValue.pop();
9675
9675
  if (value === lastValue) {
9676
- this.valueToValueIndex[value] = undefined;
9676
+ delete this.valueToIndex[value];
9677
9677
  }
9678
9678
  else {
9679
- const indexOfValue = this.valueToValueIndex[value];
9680
- this.values[indexOfValue] = lastValue;
9681
- this.valueToValueIndex[lastValue] = indexOfValue;
9679
+ const index = this.valueToIndex[value];
9680
+ this.indexToValue[index] = lastValue;
9681
+ this.valueToIndex[lastValue] = index;
9682
9682
  // 跟一般的实现不同, 直接删除值的索引.
9683
- this.valueToValueIndex[value] = undefined;
9683
+ delete this.valueToIndex[value];
9684
+ }
9685
+ }
9686
+ }
9687
+ }
9688
+
9689
+ class SparseMap {
9690
+ constructor() {
9691
+ this.keyToIndex = [];
9692
+ this.indexToKey = [];
9693
+ this.indexToValue = [];
9694
+ }
9695
+ get [Symbol.toStringTag]() {
9696
+ return this.constructor.name;
9697
+ }
9698
+ *entries() {
9699
+ for (let i = 0; i < this.indexToKey.length; i++) {
9700
+ yield [this.indexToKey[i], this.indexToValue[i]];
9701
+ }
9702
+ }
9703
+ keys() {
9704
+ return this.indexToKey.values();
9705
+ }
9706
+ values() {
9707
+ return this.indexToValue.values();
9708
+ }
9709
+ has(key) {
9710
+ // 跟一般的稀疏集实现不同, 不需要访问values数组.
9711
+ return key in this.keyToIndex;
9712
+ }
9713
+ get(key) {
9714
+ if (this.has(key)) {
9715
+ const index = this.keyToIndex[key];
9716
+ return this.indexToValue[index];
9717
+ }
9718
+ else {
9719
+ return undefined;
9720
+ }
9721
+ }
9722
+ set(key, value) {
9723
+ if (this.has(key)) {
9724
+ const index = this.keyToIndex[key];
9725
+ this.indexToValue[index] = value;
9726
+ }
9727
+ else {
9728
+ const index = this.indexToKey.length;
9729
+ this.indexToKey.push(key);
9730
+ this.indexToValue.push(value);
9731
+ this.keyToIndex[key] = index;
9732
+ }
9733
+ }
9734
+ delete(key) {
9735
+ if (this.has(key)) {
9736
+ const lastKey = this.indexToKey.pop();
9737
+ const lastValue = this.indexToValue.pop();
9738
+ if (key === lastKey) {
9739
+ delete this.keyToIndex[key];
9740
+ }
9741
+ else {
9742
+ const index = this.keyToIndex[key];
9743
+ this.indexToKey[index] = lastKey;
9744
+ this.indexToValue[index] = lastValue;
9745
+ this.keyToIndex[key] = index;
9746
+ delete this.keyToIndex[key];
9684
9747
  }
9685
9748
  }
9686
9749
  }
@@ -9806,6 +9869,102 @@
9806
9869
  }
9807
9870
  }
9808
9871
 
9872
+ class TypedSparseMap {
9873
+ constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
9874
+ this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
9875
+ this.keyToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
9876
+ this.indexToKey = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
9877
+ }
9878
+ get [Symbol.toStringTag]() {
9879
+ return this.constructor.name;
9880
+ }
9881
+ *entries() {
9882
+ for (let i = 0; i < this.indexToKey.length; i++) {
9883
+ yield [
9884
+ this.indexToKey.internalTypedArray[i],
9885
+ this.indexToValue.internalTypedArray[i]
9886
+ ];
9887
+ }
9888
+ }
9889
+ keys() {
9890
+ return this.indexToKey.internalTypedArray.values();
9891
+ }
9892
+ values() {
9893
+ return this.indexToValue.internalTypedArray.values();
9894
+ }
9895
+ has(key) {
9896
+ const index = this.keyToIndex.internalTypedArray[key];
9897
+ return this.indexToKey.internalTypedArray[index] === key;
9898
+ }
9899
+ get(key) {
9900
+ const index = this.keyToIndex.internalTypedArray[key];
9901
+ if (this.indexToKey.internalTypedArray[index] === key) {
9902
+ return this.indexToValue.internalTypedArray[index];
9903
+ }
9904
+ else {
9905
+ return undefined;
9906
+ }
9907
+ }
9908
+ set(key, value) {
9909
+ const index = this.keyToIndex.internalTypedArray[key];
9910
+ if (this.indexToKey.internalTypedArray[index] === key) {
9911
+ this.indexToValue.internalTypedArray[index] = value;
9912
+ }
9913
+ else {
9914
+ const index = this.indexToKey.length;
9915
+ this.indexToKey.push(key);
9916
+ this.indexToValue.push(value);
9917
+ this.keyToIndex.set(key, index);
9918
+ }
9919
+ }
9920
+ delete(key) {
9921
+ const index = this.keyToIndex.internalTypedArray[key];
9922
+ if (this.indexToKey.internalTypedArray[index] === key) {
9923
+ const lastKey = this.indexToKey.pop();
9924
+ const lastValue = this.indexToValue.pop();
9925
+ if (key !== lastKey) {
9926
+ this.indexToKey.internalTypedArray[index] = lastKey;
9927
+ this.indexToValue.internalTypedArray[index] = lastValue;
9928
+ this.keyToIndex.internalTypedArray[lastKey] = index;
9929
+ }
9930
+ }
9931
+ }
9932
+ }
9933
+
9934
+ class TypedSparseSet {
9935
+ constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
9936
+ this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
9937
+ this.valueToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
9938
+ }
9939
+ get [Symbol.toStringTag]() {
9940
+ return this.constructor.name;
9941
+ }
9942
+ [Symbol.iterator]() {
9943
+ return this.indexToValue.internalTypedArray[Symbol.iterator]();
9944
+ }
9945
+ has(value) {
9946
+ const index = this.valueToIndex.internalTypedArray[value];
9947
+ return this.indexToValue.internalTypedArray[index] === value;
9948
+ }
9949
+ add(value) {
9950
+ if (!this.has(value)) {
9951
+ const index = this.indexToValue.length;
9952
+ this.indexToValue.push(value);
9953
+ this.valueToIndex.set(value, index);
9954
+ }
9955
+ }
9956
+ delete(value) {
9957
+ const index = this.valueToIndex.internalTypedArray[value];
9958
+ if (this.indexToValue.internalTypedArray[index] === value) {
9959
+ const lastValue = this.indexToValue.pop();
9960
+ if (value !== lastValue) {
9961
+ this.indexToValue.internalTypedArray[index] = lastValue;
9962
+ this.valueToIndex.internalTypedArray[lastValue] = index;
9963
+ }
9964
+ }
9965
+ }
9966
+ }
9967
+
9809
9968
  exports.BadEventError = BadEventError;
9810
9969
  exports.Box = Box;
9811
9970
  exports.DynamicTypedArray = DynamicTypedArray;
@@ -9817,9 +9976,12 @@
9817
9976
  exports.LRUMap = LRUMap;
9818
9977
  exports.ObservableFiniteStateMachine = ObservableFiniteStateMachine;
9819
9978
  exports.Queue = Queue;
9979
+ exports.SparseMap = SparseMap;
9820
9980
  exports.SparseSet = SparseSet;
9821
9981
  exports.TLRUMap = TLRUMap;
9822
9982
  exports.TrieMap = TrieMap;
9983
+ exports.TypedSparseMap = TypedSparseMap;
9984
+ exports.TypedSparseSet = TypedSparseSet;
9823
9985
  exports.convertArrayToCons = convertArrayToCons;
9824
9986
  exports.convertConsToArray = convertConsToArray;
9825
9987