MCPcopy
hub / github.com/webpack/webpack / popFirst

Method popFirst

lib/util/LazyBucketSortedSet.js:148–179  ·  lib/util/LazyBucketSortedSet.js::LazyBucketSortedSet.popFirst

* 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

()

Source from the content-addressed store, hash-verified

146 * @returns {T | undefined} an item
147 */
148 popFirst() {
149 if (this.size === 0) return;
150 this.size--;
151 if (this._unsortedItems.size > 0) {
152 for (const item of this._unsortedItems) {
153 const key = this._getKey(item);
154 this._addInternal(key, item);
155 }
156 this._unsortedItems.clear();
157 }
158 this._keys.sort();
159 const key = /** @type {K} */ (first(this._keys));
160 const entry = this._map.get(key);
161 if (this._leaf) {
162 const leafEntry = /** @type {SortableSet<T>} */ (entry);
163 leafEntry.sort();
164 const item = /** @type {T} */ (first(leafEntry));
165 leafEntry.delete(item);
166 if (leafEntry.size === 0) {
167 this._deleteKey(key);
168 }
169 return item;
170 }
171 const nodeEntry =
172 /** @type {LazyBucketSortedSet<T, K>} */
173 (entry);
174 const item = nodeEntry.popFirst();
175 if (nodeEntry.size === 0) {
176 this._deleteKey(key);
177 }
178 return item;
179 }
180
181 /**
182 * Begins an in-place update for an item and returns a completion callback

Callers 1

applyMethod · 0.95

Calls 7

_addInternalMethod · 0.95
_deleteKeyMethod · 0.95
firstFunction · 0.85
sortMethod · 0.80
clearMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected