MCPcopy Create free account
hub / github.com/vercel/vercel / lambdaKnapsack

Function lambdaKnapsack

packages/python/src/dependency-externalizer.ts:1170–1191  ·  view source on GitHub ↗
(
  packages: Map<string, number>,
  capacity: number
)

Source from the content-addressed store, hash-verified

1168 * fit within the remaining capacity.
1169 */
1170export function lambdaKnapsack(
1171 packages: Map<string, number>,
1172 capacity: number
1173): string[] {
1174 if (capacity <= 0) {
1175 return [];
1176 }
1177
1178 // Sort by size descending so we pack the largest packages first.
1179 const sorted = [...packages.entries()].sort(([, a], [, b]) => b - a);
1180
1181 const bundled: string[] = [];
1182 let remaining = capacity;
1183 for (const [name, size] of sorted) {
1184 if (size <= remaining) {
1185 bundled.push(name);
1186 remaining -= size;
1187 }
1188 }
1189
1190 return bundled;
1191}

Calls 2

sortMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected