@blackglory/structures 0.6.10 → 0.7.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 +17 -1
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +97 -40
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +97 -39
- 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 -40
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +97 -39
- 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 +13 -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 +3 -3
- package/lib/es2015/sparse-set.js +16 -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 +13 -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 +3 -3
- package/lib/es2018/sparse-set.js +16 -19
- package/lib/es2018/sparse-set.js.map +1 -1
- package/package.json +1 -1
package/dist/es2018/index.umd.js
CHANGED
|
@@ -9647,45 +9647,6 @@
|
|
|
9647
9647
|
}
|
|
9648
9648
|
}
|
|
9649
9649
|
|
|
9650
|
-
class SparseSet {
|
|
9651
|
-
constructor() {
|
|
9652
|
-
this.values = [];
|
|
9653
|
-
this.valueToValueIndex = [];
|
|
9654
|
-
}
|
|
9655
|
-
get [Symbol.toStringTag]() {
|
|
9656
|
-
return this.constructor.name;
|
|
9657
|
-
}
|
|
9658
|
-
[Symbol.iterator]() {
|
|
9659
|
-
return this.values[Symbol.iterator]();
|
|
9660
|
-
}
|
|
9661
|
-
has(value) {
|
|
9662
|
-
// 跟一般的实现不同, 不需要访问values数组.
|
|
9663
|
-
return es2018$e.isntUndefined(this.valueToValueIndex[value]);
|
|
9664
|
-
}
|
|
9665
|
-
add(value) {
|
|
9666
|
-
if (!this.has(value)) {
|
|
9667
|
-
const index = this.values.length;
|
|
9668
|
-
this.values.push(value);
|
|
9669
|
-
this.valueToValueIndex[value] = index;
|
|
9670
|
-
}
|
|
9671
|
-
}
|
|
9672
|
-
remove(value) {
|
|
9673
|
-
if (this.has(value)) {
|
|
9674
|
-
const lastValue = this.values.pop();
|
|
9675
|
-
if (value === lastValue) {
|
|
9676
|
-
this.valueToValueIndex[value] = undefined;
|
|
9677
|
-
}
|
|
9678
|
-
else {
|
|
9679
|
-
const indexOfValue = this.valueToValueIndex[value];
|
|
9680
|
-
this.values[indexOfValue] = lastValue;
|
|
9681
|
-
this.valueToValueIndex[lastValue] = indexOfValue;
|
|
9682
|
-
// 跟一般的实现不同, 直接删除值的索引.
|
|
9683
|
-
this.valueToValueIndex[value] = undefined;
|
|
9684
|
-
}
|
|
9685
|
-
}
|
|
9686
|
-
}
|
|
9687
|
-
}
|
|
9688
|
-
|
|
9689
9650
|
// 相关提案: https://github.com/tc39/proposal-resizablearraybuffer
|
|
9690
9651
|
class DynamicTypedArray {
|
|
9691
9652
|
constructor(typedArrayConstructor, { capacity = 0, growthFactor = 1.5 } = {}) {
|
|
@@ -9806,6 +9767,102 @@
|
|
|
9806
9767
|
}
|
|
9807
9768
|
}
|
|
9808
9769
|
|
|
9770
|
+
class SparseSet {
|
|
9771
|
+
constructor() {
|
|
9772
|
+
this.indexToValue = new DynamicTypedArray(Uint32Array);
|
|
9773
|
+
this.valueToIndex = new DynamicTypedArray(Uint32Array);
|
|
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 {
|
|
9805
|
+
constructor() {
|
|
9806
|
+
this.keyToIndex = new DynamicTypedArray(Uint32Array);
|
|
9807
|
+
this.indexToKey = new DynamicTypedArray(Uint32Array);
|
|
9808
|
+
this.indexToValue = new DynamicTypedArray(Uint32Array);
|
|
9809
|
+
}
|
|
9810
|
+
get [Symbol.toStringTag]() {
|
|
9811
|
+
return this.constructor.name;
|
|
9812
|
+
}
|
|
9813
|
+
*entries() {
|
|
9814
|
+
for (let i = 0; i < this.indexToKey.length; i++) {
|
|
9815
|
+
yield [
|
|
9816
|
+
this.indexToKey.internalTypedArray[i],
|
|
9817
|
+
this.indexToValue.internalTypedArray[i]
|
|
9818
|
+
];
|
|
9819
|
+
}
|
|
9820
|
+
}
|
|
9821
|
+
keys() {
|
|
9822
|
+
return this.indexToKey.internalTypedArray.values();
|
|
9823
|
+
}
|
|
9824
|
+
values() {
|
|
9825
|
+
return this.indexToValue.internalTypedArray.values();
|
|
9826
|
+
}
|
|
9827
|
+
has(key) {
|
|
9828
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9829
|
+
return this.indexToKey.internalTypedArray[index] === key;
|
|
9830
|
+
}
|
|
9831
|
+
get(key) {
|
|
9832
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9833
|
+
if (this.indexToKey.internalTypedArray[index] === key) {
|
|
9834
|
+
return this.indexToValue.internalTypedArray[index];
|
|
9835
|
+
}
|
|
9836
|
+
else {
|
|
9837
|
+
return undefined;
|
|
9838
|
+
}
|
|
9839
|
+
}
|
|
9840
|
+
set(key, value) {
|
|
9841
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9842
|
+
if (this.indexToKey.internalTypedArray[index] === key) {
|
|
9843
|
+
this.indexToValue.internalTypedArray[index] = value;
|
|
9844
|
+
}
|
|
9845
|
+
else {
|
|
9846
|
+
const index = this.indexToKey.length;
|
|
9847
|
+
this.indexToKey.push(key);
|
|
9848
|
+
this.indexToValue.push(value);
|
|
9849
|
+
this.keyToIndex.set(key, index);
|
|
9850
|
+
}
|
|
9851
|
+
}
|
|
9852
|
+
delete(key) {
|
|
9853
|
+
const index = this.keyToIndex.internalTypedArray[key];
|
|
9854
|
+
if (this.indexToKey.internalTypedArray[index] === key) {
|
|
9855
|
+
const lastKey = this.indexToKey.pop();
|
|
9856
|
+
const lastValue = this.indexToValue.pop();
|
|
9857
|
+
if (key !== lastKey) {
|
|
9858
|
+
this.indexToKey.internalTypedArray[index] = lastKey;
|
|
9859
|
+
this.indexToValue.internalTypedArray[index] = lastValue;
|
|
9860
|
+
this.keyToIndex.internalTypedArray[lastKey] = index;
|
|
9861
|
+
}
|
|
9862
|
+
}
|
|
9863
|
+
}
|
|
9864
|
+
}
|
|
9865
|
+
|
|
9809
9866
|
exports.BadEventError = BadEventError;
|
|
9810
9867
|
exports.Box = Box;
|
|
9811
9868
|
exports.DynamicTypedArray = DynamicTypedArray;
|
|
@@ -9817,6 +9874,7 @@
|
|
|
9817
9874
|
exports.LRUMap = LRUMap;
|
|
9818
9875
|
exports.ObservableFiniteStateMachine = ObservableFiniteStateMachine;
|
|
9819
9876
|
exports.Queue = Queue;
|
|
9877
|
+
exports.SparseMap = SparseMap;
|
|
9820
9878
|
exports.SparseSet = SparseSet;
|
|
9821
9879
|
exports.TLRUMap = TLRUMap;
|
|
9822
9880
|
exports.TrieMap = TrieMap;
|