MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / buildUnits

Function buildUnits

src/orchestration/partition.ts:70–91  ·  view source on GitHub ↗

Coalesce coupled items into units, preserving first-appearance order.

(items: WorkItem<T>[])

Source from the content-addressed store, hash-verified

68
69/** Coalesce coupled items into units, preserving first-appearance order. */
70function buildUnits<T>(items: WorkItem<T>[]): Unit<T>[] {
71 const byKey = new Map<string, Unit<T>>();
72 const units: Unit<T>[] = [];
73 items.forEach((item, i) => {
74 const w = sanitizeWeight(item.weight);
75 const key = item.coupledKey && item.coupledKey.length > 0 ? item.coupledKey : null;
76 if (key === null) {
77 units.push({ key: item.id, weight: w, members: [item], order: i });
78 return;
79 }
80 const existing = byKey.get(key);
81 if (existing) {
82 existing.weight += w;
83 existing.members.push(item);
84 } else {
85 const unit: Unit<T> = { key, weight: w, members: [item], order: i };
86 byKey.set(key, unit);
87 units.push(unit);
88 }
89 });
90 return units;
91}
92
93/** Decide how many partitions to create, clamped to every relevant bound. */
94function chooseK<T>(units: Unit<T>[], totalWeight: number, opts: PartitionOptions): number {

Callers 1

partitionWorkFunction · 0.85

Calls 4

sanitizeWeightFunction · 0.85
pushMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected