pub struct BipartiteMatching { /* private fields */ }Expand description
A reusable Hopcroft–Karp matcher.
Built to be reset and refilled each frame: the internal vectors keep their
capacity across reset, so a caller with a stable graph
shape pays one set of allocations on the first frame and none after.
Implementations§
Source§impl BipartiteMatching
impl BipartiteMatching
Sourcepub fn with_shape(n_left: usize, n_right: usize) -> Self
pub fn with_shape(n_left: usize, n_right: usize) -> Self
A matcher shaped for n_left layers and n_right planes.
Sourcepub fn reset(&mut self, n_left: usize, n_right: usize)
pub fn reset(&mut self, n_left: usize, n_right: usize)
Re-shape and clear, keeping allocated capacity.
Every per-node container is reset, so a fresh call sees exactly the state a freshly constructed matcher would.
Sourcepub fn add_edge(&mut self, left: usize, right: usize)
pub fn add_edge(&mut self, left: usize, right: usize)
Add an unscored edge: layer left could use plane right.
Out-of-range endpoints are ignored rather than panicking — a caller filtering candidates should not have to re-check bounds the matcher already knows.
Sourcepub fn add_scored_edge(&mut self, left: usize, right: usize, score: i32)
pub fn add_scored_edge(&mut self, left: usize, right: usize, score: i32)
Add an edge with a preference score. Higher is tried first.
The score cannot change how many layers get placed — see the module documentation.
Sourcepub fn solve(&mut self) -> usize
pub fn solve(&mut self) -> usize
Compute the maximum-cardinality matching, returning how many pairs it found.
Sourcepub fn match_for_left(&self, left: usize) -> Option<usize>
pub fn match_for_left(&self, left: usize) -> Option<usize>
The plane matched to a layer, after solve.
Sourcepub fn match_for_right(&self, right: usize) -> Option<usize>
pub fn match_for_right(&self, right: usize) -> Option<usize>
The layer matched to a plane, after solve.
Sourcepub const fn matched_count(&self) -> usize
pub const fn matched_count(&self) -> usize
How many pairs the last solve found.