Skip to content

Commit

Permalink
Add DerivationTree.packages() -> HashSet<&P> (#11)
Browse files Browse the repository at this point in the history
* Add `DeriviationTree.packages -> HashSet<&P>`

* Fixup `main`

* Use FxHashSet
  • Loading branch information
zanieb authored and konstin committed May 7, 2024
1 parent e13fb6f commit cf25a87
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 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,29 @@ 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 [Package]s referred to in the deriviation 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 cf25a87

Please sign in to comment.