From 881bb16f652ec33fb18be36bd7972536d17969d8 Mon Sep 17 00:00:00 2001 From: Michael Neumann Date: Sun, 7 Apr 2019 12:18:31 +0200 Subject: [PATCH] Use FixedBitSet#ones() iterator Improves performance by about 5% --- src/coverage.rs | 16 +++------------- src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/coverage.rs b/src/coverage.rs index 7285639..4715455 100644 --- a/src/coverage.rs +++ b/src/coverage.rs @@ -53,22 +53,12 @@ impl Coverage { /// iterates over all uncovered (row, column) pairs in row, column order #[inline] - pub fn iter_uncovered_row_column(&self, mut f: F) + pub fn iter_uncovered_row_column_order(&self, mut f: F) where F: FnMut(Position), { - let n = self.n(); - - for row in 0..n { - if self.is_row_covered(row) { - continue; - } - - for column in 0..n { - if self.is_column_covered(column) { - continue; - } - + for row in self.uncovered_rows.ones() { + for column in self.uncovered_columns.ones() { f(Position { row, column }); } } diff --git a/src/lib.rs b/src/lib.rs index 348a655..b1739b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -231,7 +231,7 @@ where // Find the smallest uncovered value in the matrix let mut min = None; - cov.iter_uncovered_row_column(|pos| { + cov.iter_uncovered_row_column_order(|pos| { let elm = c.element_at(pos); min = Some(match min { Some(m) => {