From 22808e6140ac5a901be5fb146c59d5de4b480d1a Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 12 Mar 2026 20:25:21 -0500 Subject: [PATCH] feat: add is_empty method to GitIndexCache and refactor Hungarian algorithm loop - Introduced `is_empty` method in `GitIndexCache` to check if the cache has any entries. - Refactored the loop in the `min_cost_assignment` function in `hungarian.rs` to use `enumerate` for improved readability and efficiency. --- src/git.rs | 4 ++++ src/hungarian.rs | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/git.rs b/src/git.rs index ce8e4351..8e77a596 100644 --- a/src/git.rs +++ b/src/git.rs @@ -306,6 +306,10 @@ impl GitIndexCache { self.entries.len() } + pub fn is_empty(&self) -> bool { + self.entries.is_empty() + } + /// Returns `true` if the new content's blob SHA1 matches the git index /// entry for this path, meaning the file on disk almost certainly /// already has this content. diff --git a/src/hungarian.rs b/src/hungarian.rs index fc0b29f5..30eb1020 100644 --- a/src/hungarian.rs +++ b/src/hungarian.rs @@ -94,9 +94,9 @@ pub fn min_cost_assignment( } let mut result = Vec::with_capacity(rows.min(cols)); - for j in 1..=n { - if p[j] != 0 && p[j] <= rows && j <= cols { - result.push((p[j] - 1, j - 1)); + for (j, &assigned_row) in p.iter().enumerate().skip(1) { + if assigned_row != 0 && assigned_row <= rows && j <= cols { + result.push((assigned_row - 1, j - 1)); } } result