@blackglory/structures 0.8.0 → 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 +31 -3
  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 +138 -36
  5. package/dist/es2015/index.mjs.map +1 -1
  6. package/dist/es2015/index.umd.js +139 -35
  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 +138 -36
  13. package/dist/es2018/index.mjs.map +1 -1
  14. package/dist/es2018/index.umd.js +139 -35
  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 +2 -0
  19. package/lib/es2015/index.js +2 -0
  20. package/lib/es2015/index.js.map +1 -1
  21. package/lib/es2015/sparse-map.d.ts +5 -12
  22. package/lib/es2015/sparse-map.js +25 -26
  23. package/lib/es2015/sparse-map.js.map +1 -1
  24. package/lib/es2015/sparse-set.d.ts +2 -8
  25. package/lib/es2015/sparse-set.js +15 -13
  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 +2 -0
  34. package/lib/es2018/index.js +2 -0
  35. package/lib/es2018/index.js.map +1 -1
  36. package/lib/es2018/sparse-map.d.ts +5 -12
  37. package/lib/es2018/sparse-map.js +25 -26
  38. package/lib/es2018/sparse-map.js.map +1 -1
  39. package/lib/es2018/sparse-set.d.ts +2 -8
  40. package/lib/es2018/sparse-set.js +15 -13
  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 +1 -1
@@ -9647,6 +9647,108 @@
9647
9647
  }
9648
9648
  }
9649
9649
 
9650
+ class SparseSet {
9651
+ constructor() {
9652
+ this.indexToValue = [];
9653
+ this.valueToIndex = [];
9654
+ }
9655
+ get [Symbol.toStringTag]() {
9656
+ return this.constructor.name;
9657
+ }
9658
+ [Symbol.iterator]() {
9659
+ return this.indexToValue[Symbol.iterator]();
9660
+ }
9661
+ has(value) {
9662
+ // 跟一般的实现不同, 不需要访问values数组.
9663
+ return value in this.valueToIndex;
9664
+ }
9665
+ add(value) {
9666
+ if (!this.has(value)) {
9667
+ const index = this.indexToValue.length;
9668
+ this.indexToValue.push(value);
9669
+ this.valueToIndex[value] = index;
9670
+ }
9671
+ }
9672
+ delete(value) {
9673
+ if (this.has(value)) {
9674
+ const lastValue = this.indexToValue.pop();
9675
+ if (value === lastValue) {
9676
+ delete this.valueToIndex[value];
9677
+ }
9678
+ else {
9679
+ const index = this.valueToIndex[value];
9680
+ this.indexToValue[index] = lastValue;
9681
+ this.valueToIndex[lastValue] = index;
9682
+ // 跟一般的实现不同, 直接删除值的索引.
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];
9747
+ }
9748
+ }
9749
+ }
9750
+ }
9751
+
9650
9752
  // 相关提案: https://github.com/tc39/proposal-resizablearraybuffer
9651
9753
  class DynamicTypedArray {
9652
9754
  constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
@@ -9767,41 +9869,7 @@
9767
9869
  }
9768
9870
  }
9769
9871
 
9770
- class SparseSet {
9771
- constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
9772
- this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
9773
- this.valueToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
9774
- }
9775
- get [Symbol.toStringTag]() {
9776
- return this.constructor.name;
9777
- }
9778
- [Symbol.iterator]() {
9779
- return this.indexToValue.internalTypedArray[Symbol.iterator]();
9780
- }
9781
- has(value) {
9782
- const index = this.valueToIndex.internalTypedArray[value];
9783
- return this.indexToValue.internalTypedArray[index] === value;
9784
- }
9785
- add(value) {
9786
- if (!this.has(value)) {
9787
- const index = this.indexToValue.length;
9788
- this.indexToValue.push(value);
9789
- this.valueToIndex.set(value, index);
9790
- }
9791
- }
9792
- delete(value) {
9793
- const index = this.valueToIndex.internalTypedArray[value];
9794
- if (this.indexToValue.internalTypedArray[index] === value) {
9795
- const lastValue = this.indexToValue.pop();
9796
- if (value !== lastValue) {
9797
- this.indexToValue.internalTypedArray[index] = lastValue;
9798
- this.valueToIndex.internalTypedArray[lastValue] = index;
9799
- }
9800
- }
9801
- }
9802
- }
9803
-
9804
- class SparseMap {
9872
+ class TypedSparseMap {
9805
9873
  constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
9806
9874
  this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
9807
9875
  this.keyToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
@@ -9863,6 +9931,40 @@
9863
9931
  }
9864
9932
  }
9865
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
+
9866
9968
  exports.BadEventError = BadEventError;
9867
9969
  exports.Box = Box;
9868
9970
  exports.DynamicTypedArray = DynamicTypedArray;
@@ -9878,6 +9980,8 @@
9878
9980
  exports.SparseSet = SparseSet;
9879
9981
  exports.TLRUMap = TLRUMap;
9880
9982
  exports.TrieMap = TrieMap;
9983
+ exports.TypedSparseMap = TypedSparseMap;
9984
+ exports.TypedSparseSet = TypedSparseSet;
9881
9985
  exports.convertArrayToCons = convertArrayToCons;
9882
9986
  exports.convertConsToArray = convertConsToArray;
9883
9987