Skip to content

Commit b10fb1a

Browse files
authored
refactor: centralize use of hash sets/maps (pubgrub-rs#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.
1 parent 4a48371 commit b10fb1a

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/internal/core.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! Core model and functions
44
//! to write a functional PubGrub algorithm.
55
6-
use std::collections::HashSet as Set;
76
use std::error::Error;
87

98
use crate::error::PubGrubError;
@@ -16,7 +15,7 @@ use crate::internal::partial_solution::{DecisionLevel, PartialSolution};
1615
use crate::internal::small_vec::SmallVec;
1716
use crate::package::Package;
1817
use crate::report::DerivationTree;
19-
use crate::type_aliases::{DependencyConstraints, Map};
18+
use crate::type_aliases::{DependencyConstraints, Map, Set};
2019
use crate::version_set::VersionSet;
2120

2221
/// Current state of the PubGrub algorithm.
@@ -294,8 +293,8 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
294293
}
295294

296295
fn find_shared_ids(&self, incompat: IncompId<P, VS>) -> Set<IncompId<P, VS>> {
297-
let mut all_ids = Set::new();
298-
let mut shared_ids = Set::new();
296+
let mut all_ids = Set::default();
297+
let mut shared_ids = Set::default();
299298
let mut stack = vec![incompat];
300299
while let Some(i) = stack.pop() {
301300
if let Some((id1, id2)) = self.incompatibility_store[i].causes() {

src/internal/incompatibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! An incompatibility is a set of terms for different packages
44
//! that should never be satisfied all together.
55
6-
use std::collections::HashSet as Set;
76
use std::fmt;
87

98
use crate::internal::arena::{Arena, Id};
@@ -13,6 +12,7 @@ use crate::report::{
1312
DefaultStringReportFormatter, DerivationTree, Derived, External, ReportFormatter,
1413
};
1514
use crate::term::{self, Term};
15+
use crate::type_aliases::Set;
1616
use crate::version_set::VersionSet;
1717

1818
/// An incompatibility is a set of terms for different packages

src/type_aliases.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/// Map implementation used by the library.
66
pub type Map<K, V> = rustc_hash::FxHashMap<K, V>;
77

8+
/// Set implementation used by the library.
9+
pub type Set<V> = rustc_hash::FxHashSet<V>;
10+
811
/// Concrete dependencies picked by the library during [resolve](crate::solver::resolve)
912
/// from [DependencyConstraints].
1013
pub type SelectedDependencies<P, V> = Map<P, V>;

0 commit comments

Comments
 (0)