diff --git a/Cargo.lock b/Cargo.lock index cd893650..4a63aa29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,19 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "getrandom 0.3.3", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -533,6 +546,7 @@ checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" name = "pathfinding" version = "4.14.0" dependencies = [ + "ahash", "codspeed-criterion-compat", "deprecate-until", "iai-callgrind", diff --git a/Cargo.toml b/Cargo.toml index 9ca98786..70304bba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ iai = [] num-traits = "0.2.19" indexmap = "2.11.4" rustc-hash = "2.1.1" +ahash = "0.8.11" integer-sqrt = "0.1.5" thiserror = "2.0.17" deprecate-until = "0.1.1" diff --git a/src/directed/count_paths.rs b/src/directed/count_paths.rs index 29b4533f..b1ff76fe 100644 --- a/src/directed/count_paths.rs +++ b/src/directed/count_paths.rs @@ -1,14 +1,13 @@ //! Count the total number of possible paths to reach a destination. +use ahash::AHashMap; use std::hash::Hash; -use rustc_hash::FxHashMap; - fn cached_count_paths( start: T, successors: &mut FN, success: &mut FS, - cache: &mut FxHashMap, + cache: &mut AHashMap, ) -> usize where T: Eq + Hash, @@ -66,6 +65,6 @@ where start, &mut successors, &mut success, - &mut FxHashMap::default(), + &mut AHashMap::default(), ) } diff --git a/src/noderefs.rs b/src/noderefs.rs index b11c7019..7b830f74 100644 --- a/src/noderefs.rs +++ b/src/noderefs.rs @@ -1,4 +1,4 @@ -use rustc_hash::FxHashSet; +use ahash::AHashSet; use std::hash::Hash; use std::iter::FromIterator; use std::ops::Deref; @@ -22,19 +22,19 @@ use std::ops::Deref; /// let refs: NodeRefs = NodeRefs::from_iter([&red, &blue, &green]); /// ``` #[derive(Debug, Clone, PartialEq, Eq)] -pub struct NodeRefs<'a, N>(FxHashSet<&'a N>) +pub struct NodeRefs<'a, N>(AHashSet<&'a N>) where N: Eq + Hash + Clone; impl<'a, N: Eq + Hash + Clone> FromIterator<&'a N> for NodeRefs<'a, N> { fn from_iter>(iter: T) -> Self { - NodeRefs(FxHashSet::from_iter(iter)) + NodeRefs(AHashSet::from_iter(iter)) } } impl<'a, N: Eq + Hash + Clone> From<&'a N> for NodeRefs<'a, N> { fn from(value: &'a N) -> Self { - NodeRefs(FxHashSet::from_iter([value])) + NodeRefs(AHashSet::from_iter([value])) } } @@ -57,7 +57,7 @@ impl<'a, N: Eq + Hash + Clone> IntoIterator for &'a NodeRefs<'a, N> { } impl<'a, N: Eq + Hash + Clone> Deref for NodeRefs<'a, N> { - type Target = FxHashSet<&'a N>; + type Target = AHashSet<&'a N>; fn deref(&self) -> &Self::Target { &self.0 @@ -78,7 +78,7 @@ mod tests { let refs = NodeRefs::from_iter(&nodes); assert_eq!( refs.0, - FxHashSet::from_iter([&nodes[0], &nodes[1], &nodes[2]]) + AHashSet::from_iter([&nodes[0], &nodes[1], &nodes[2]]) ); } @@ -86,7 +86,7 @@ mod tests { fn test_from_single_ref() { let node = Node(42); let refs = NodeRefs::from(&node); - assert_eq!(refs.0, FxHashSet::from_iter([&node])); + assert_eq!(refs.0, AHashSet::from_iter([&node])); } #[test] diff --git a/src/undirected/connected_components.rs b/src/undirected/connected_components.rs index 1f543d37..57d48e27 100644 --- a/src/undirected/connected_components.rs +++ b/src/undirected/connected_components.rs @@ -1,12 +1,11 @@ //! Separate components of an undirected graph into disjoint sets. +use ahash::{AHashMap, AHashSet}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::{HashMap, HashSet}; use std::hash::Hash; use std::marker::PhantomData; -use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; - /// A connected component implementation for various generic types. /// /// This structure is only useful if the default collections used by @@ -107,8 +106,7 @@ where let (_, gindices) = Self::separate_components(groups); // Pre-size the hash map to reduce reallocations let estimated_capacity = gindices.iter().filter(|&&n| n != usize::MAX).count(); - let mut gb: FxHashMap> = - FxHashMap::with_capacity_and_hasher(estimated_capacity, FxBuildHasher); + let mut gb: AHashMap> = AHashMap::with_capacity(estimated_capacity); for (i, n) in gindices .into_iter() .enumerate()