MCPcopy
hub / github.com/webpack/webpack / assignDeterministicIds

Function assignDeterministicIds

lib/ids/IdHelpers.js:391–431  ·  view source on GitHub ↗
(
	items,
	getName,
	comparator,
	assignId,
	ranges = [10],
	expandFactor = 10,
	extraSpace = 0,
	salt = 0
)

Source from the content-addressed store, hash-verified

389 * @returns {void}
390 */
391const assignDeterministicIds = (
392 items,
393 getName,
394 comparator,
395 assignId,
396 ranges = [10],
397 expandFactor = 10,
398 extraSpace = 0,
399 salt = 0
400) => {
401 items.sort(comparator);
402
403 // max 5% fill rate
404 const optimalRange = Math.min(
405 items.length * 20 + extraSpace,
406 Number.MAX_SAFE_INTEGER
407 );
408
409 let i = 0;
410 let range = ranges[i];
411 while (range < optimalRange) {
412 i++;
413 if (i < ranges.length) {
414 range = Math.min(ranges[i], Number.MAX_SAFE_INTEGER);
415 } else if (expandFactor) {
416 range = Math.min(range * expandFactor, Number.MAX_SAFE_INTEGER);
417 } else {
418 break;
419 }
420 }
421
422 for (const item of items) {
423 const ident = getName(item);
424 /** @type {number} */
425 let id;
426 let i = salt;
427 do {
428 id = numberHash(ident + i++, range);
429 } while (!assignId(item, id));
430 }
431};
432
433/**
434 * Assign ascending module ids.

Callers 3

mangleExportsInfoFunction · 0.85
applyMethod · 0.85
applyMethod · 0.85

Calls 2

getNameFunction · 0.85
sortMethod · 0.80

Tested by

no test coverage detected