@blackglory/structures 0.6.9 → 0.8.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 +36 -4
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +97 -39
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +97 -38
- 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 +97 -39
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +97 -38
- 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 +1 -0
- package/lib/es2015/index.js +1 -0
- package/lib/es2015/index.js.map +1 -1
- package/lib/es2015/sparse-map.d.ts +20 -0
- package/lib/es2015/sparse-map.js +67 -0
- package/lib/es2015/sparse-map.js.map +1 -0
- package/lib/es2015/sparse-set.d.ts +10 -4
- package/lib/es2015/sparse-set.js +17 -19
- package/lib/es2015/sparse-set.js.map +1 -1
- package/lib/es2018/index.d.ts +1 -0
- package/lib/es2018/index.js +1 -0
- package/lib/es2018/index.js.map +1 -1
- package/lib/es2018/sparse-map.d.ts +20 -0
- package/lib/es2018/sparse-map.js +67 -0
- package/lib/es2018/sparse-map.js.map +1 -0
- package/lib/es2018/sparse-set.d.ts +10 -4
- package/lib/es2018/sparse-set.js +17 -19
- package/lib/es2018/sparse-set.js.map +1 -1
- package/package.json +2 -2
package/dist/es2018/index.mjs
CHANGED
|
@@ -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
|
-
// 跟一般的实现不同, 不需要访问values数组.
|
|
9659
|
-
return es2018$e.isntUndefined(this.valueToValueIndex[value]);
|
|
9660
|
-
}
|
|
9661
|
-
add(value) {
|
|
9662
|
-
if (!this.has(value)) {
|
|
9663
|
-
const index = this.values.length;
|
|
9664
|
-
this.values.push(value);
|
|
9665
|
-
this.valueToValueIndex[value] = index;
|
|
9666
|
-
}
|
|
9667
|
-
}
|
|
9668
|
-
remove(value) {
|
|
9669
|
-
if (this.has(value)) {
|
|
9670
|
-
const lastValue = this.values.pop();
|
|
9671
|
-
if (value !== lastValue) {
|
|
9672
|
-
const indexOfValue = this.valueToValueIndex[value];
|
|
9673
|
-
this.values[indexOfValue] = lastValue;
|
|
9674
|
-
this.valueToValueIndex[lastValue] = indexOfValue;
|
|
9675
|
-
// 跟一般的实现不同, 直接删除值的索引.
|
|
9676
|
-
this.valueToValueIndex[value] = undefined;
|
|
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
|
-
|
|
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 {
|
|
9799
|
+
constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
|
|
9800
|
+
this.indexToValue = new DynamicTypedArray(typedArrayConstructor, { capacity, growthFactor });
|
|
9801
|
+
this.keyToIndex = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
|
|
9802
|
+
this.indexToKey = new DynamicTypedArray(Uint32Array, { capacity, growthFactor });
|
|
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
|