Enhance matching module with valid children tracking and code readability improvements

- Added a `validChildren` field to the `VCache` structure to track valid child instances during the matching process.
- Refactored the `cacheVirtual` function to improve readability by formatting parameters across multiple lines.
- Updated the `computePairCost` function to utilize the new `validChildren` field for more accurate cost calculations.
- Simplified the `matchChildren` function by removing redundant code and improving the handling of matched instances.
- Enhanced test cases for the `matchChildren` function to ensure consistent behavior and validate the new changes.

These updates improve the efficiency and clarity of the matching process, ensuring better performance and maintainability.
This commit is contained in:
Joe 2026-02-18 06:40:28 -06:00
parent b687c8862d
commit ddd47b9afa
9 changed files with 287 additions and 363 deletions

View file

@ -1318,7 +1318,10 @@ mod tests {
let (tree, children) = make_tree_with_children(&[("Alpha", "Folder"), ("Beta", "Folder")]);
let result = match_forward(snaps, &children, &tree, &MatchingSession::new());
assert_eq!(result.matched.len(), 2);
assert_eq!(result.total_cost, 0, "Identical instances should have zero cost");
assert_eq!(
result.total_cost, 0,
"Identical instances should have zero cost"
);
}
#[test]
@ -1390,14 +1393,8 @@ mod tests {
#[test]
fn session_cache_consistent() {
let snaps1 = vec![
make_snapshot("X", "Folder"),
make_snapshot("Y", "Folder"),
];
let snaps2 = vec![
make_snapshot("X", "Folder"),
make_snapshot("Y", "Folder"),
];
let snaps1 = vec![make_snapshot("X", "Folder"), make_snapshot("Y", "Folder")];
let snaps2 = vec![make_snapshot("X", "Folder"), make_snapshot("Y", "Folder")];
let (tree, children) = make_tree_with_children(&[("X", "Folder"), ("Y", "Folder")]);
let session = MatchingSession::new();
@ -1406,10 +1403,7 @@ mod tests {
assert_eq!(r1.matched.len(), r2.matched.len());
assert_eq!(r1.total_cost, r2.total_cost);
assert_eq!(
r1.unmatched_snapshot.len(),
r2.unmatched_snapshot.len()
);
assert_eq!(r1.unmatched_snapshot.len(), r2.unmatched_snapshot.len());
}
#[test]