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.
This commit is contained in:
Joe 2026-03-12 20:25:21 -05:00
parent a901848861
commit 22808e6140
2 changed files with 7 additions and 3 deletions

View file

@ -306,6 +306,10 @@ impl GitIndexCache {
self.entries.len() 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 /// Returns `true` if the new content's blob SHA1 matches the git index
/// entry for this path, meaning the file on disk almost certainly /// entry for this path, meaning the file on disk almost certainly
/// already has this content. /// already has this content.

View file

@ -94,9 +94,9 @@ pub fn min_cost_assignment(
} }
let mut result = Vec::with_capacity(rows.min(cols)); let mut result = Vec::with_capacity(rows.min(cols));
for j in 1..=n { for (j, &assigned_row) in p.iter().enumerate().skip(1) {
if p[j] != 0 && p[j] <= rows && j <= cols { if assigned_row != 0 && assigned_row <= rows && j <= cols {
result.push((p[j] - 1, j - 1)); result.push((assigned_row - 1, j - 1));
} }
} }
result result