Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions src/directed/count_paths.rs
Original file line number Diff line number Diff line change
@@ -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<T, FN, IN, FS>(
start: T,
successors: &mut FN,
success: &mut FS,
cache: &mut FxHashMap<T, usize>,
cache: &mut AHashMap<T, usize>,
) -> usize
where
T: Eq + Hash,
Expand Down Expand Up @@ -66,6 +65,6 @@ where
start,
&mut successors,
&mut success,
&mut FxHashMap::default(),
&mut AHashMap::default(),
)
}
14 changes: 7 additions & 7 deletions src/noderefs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_hash::FxHashSet;
use ahash::AHashSet;
use std::hash::Hash;
use std::iter::FromIterator;
use std::ops::Deref;
Expand All @@ -22,19 +22,19 @@ use std::ops::Deref;
/// let refs: NodeRefs<N> = 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<T: IntoIterator<Item = &'a N>>(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]))
}
}

Expand All @@ -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
Expand All @@ -78,15 +78,15 @@ 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]])
);
}

#[test]
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]
Expand Down
6 changes: 2 additions & 4 deletions src/undirected/connected_components.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<usize, FxHashSet<N>> =
FxHashMap::with_capacity_and_hasher(estimated_capacity, FxBuildHasher);
let mut gb: AHashMap<usize, AHashSet<N>> = AHashMap::with_capacity(estimated_capacity);
for (i, n) in gindices
.into_iter()
.enumerate()
Expand Down