@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
@@ -9641,6 +9641,108 @@ class ObservableFiniteStateMachine extends FiniteStateMachine {
9641
9641
  }
9642
9642
  }
9643
9643
 
9644
+ class SparseSet {
9645
+ constructor() {
9646
+ this.indexToValue = [];
9647
+ this.valueToIndex = [];
9648
+ }
9649
+ get [Symbol.toStringTag]() {
9650
+ return this.constructor.name;
9651
+ }
9652
+ [Symbol.iterator]() {
9653
+ return this.indexToValue[Symbol.iterator]();
9654
+ }
9655
+ has(value) {
9656
+ // 跟一般的实现不同, 不需要访问values数组.
9657
+ return value in this.valueToIndex;
9658
+ }
9659
+ add(value) {
9660
+ if (!this.has(value)) {
9661
+ const index = this.indexToValue.length;
9662
+ this.indexToValue.push(value);
9663
+ this.valueToIndex[value] = index;
9664
+ }
9665
+ }
9666
+ delete(value) {
9667
+ if (this.has(value)) {
9668
+ const lastValue = this.indexToValue.pop();
9669
+ if (value === lastValue) {
9670
+ delete this.valueToIndex[value];
9671
+ }
9672
+ else {
9673
+ const index = this.valueToIndex[value];
9674
+ this.indexToValue[index] = lastValue;
9675
+ this.valueToIndex[lastValue] = index;
9676
+ // 跟一般的实现不同, 直接删除值的索引.
9677
+ delete this.valueToIndex[value];
9678
+ }
9679
+ }
9680
+ }
9681
+ }
9682
+
9683
+ class SparseMap {
9684
+ constructor() {
9685
+ this.keyToIndex = [];
9686
+ this.indexToKey = [];
9687
+ this.indexToValue = [];
9688
+ }
9689
+ get [Symbol.toStringTag]() {
9690
+ return this.constructor.name;
9691
+ }
9692
+ *entries() {
9693
+ for (let i = 0; i < this.indexToKey.length; i++) {
9694
+ yield [this.indexToKey[i], this.indexToValue[i]];
9695
+ }
9696
+ }
9697
+ keys() {
9698
+ return this.indexToKey.values();
9699
+ }
9700
+ values() {
9701
+ return this.indexToValue.values();
9702
+ }
9703
+ has(key) {
9704
+ // 跟一般的稀疏集实现不同, 不需要访问values数组.
9705
+ return key in this.keyToIndex;
9706
+ }
9707
+ get(key) {
9708
+ if (this.has(key)) {
9709
+ const index = this.keyToIndex[key];
9710
+ return this.indexToValue[index];
9711
+ }
9712
+ else {
9713
+ return undefined;
9714
+ }
9715
+ }
9716
+ set(key, value) {
9717
+ if (this.has(key)) {
9718
+ const index = this.keyToIndex[key];
9719
+ this.indexToValue[index] = value;
9720
+ }
9721
+ else {
9722
+ const index = this.indexToKey.length;
9723
+ this.indexToKey.push(key);
9724
+ this.indexToValue.push(value);
9725
+ this.keyToIndex[key] = index;
9726
+ }
9727
+ }
9728
+ delete(key) {
9729
+ if (this.has(key)) {
9730
+ const lastKey = this.indexToKey.pop();
9731
+ const lastValue = this.indexToValue.pop();
9732
+ if (key === lastKey) {
9733
+ delete this.keyToIndex[key];
9734
+ }
9735
+ else {
9736
+ const index = this.keyToIndex[key];
9737
+ this.indexToKey[index] = lastKey;
9738
+ this.indexToValue[index] = lastValue;
9739
+ this.keyToIndex[key] = index;
9740
+ delete this.keyToIndex[key];
9741
+ }
9742
+ }
9743
+ }
9744
+ }
9745
+
9644
9746
  // 相关提案: https://github.com/tc39/proposal-resizablearraybuffer
9645
9747
  class DynamicTypedArray {
9646
9748
  constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
@@ -9761,41 +9863,7 @@ function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
9761
9863
  }
9762
9864
  }
9763
9865
 
9764
- class SparseSet {
9765
- constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
9766
- this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
9767
- this.valueToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
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 {
9866
+ class TypedSparseMap {
9799
9867
  constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
9800
9868
  this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
9801
9869
  this.keyToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
@@ -9857,5 +9925,39 @@ class SparseMap {
9857
9925
  }
9858
9926
  }
9859
9927
 
9860
- export { BadEventError, Box, DynamicTypedArray, Emitter, ExpirableMap, FiniteStateMachine, HashMap, HashSet, LRUMap, ObservableFiniteStateMachine, Queue, SparseMap, SparseSet, TLRUMap, TrieMap, convertArrayToCons, convertConsToArray };
9928
+ class TypedSparseSet {
9929
+ constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
9930
+ this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
9931
+ this.valueToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
9932
+ }
9933
+ get [Symbol.toStringTag]() {
9934
+ return this.constructor.name;
9935
+ }
9936
+ [Symbol.iterator]() {
9937
+ return this.indexToValue.internalTypedArray[Symbol.iterator]();
9938
+ }
9939
+ has(value) {
9940
+ const index = this.valueToIndex.internalTypedArray[value];
9941
+ return this.indexToValue.internalTypedArray[index] === value;
9942
+ }
9943
+ add(value) {
9944
+ if (!this.has(value)) {
9945
+ const index = this.indexToValue.length;
9946
+ this.indexToValue.push(value);
9947
+ this.valueToIndex.set(value, index);
9948
+ }
9949
+ }
9950
+ delete(value) {
9951
+ const index = this.valueToIndex.internalTypedArray[value];
9952
+ if (this.indexToValue.internalTypedArray[index] === value) {
9953
+ const lastValue = this.indexToValue.pop();
9954
+ if (value !== lastValue) {
9955
+ this.indexToValue.internalTypedArray[index] = lastValue;
9956
+ this.valueToIndex.internalTypedArray[lastValue] = index;
9957
+ }
9958
+ }
9959
+ }
9960
+ }
9961
+
9962
+ export { BadEventError, Box, DynamicTypedArray, Emitter, ExpirableMap, FiniteStateMachine, HashMap, HashSet, LRUMap, ObservableFiniteStateMachine, Queue, SparseMap, SparseSet, TLRUMap, TrieMap, TypedSparseMap, TypedSparseSet, convertArrayToCons, convertConsToArray };
9861
9963
  //# sourceMappingURL=index.mjs.map