@blackglory/structures 0.6.0 → 0.6.3

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 (44) hide show
  1. package/README.md +20 -5
  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 +54 -1
  5. package/dist/es2015/index.mjs.map +1 -1
  6. package/dist/es2015/index.umd.js +54 -0
  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 +54 -1
  13. package/dist/es2018/index.mjs.map +1 -1
  14. package/dist/es2018/index.umd.js +54 -0
  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/hash-map.d.ts +2 -2
  19. package/lib/es2015/hash-map.js.map +1 -1
  20. package/lib/es2015/hash-set.d.ts +2 -2
  21. package/lib/es2015/hash-set.js.map +1 -1
  22. package/lib/es2015/index.d.ts +1 -0
  23. package/lib/es2015/index.js +1 -0
  24. package/lib/es2015/index.js.map +1 -1
  25. package/lib/es2015/sparse-set.d.ts +8 -0
  26. package/lib/es2015/sparse-set.js +37 -0
  27. package/lib/es2015/sparse-set.js.map +1 -0
  28. package/lib/es2015/trie-map.d.ts +4 -2
  29. package/lib/es2015/trie-map.js +19 -0
  30. package/lib/es2015/trie-map.js.map +1 -1
  31. package/lib/es2018/hash-map.d.ts +2 -2
  32. package/lib/es2018/hash-map.js.map +1 -1
  33. package/lib/es2018/hash-set.d.ts +2 -2
  34. package/lib/es2018/hash-set.js.map +1 -1
  35. package/lib/es2018/index.d.ts +1 -0
  36. package/lib/es2018/index.js +1 -0
  37. package/lib/es2018/index.js.map +1 -1
  38. package/lib/es2018/sparse-set.d.ts +8 -0
  39. package/lib/es2018/sparse-set.js +37 -0
  40. package/lib/es2018/sparse-set.js.map +1 -0
  41. package/lib/es2018/trie-map.d.ts +4 -2
  42. package/lib/es2018/trie-map.js +19 -0
  43. package/lib/es2018/trie-map.js.map +1 -1
  44. package/package.json +1 -1
@@ -7564,6 +7564,24 @@
7564
7564
  get [Symbol.toStringTag]() {
7565
7565
  return this.constructor.name;
7566
7566
  }
7567
+ *entries() {
7568
+ yield* dfs(this.root, []);
7569
+ function* dfs(node, paths) {
7570
+ for (const [path, childNode] of node.children) {
7571
+ const newPaths = [...paths, path];
7572
+ if (es2018$2.isntUndefined(childNode.value)) {
7573
+ yield [newPaths, childNode.value];
7574
+ }
7575
+ yield* dfs(childNode, newPaths);
7576
+ }
7577
+ }
7578
+ }
7579
+ keys() {
7580
+ return es2018$4.map(this.entries(), ([key]) => key);
7581
+ }
7582
+ values() {
7583
+ return es2018$4.map(this.entries(), ([_, value]) => value);
7584
+ }
7567
7585
  set(key, value) {
7568
7586
  let node = this.root;
7569
7587
  for (const part of key) {
@@ -9244,6 +9262,41 @@
9244
9262
  }
9245
9263
  }
9246
9264
 
9265
+ class SparseSet {
9266
+ constructor() {
9267
+ this.values = [];
9268
+ this.valueToValueIndex = [];
9269
+ }
9270
+ *[Symbol.iterator]() {
9271
+ for (const value of this.values) {
9272
+ yield value;
9273
+ }
9274
+ }
9275
+ has(value) {
9276
+ // 跟一般的实现不同, 不需要访问values数组.
9277
+ return this.valueToValueIndex[value] !== undefined;
9278
+ }
9279
+ add(value) {
9280
+ if (!this.has(value)) {
9281
+ const index = this.values.length;
9282
+ this.values.push(value);
9283
+ this.valueToValueIndex[value] = index;
9284
+ }
9285
+ }
9286
+ remove(value) {
9287
+ if (this.has(value)) {
9288
+ const lastValue = this.values.pop();
9289
+ if (value !== lastValue) {
9290
+ const indexOfValue = this.valueToValueIndex[value];
9291
+ this.values[indexOfValue] = lastValue;
9292
+ this.valueToValueIndex[lastValue] = indexOfValue;
9293
+ // 跟一般的实现不同, 直接删除值的索引.
9294
+ this.valueToValueIndex[value] = undefined;
9295
+ }
9296
+ }
9297
+ }
9298
+ }
9299
+
9247
9300
  exports.BadEventError = BadEventError;
9248
9301
  exports.Box = Box;
9249
9302
  exports.Emitter = Emitter;
@@ -9254,6 +9307,7 @@
9254
9307
  exports.LRUMap = LRUMap;
9255
9308
  exports.ObservableFiniteStateMachine = ObservableFiniteStateMachine;
9256
9309
  exports.Queue = Queue;
9310
+ exports.SparseSet = SparseSet;
9257
9311
  exports.TLRUMap = TLRUMap;
9258
9312
  exports.TrieMap = TrieMap;
9259
9313
  exports.convertArrayToCons = convertArrayToCons;