Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/kuhn_munkres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! [Kuhn-Munkres algorithm](https://en.wikipedia.org/wiki/Hungarian_algorithm)
//! (also known as Hungarian algorithm).

use crate::{FxIndexSet, matrix::Matrix};
use crate::matrix::Matrix;
use num_traits::{Bounded, Signed, Zero};
use std::iter::Sum;

Expand Down Expand Up @@ -138,7 +138,9 @@ where
let mut ly: Vec<C> = vec![Zero::zero(); ny];
// s, augmenting, and slack will be reset every time they are reused. augmenting
// contains Some(prev) when the corresponding node belongs to the augmenting path.
let mut s = FxIndexSet::<usize>::default();
// Every x node enters the alternating path at most once per root, and the set is only ever
// appended to and walked, so a plain vector does the job without hashing.
let mut s = Vec::<usize>::new();
let mut alternating = Vec::with_capacity(ny);
let mut slack = vec![Zero::zero(); ny];
let mut slackx = Vec::with_capacity(ny);
Expand All @@ -149,7 +151,7 @@ where
// loop below. Above the loop is some code to initialize the search.
let mut y = {
s.clear();
s.insert(root);
s.push(root);
// Slack for a vertex y is, initially, the margin between the
// sum of the labels of root and y, and the weight between root and y.
// As we add x nodes to the alternating path, we update the slack to
Expand Down Expand Up @@ -197,7 +199,7 @@ where
// This y node had a predecessor, add it to the set of x nodes
// in the augmenting path.
let x = yx[y].unwrap();
s.insert(x);
s.push(x);
// Update slack because of the added vertex in s might contain a
// greater slack than with previously inserted x nodes in the augmenting
// path.
Expand Down
4 changes: 2 additions & 2 deletions src/undirected/connected_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ where
.filter(|&(_, n)| n != usize::MAX)
{
let set = gb.entry(n).or_default();
for e in groups[i].clone() {
set.insert(e);
for e in &groups[i] {
set.insert(e.clone());
}
}
gb.into_values().map(|v| v.into_iter().collect()).collect()
Expand Down
Loading