From b10fb1ab0c2799a59b5e9f739739f4cd8cf9ea5a Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 22 Jan 2024 14:36:50 -0500 Subject: [PATCH] refactor: centralize use of hash sets/maps (#182) Previously, pubgrub used an alias for HashMap so that everything used the same implementation. But it didn't do the same for HashSet, and indeed, there were some uses of FxHashSet and std::collections::HashSet. Like for HashMap, we standard on the use of FxHashSet for everything. --- src/internal/core.rs | 7 +++---- src/internal/incompatibility.rs | 2 +- src/type_aliases.rs | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/internal/core.rs b/src/internal/core.rs index 38bdca17..eceb7b68 100644 --- a/src/internal/core.rs +++ b/src/internal/core.rs @@ -3,7 +3,6 @@ //! Core model and functions //! to write a functional PubGrub algorithm. -use std::collections::HashSet as Set; use std::error::Error; use crate::error::PubGrubError; @@ -16,7 +15,7 @@ use crate::internal::partial_solution::{DecisionLevel, PartialSolution}; use crate::internal::small_vec::SmallVec; use crate::package::Package; use crate::report::DerivationTree; -use crate::type_aliases::{DependencyConstraints, Map}; +use crate::type_aliases::{DependencyConstraints, Map, Set}; use crate::version_set::VersionSet; /// Current state of the PubGrub algorithm. @@ -294,8 +293,8 @@ impl State { } fn find_shared_ids(&self, incompat: IncompId) -> Set> { - let mut all_ids = Set::new(); - let mut shared_ids = Set::new(); + let mut all_ids = Set::default(); + let mut shared_ids = Set::default(); let mut stack = vec![incompat]; while let Some(i) = stack.pop() { if let Some((id1, id2)) = self.incompatibility_store[i].causes() { diff --git a/src/internal/incompatibility.rs b/src/internal/incompatibility.rs index 180ec4ec..1540a43b 100644 --- a/src/internal/incompatibility.rs +++ b/src/internal/incompatibility.rs @@ -3,7 +3,6 @@ //! An incompatibility is a set of terms for different packages //! that should never be satisfied all together. -use std::collections::HashSet as Set; use std::fmt; use crate::internal::arena::{Arena, Id}; @@ -13,6 +12,7 @@ use crate::report::{ DefaultStringReportFormatter, DerivationTree, Derived, External, ReportFormatter, }; use crate::term::{self, Term}; +use crate::type_aliases::Set; use crate::version_set::VersionSet; /// An incompatibility is a set of terms for different packages diff --git a/src/type_aliases.rs b/src/type_aliases.rs index 11cc37c7..ba57be06 100644 --- a/src/type_aliases.rs +++ b/src/type_aliases.rs @@ -5,6 +5,9 @@ /// Map implementation used by the library. pub type Map = rustc_hash::FxHashMap; +/// Set implementation used by the library. +pub type Set = rustc_hash::FxHashSet; + /// Concrete dependencies picked by the library during [resolve](crate::solver::resolve) /// from [DependencyConstraints]. pub type SelectedDependencies = Map;