Skip to content

Commit

Permalink
Create a sort function for GraphImpact
Browse files Browse the repository at this point in the history
Summary: Centralise this logic in one place.

Differential Revision: D58402987

fbshipit-source-id: aa8206e607e1504f377fcebccc0dce6d980f6bdc
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Jun 11, 2024
1 parent 4ac0e3d commit cf4a990
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions btd/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ impl<'a> GraphImpact<'a> {
.chain(self.non_recursive.iter())
.cloned()
}

/// Sort all the fields, ensuring they are in a deterministic order.
pub fn sort(&mut self) {
self.recursive.sort_by_key(|(t, _)| t.label_key());
self.non_recursive.sort_by_key(|(t, _)| t.label_key());
self.removed.sort_by_key(|(t, _)| t.label_key());
}
}

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -251,9 +258,7 @@ pub fn immediate_target_changes<'a>(
.collect();

// Sort to ensure deterministic output
res.recursive.sort_by_key(|(t, _)| t.label_key());
res.non_recursive.sort_by_key(|(t, _)| t.label_key());
res.removed.sort_by_key(|(t, _)| t.label_key());
res.sort();
res
}

Expand Down

0 comments on commit cf4a990

Please sign in to comment.