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 Mar 22, 2024
1 parent a2151d9 commit dfa84fb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/unsat_root_message_no_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
format!("dependencies of {package} at version {set} are unavailable")
}
}
External::UnusableDependencies(package, set, ..) => {
if set == &Range::full() {
format!("dependencies of {package} are unusable")
} else {
format!("dependencies of {package} at version {set} are unusable")
}
}
External::FromDependencyOf(package, package_set, dependency, dependency_set) => {
if package_set == &Range::full() && dependency_set == &Range::full() {
format!("{package} depends on {dependency}")
Expand All @@ -99,13 +106,6 @@ impl ReportFormatter<Package, Range<SemanticVersion>> for CustomReportFormatter
format!("{package} {package_set} depends on {dependency} {dependency_set}")
}
}
External::UnusableDependencies(package, set, ..) => {
if set == &Range::full() {
format!("dependencies of {package} are unusable")
} else {
format!("dependencies of {package} at version {set} are unusable")
}
}
}
}
}
Expand Down
27 changes: 27 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;
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 @@ -73,6 +75,31 @@ pub struct Derived<P: Package, VS: VersionSet> {
}

impl<P: Package, VS: VersionSet> DerivationTree<P, VS> {
/// 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::UnavailableDependencies(p, _)
| External::UnusableDependencies(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 dfa84fb

Please sign in to comment.