@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.
- package/README.md +64 -4
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +174 -15
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +176 -14
- package/dist/es2015/index.umd.js.map +1 -1
- package/dist/es2015/index.umd.min.js +2 -2
- package/dist/es2015/index.umd.min.js.map +1 -1
- package/dist/es2018/index.min.mjs +2 -2
- package/dist/es2018/index.min.mjs.map +1 -1
- package/dist/es2018/index.mjs +174 -15
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +176 -14
- package/dist/es2018/index.umd.js.map +1 -1
- package/dist/es2018/index.umd.min.js +2 -2
- package/dist/es2018/index.umd.min.js.map +1 -1
- package/lib/es2015/index.d.ts +3 -0
- package/lib/es2015/index.js +3 -0
- package/lib/es2015/index.js.map +1 -1
- package/lib/es2015/sparse-map.d.ts +13 -0
- package/lib/es2015/sparse-map.js +66 -0
- package/lib/es2015/sparse-map.js.map +1 -0
- package/lib/es2015/sparse-set.d.ts +3 -3
- package/lib/es2015/sparse-set.js +14 -15
- package/lib/es2015/sparse-set.js.map +1 -1
- package/lib/es2015/typed-sparse-map.d.ts +20 -0
- package/lib/es2015/typed-sparse-map.js +67 -0
- package/lib/es2015/typed-sparse-map.js.map +1 -0
- package/lib/es2015/typed-sparse-set.d.ts +15 -0
- package/lib/es2015/typed-sparse-set.js +39 -0
- package/lib/es2015/typed-sparse-set.js.map +1 -0
- package/lib/es2018/index.d.ts +3 -0
- package/lib/es2018/index.js +3 -0
- package/lib/es2018/index.js.map +1 -1
- package/lib/es2018/sparse-map.d.ts +13 -0
- package/lib/es2018/sparse-map.js +66 -0
- package/lib/es2018/sparse-map.js.map +1 -0
- package/lib/es2018/sparse-set.d.ts +3 -3
- package/lib/es2018/sparse-set.js +14 -15
- package/lib/es2018/sparse-set.js.map +1 -1
- package/lib/es2018/typed-sparse-map.d.ts +20 -0
- package/lib/es2018/typed-sparse-map.js +67 -0
- package/lib/es2018/typed-sparse-map.js.map +1 -0
- package/lib/es2018/typed-sparse-set.d.ts +15 -0
- package/lib/es2018/typed-sparse-set.js +39 -0
- package/lib/es2018/typed-sparse-set.js.map +1 -0
- package/package.json +2 -2
package/dist/es2018/index.mjs
CHANGED
|
@@ -9643,38 +9643,101 @@ class ObservableFiniteStateMachine extends FiniteStateMachine {
|
|
|
9643
9643
|
|
|
9644
9644
|
class SparseSet {
|
|
9645
9645
|
constructor() {
|
|
9646
|
-
this.
|
|
9647
|
-
this.
|
|
9646
|
+
this.indexToValue = [];
|
|
9647
|
+
this.valueToIndex = [];
|
|
9648
9648
|
}
|
|
9649
9649
|
get [Symbol.toStringTag]() {
|
|
9650
9650
|
return this.constructor.name;
|
|
9651
9651
|
}
|
|
9652
9652
|
[Symbol.iterator]() {
|
|
9653
|
-
return this.
|
|
9653
|
+
return this.indexToValue[Symbol.iterator]();
|
|
9654
9654
|
}
|
|
9655
9655
|
has(value) {
|
|
9656
9656
|
// 跟一般的实现不同, 不需要访问values数组.
|
|
9657
|
-
return
|
|
9657
|
+
return value in this.valueToIndex;
|
|
9658
9658
|
}
|
|
9659
9659
|
add(value) {
|
|
9660
9660
|
if (!this.has(value)) {
|
|
9661
|
-
const index = this.
|
|
9662
|
-
this.
|
|
9663
|
-
this.
|
|
9661
|
+
const index = this.indexToValue.length;
|
|
9662
|
+
this.indexToValue.push(value);
|
|
9663
|
+
this.valueToIndex[value] = index;
|
|
9664
9664
|
}
|
|
9665
9665
|
}
|
|
9666
|
-
|
|
9666
|
+
delete(value) {
|
|
9667
9667
|
if (this.has(value)) {
|
|
9668
|
-
const lastValue = this.
|
|
9668
|
+
const lastValue = this.indexToValue.pop();
|
|
9669
9669
|
if (value === lastValue) {
|
|
9670
|
-
this.
|
|
9670
|
+
delete this.valueToIndex[value];
|
|
9671
9671
|
}
|
|
9672
9672
|
else {
|
|
9673
|
-
const
|
|
9674
|
-
this.
|
|
9675
|
-
this.
|
|
9673
|
+
const index = this.valueToIndex[value];
|
|
9674
|
+
this.indexToValue[index] = lastValue;
|
|
9675
|
+
this.valueToIndex[lastValue] = index;
|
|
9676
9676
|
// 跟一般的实现不同, 直接删除值的索引.
|
|
9677
|
-
this.
|
|
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];
|
|
9678
9741
|
}
|
|
9679
9742
|
}
|
|
9680
9743
|
}
|
|
@@ -9800,5 +9863,101 @@ function computeNewCapacity(oldCapacity, targetLength, growthFactor) {
|
|
|
9800
9863
|
}
|
|
9801
9864
|
}
|
|
9802
9865
|
|
|
9803
|
-
|
|
9866
|
+
class TypedSparseMap {
|
|
9867
|
+
constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
|
|
9868
|
+
this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
|
|
9869
|
+
this.keyToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
|
|
9870
|
+
this.indexToKey = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
|
|
9871
|
+
}
|
|
9872
|
+
get [Symbol.toStringTag]() {
|
|
9873
|
+
return this.constructor.name;
|
|
9874
|
+
}
|
|
9875
|
+
*entries() {
|
|
9876
|
+
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
9877
|
+
yield [
|
|
9878
|
+
this.indexToKey.internalTypedArray[i],
|
|
9879
|
+
this.indexToValue.internalTypedArray[i]
|
|
9880
|
+
];
|
|
9881
|
+
}
|
|
9882
|
+
}
|
|
9883
|
+
keys() {
|
|
9884
|
+
return this.indexToKey.internalTypedArray.values();
|
|
9885
|
+
}
|
|
9886
|
+
values() {
|
|
9887
|
+
return this.indexToValue.internalTypedArray.values();
|
|
9888
|
+
}
|
|
9889
|
+
has(key) {
|
|
9890
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9891
|
+
return this.indexToKey.internalTypedArray[index] === key;
|
|
9892
|
+
}
|
|
9893
|
+
get(key) {
|
|
9894
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9895
|
+
if (this.indexToKey.internalTypedArray[index] === key) {
|
|
9896
|
+
return this.indexToValue.internalTypedArray[index];
|
|
9897
|
+
}
|
|
9898
|
+
else {
|
|
9899
|
+
return undefined;
|
|
9900
|
+
}
|
|
9901
|
+
}
|
|
9902
|
+
set(key, value) {
|
|
9903
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9904
|
+
if (this.indexToKey.internalTypedArray[index] === key) {
|
|
9905
|
+
this.indexToValue.internalTypedArray[index] = value;
|
|
9906
|
+
}
|
|
9907
|
+
else {
|
|
9908
|
+
const index = this.indexToKey.length;
|
|
9909
|
+
this.indexToKey.push(key);
|
|
9910
|
+
this.indexToValue.push(value);
|
|
9911
|
+
this.keyToIndex.set(key, index);
|
|
9912
|
+
}
|
|
9913
|
+
}
|
|
9914
|
+
delete(key) {
|
|
9915
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9916
|
+
if (this.indexToKey.internalTypedArray[index] === key) {
|
|
9917
|
+
const lastKey = this.indexToKey.pop();
|
|
9918
|
+
const lastValue = this.indexToValue.pop();
|
|
9919
|
+
if (key !== lastKey) {
|
|
9920
|
+
this.indexToKey.internalTypedArray[index] = lastKey;
|
|
9921
|
+
this.indexToValue.internalTypedArray[index] = lastValue;
|
|
9922
|
+
this.keyToIndex.internalTypedArray[lastKey] = index;
|
|
9923
|
+
}
|
|
9924
|
+
}
|
|
9925
|
+
}
|
|
9926
|
+
}
|
|
9927
|
+
|
|
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 };
|
|
9804
9963
|
//# sourceMappingURL=index.mjs.map
|