Skip to content

Commit

Permalink
Add DerivationTree.packages() -> HashSet<&P>
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored and konstin committed May 7, 2024
1 parent f3dbcda commit c69d3ca
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::fmt::{self, Debug, Display};
use std::ops::Deref;
use std::sync::Arc;

use rustc_hash::FxHashSet;

use crate::package::Package;
use crate::term::Term;
use crate::type_aliases::Map;
Expand Down Expand Up @@ -71,6 +73,30 @@ pub struct Derived<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display>
}

impl<P: Package, VS: VersionSet, M: Eq + Clone + Debug + Display> DerivationTree<P, VS, M> {
/// Get all packages referred to in the derivation tree.
pub fn packages(&self) -> FxHashSet<&P> {
let mut packages = FxHashSet::default();
match self {
Self::External(external) => match external {
External::FromDependencyOf(p, _, p2, _) => {
packages.insert(p);
packages.insert(p2);
}
External::NoVersions(p, _)
| External::NotRoot(p, _)
| External::Custom(p, _, _) => {
packages.insert(p);
}
},
Self::Derived(derived) => {
packages.extend(derived.terms.keys());
packages.extend(derived.cause1.packages().iter());
packages.extend(derived.cause2.packages().iter());
}
}
packages
}

/// Merge the [NoVersions](External::NoVersions) external incompatibilities
/// with the other one they are matched with
/// in a derived incompatibility.
Expand Down

0 comments on commit c69d3ca

Please sign in to comment.