for (u = 1; u <= u_size; u++)
{ if (state->pair_uv[u] == 0) if (hk_depth_search(state, u))
state->matching++;
}
CHECK_FOR_INTERRUPTS(); /* just in case */
}
return state;
}
/* *FreeastatereturnedbyBipartiteMatch,exceptfortheoriginaladjacency *list,whichisownedbythecaller.Thisonlyfreesmemory,soit'soptional.
*/ void
BipartiteMatchFree(BipartiteMatchState *state)
{ /* adjacency matrix is treated as owned by the caller */
pfree(state->pair_uv);
pfree(state->pair_vu);
pfree(state->distance);
pfree(state->queue);
pfree(state);
}
/* *Performthebreadth-firstsearchstepofH-Kmatching. *Returnstrueifsuccessful.
*/ staticbool
hk_breadth_search(BipartiteMatchState *state)
{ int usize = state->u_size; short *queue = state->queue; short *distance = state->distance; int qhead = 0; /* we never enqueue any node more than once */ int qtail = 0; /* so don't have to worry about wrapping */ int u;
distance[0] = HK_INFINITY;
for (u = 1; u <= usize; u++)
{ if (state->pair_uv[u] == 0)
{
distance[u] = 0;
queue[qhead++] = u;
} else
distance[u] = HK_INFINITY;
}
while (qtail < qhead)
{
u = queue[qtail++];
if (distance[u] < distance[0])
{ short *u_adj = state->adjacency[u]; int i = u_adj ? u_adj[0] : 0;
for (; i > 0; i--)
{ int u_next = state->pair_vu[u_adj[i]];
/* *Performthedepth-firstsearchstepofH-Kmatching. *Returnstrueifsuccessful.
*/ staticbool
hk_depth_search(BipartiteMatchState *state, int u)
{ short *distance = state->distance; short *pair_uv = state->pair_uv; short *pair_vu = state->pair_vu; short *u_adj = state->adjacency[u]; int i = u_adj ? u_adj[0] : 0; short nextdist;
if (u == 0) returntrue; if (distance[u] == HK_INFINITY) returnfalse;
nextdist = distance[u] + 1;
check_stack_depth();
for (; i > 0; i--)
{ int v = u_adj[i];
if (distance[pair_vu[v]] == nextdist)
{ if (hk_depth_search(state, pair_vu[v]))
{
pair_vu[v] = u;
pair_uv[u] = v; returntrue;
}
}
}
distance[u] = HK_INFINITY; returnfalse;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.