WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/webpack/lib/util/LazyBucketSortedSet.js
@@ -9,23 +9,28 @@
const SortableSet = require("./SortableSet");
/**
 * Callback that extracts the grouping key for an item at one bucket layer.
 * @template T
 * @template K
 * @typedef {(item: T) => K} GetKey
 */
/**
 * Comparison function used to order keys or leaf items.
 * @template T
 * @typedef {(a: T, n: T) => number} Comparator
 */
/**
 * Internal bucket entry, either another nested bucket set or a sorted leaf set.
 * @template T
 * @template K
 * @typedef {LazyBucketSortedSet<T, K> | SortableSet<T>} Entry
 */
/**
 * Constructor argument accepted for nested bucket layers or the final leaf
 * comparator.
 * @template T
 * @template K
 * @typedef {GetKey<T, K> | Comparator<K> | Comparator<T>} Arg
@@ -45,6 +50,8 @@
 */
class LazyBucketSortedSet {
   /**
    * Creates a lazily sorted, potentially multi-level bucket structure whose
    * order is only fully resolved when items are popped.
    * @param {GetKey<T, K>} getKey function to get key from item
    * @param {Comparator<K>=} comparator comparator to sort keys
    * @param {...Arg<T, K>} args more pairs of getKey and comparator plus optional final comparator for the last layer
@@ -56,11 +63,14 @@
      this._keys = new SortableSet(undefined, comparator);
      /** @type {Map<K, Entry<T, K>>} */
      this._map = new Map();
      /** @type {Set<T>} */
      this._unsortedItems = new Set();
      this.size = 0;
   }
   /**
    * Adds an item to the unsorted staging area so sorting can be deferred until
    * an ordered pop is requested.
    * @param {T} item an item
    * @returns {void}
    */
@@ -70,6 +80,8 @@
   }
   /**
    * Inserts an item into the correct nested bucket, creating intermediate
    * bucket structures on demand.
    * @param {K} key key of item
    * @param {T} item the item
    * @returns {void}
@@ -94,6 +106,8 @@
   }
   /**
    * Removes an item from either the unsorted staging area or its resolved
    * bucket and prunes empty buckets as needed.
    * @param {T} item an item
    * @returns {void}
    */
@@ -112,6 +126,7 @@
   }
   /**
    * Removes an empty bucket key and its corresponding nested entry.
    * @param {K} key key to be removed
    * @returns {void}
    */
@@ -121,6 +136,8 @@
   }
   /**
    * Removes and returns the smallest item according to the configured bucket
    * order, sorting only the portions of the structure that are needed.
    * @returns {T | undefined} an item
    */
   popFirst() {
@@ -157,6 +174,8 @@
   }
   /**
    * Begins an in-place update for an item and returns a completion callback
    * that can either reinsert it under a new key or remove it entirely.
    * @param {T} item to be updated item
    * @returns {(remove?: true) => void} finish update
    */
@@ -221,6 +240,8 @@
   }
   /**
    * Appends iterators for every stored bucket and leaf to support unordered
    * traversal across the entire structure.
    * @param {Iterator<T>[]} iterators list of iterators to append to
    * @returns {void}
    */
@@ -244,6 +265,7 @@
   }
   /**
    * Iterates over all stored items without imposing bucket sort order.
    * @returns {Iterator<T>} the iterator
    */
   [Symbol.iterator]() {