MCPcopy
hub / github.com/webpack/webpack / intersect

Function intersect

lib/util/SetHelpers.js:14–37  ·  view source on GitHub ↗
(sets)

Source from the content-addressed store, hash-verified

12 * @returns {Set<T>} returns a new Set containing the intersecting items
13 */
14const intersect = (sets) => {
15 if (sets.length === 0) return new Set();
16 if (sets.length === 1) return new Set(sets[0]);
17 let minSize = Infinity;
18 let minIndex = -1;
19 for (let i = 0; i < sets.length; i++) {
20 const size = sets[i].size;
21 if (size < minSize) {
22 minIndex = i;
23 minSize = size;
24 }
25 }
26 const current = new Set(sets[minIndex]);
27 for (let i = 0; i < sets.length; i++) {
28 if (i === minIndex) continue;
29 const set = sets[i];
30 for (const item of current) {
31 if (!set.has(item)) {
32 current.delete(item);
33 }
34 }
35 }
36 return current;
37};
38
39/**
40 * Checks if a set is the subset of another set

Callers 3

getAllAsyncChunksMethod · 0.85
hasAsyncChunksMethod · 0.85
applySplitMethod · 0.85

Calls 2

hasMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected