From cf25a87b74b8302bd9643290be9db230e3f65d6d Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 8 Dec 2023 16:17:31 -0600 Subject: [PATCH] Add `DerivationTree.packages() -> HashSet<&P>` (#11) * Add `DeriviationTree.packages -> HashSet<&P>` * Fixup `main` * Use FxHashSet --- src/report.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/report.rs b/src/report.rs index 35880dce..944bd9f0 100644 --- a/src/report.rs +++ b/src/report.rs @@ -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; @@ -71,6 +73,29 @@ pub struct Derived } impl DerivationTree { + /// 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.