Example
// ____ // / \. // 0 1 2 | 3 4 // | / \ /| | |\ | // | / X | / | \ | // |/ / \|/ | \| // 5 6 7 8 9 // uint[][] adjacency; adjacency.length = 10; alias connect = (from, uint[] neighbors...) { adjacency[from] ~= neighbors; }; connect(0u, 5u); connect(1u, 5u, 7u); connect(2u, 6u, 7u); connect(3u, 8u, 9u); connect(4u, 7u, 9u); connect(5u, 0u, 1u); connect(6u, 2u); connect(7u, 2u, 4u); connect(8u, 3u); connect(9u, 3u, 4u); auto count = hopcroftKarp(iota(5u), iota(5u, 10u), adjacency); assert(count == 5);
Takes as input a bipartite graph and produces as output a maximum cardinality matching – a set of as many edges as possible with the property that no two edges share an endpoint.
Calling this function with a non-bipartite graph results in undefined behaviour.