From fcd959a219b2a51d9c0f4ef144886c38e68ddebb 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 9286393c..d1b31655 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.