Skip to content

Commit db9e5b8

Browse files
authored
Swap ahash with foldhash (#1418)
* Use foldhash instead of ahash * Make things build again
1 parent 5ca23e1 commit db9e5b8

File tree

11 files changed

+27
-66
lines changed

11 files changed

+27
-66
lines changed

Cargo.lock

Lines changed: 4 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repository = "https://github.com/Qiskit/rustworkx"
2525
license = "Apache-2.0"
2626

2727
[workspace.dependencies]
28-
ahash = "0.8.6"
28+
foldhash = "0.1.5"
2929
fixedbitset = "0.5.7"
3030
indexmap = { version = ">=1.9, <3", features = ["rayon"] }
3131
ndarray = { version = "0.16.1", features = ["rayon"] }
@@ -42,7 +42,7 @@ name = "rustworkx"
4242
crate-type = ["cdylib"]
4343

4444
[dependencies]
45-
ahash.workspace = true
45+
foldhash.workspace = true
4646
fixedbitset.workspace = true
4747
hashbrown.workspace = true
4848
indexmap.workspace = true

rustworkx-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repository.workspace = true
1212
license.workspace = true
1313

1414
[dependencies]
15-
ahash.workspace = true
15+
foldhash.workspace = true
1616
fixedbitset.workspace = true
1717
hashbrown.workspace = true
1818
indexmap.workspace = true

rustworkx-core/src/coloring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// License for the specific language governing permissions and limitations
1111
// under the License.
1212

13-
use ahash::RandomState;
13+
use foldhash::fast::RandomState;
1414
use priority_queue::PriorityQueue;
1515
use std::cmp::Ordering;
1616
use std::cmp::Reverse;

rustworkx-core/src/connectivity/johnson_simple_cycles.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// License for the specific language governing permissions and limitations
1111
// under the License.
1212

13-
use ahash::RandomState;
13+
use foldhash::fast::RandomState;
1414
use hashbrown::{HashMap, HashSet};
1515
use indexmap::IndexSet;
1616
use std::hash::Hash;
@@ -93,7 +93,7 @@ fn unblock(
9393
#[allow(clippy::too_many_arguments)]
9494
fn process_stack(
9595
start_node: NodeIndex,
96-
stack: &mut Vec<(NodeIndex, IndexSet<NodeIndex, ahash::RandomState>)>,
96+
stack: &mut Vec<(NodeIndex, IndexSet<NodeIndex, foldhash::fast::RandomState>)>,
9797
path: &mut Vec<NodeIndex>,
9898
closed: &mut HashSet<NodeIndex>,
9999
blocked: &mut HashSet<NodeIndex>,
@@ -117,7 +117,7 @@ fn process_stack(
117117
next_node,
118118
subgraph
119119
.neighbors(next_node)
120-
.collect::<IndexSet<NodeIndex, ahash::RandomState>>(),
120+
.collect::<IndexSet<NodeIndex, foldhash::fast::RandomState>>(),
121121
));
122122
closed.remove(&next_node);
123123
blocked.insert(next_node);
@@ -197,7 +197,7 @@ impl SimpleCycleIter {
197197
return Some(vec![cycle_node]);
198198
}
199199
// Restore previous state if it exists
200-
let mut stack: Vec<(NodeIndex, IndexSet<NodeIndex, ahash::RandomState>)> =
200+
let mut stack: Vec<(NodeIndex, IndexSet<NodeIndex, foldhash::fast::RandomState>)> =
201201
std::mem::take(&mut self.stack);
202202
let mut path: Vec<NodeIndex> = std::mem::take(&mut self.path);
203203
let mut closed: HashSet<NodeIndex> = std::mem::take(&mut self.closed);
@@ -258,7 +258,7 @@ impl SimpleCycleIter {
258258
self.start_node,
259259
subgraph
260260
.neighbors(self.start_node)
261-
.collect::<IndexSet<NodeIndex, ahash::RandomState>>(),
261+
.collect::<IndexSet<NodeIndex, foldhash::fast::RandomState>>(),
262262
)];
263263
if let Some(res) = process_stack(
264264
self.start_node,

rustworkx-core/src/connectivity/min_cut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ where
3939
F: FnMut(G::EdgeRef) -> K,
4040
K: Copy + Ord + Zero + AddAssign,
4141
{
42-
let mut pq = PriorityQueue::<G::NodeId, K, ahash::RandomState>::from(
42+
let mut pq = PriorityQueue::<G::NodeId, K, foldhash::fast::RandomState>::from(
4343
graph
4444
.node_identifiers()
4545
.map(|nx| (nx, K::zero()))

rustworkx-core/src/dictmap.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
// under the License.
1212

1313
//! This module contains the [`DictMap`] type alias which is a combination of
14-
//! [`IndexMap`] and [`AHash`].
14+
//! [`IndexMap`] and [`Foldhash`].
1515
//!
1616
//! It is used as a return type for rustworkx for compatibility
1717
//! with Python's dict which preserves insertion order.
1818
//!
19-
//! [`AHash`]: https://crates.io/crates/ahash
19+
//! [`Foldhash`]: https://crates.io/crates/foldhash
2020
2121
use indexmap::IndexMap;
2222

2323
/// Convenient alias to build an [`IndexMap`] using a custom hasher.
24-
/// For the moment, we use ahash which is the default hasher
24+
/// For the moment, we use foldhash which is the default hasher
2525
/// for [`HashMap`], another hashmap we use.
2626
///
2727
/// [`HashMap`]: https://docs.rs/hashbrown/0.11.2/hashbrown/hash_map/struct.HashMap.html
28-
pub type DictMap<K, V> = IndexMap<K, V, ahash::RandomState>;
28+
pub type DictMap<K, V> = IndexMap<K, V, foldhash::fast::RandomState>;
2929

3030
pub trait InitWithHasher {
3131
fn new() -> Self
@@ -40,11 +40,11 @@ pub trait InitWithHasher {
4040
impl<K, V> InitWithHasher for DictMap<K, V> {
4141
#[inline]
4242
fn new() -> Self {
43-
indexmap::IndexMap::with_capacity_and_hasher(0, ahash::RandomState::default())
43+
indexmap::IndexMap::with_capacity_and_hasher(0, foldhash::fast::RandomState::default())
4444
}
4545

4646
#[inline]
4747
fn with_capacity(n: usize) -> Self {
48-
indexmap::IndexMap::with_capacity_and_hasher(n, ahash::RandomState::default())
48+
indexmap::IndexMap::with_capacity_and_hasher(n, foldhash::fast::RandomState::default())
4949
}
5050
}

rustworkx-core/src/graph_ext/contraction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ where
471471

472472
fn contract_stable<G, F, E: Error>(
473473
graph: &mut G,
474-
mut nodes: IndexSet<G::NodeId, ahash::RandomState>,
474+
mut nodes: IndexSet<G::NodeId, foldhash::fast::RandomState>,
475475
weight: G::NodeWeight,
476476
weight_combo_fn: Option<F>,
477477
) -> Result<G::NodeId, E>
@@ -499,7 +499,7 @@ where
499499
Ok(node_index)
500500
}
501501

502-
fn can_contract<G>(graph: G, nodes: &IndexSet<G::NodeId, ahash::RandomState>) -> bool
502+
fn can_contract<G>(graph: G, nodes: &IndexSet<G::NodeId, foldhash::fast::RandomState>) -> bool
503503
where
504504
G: Data + Visitable + IntoEdgesDirected,
505505
G::NodeId: Eq + Hash,
@@ -536,7 +536,7 @@ type NoCallback<E> = Option<fn(&E, &E) -> Result<E, Infallible>>;
536536
fn add_edges<G, F, E>(
537537
graph: &mut G,
538538
new_node: G::NodeId,
539-
nodes: &IndexSet<G::NodeId, ahash::RandomState>,
539+
nodes: &IndexSet<G::NodeId, foldhash::fast::RandomState>,
540540
mut weight_combo_fn: Option<F>,
541541
) -> Result<(), E>
542542
where

rustworkx-core/src/shortest_path/all_shortest_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::dictmap::*;
3838
/// use rustworkx_core::dictmap::DictMap;
3939
/// use rustworkx_core::shortest_path::all_shortest_paths;
4040
/// use rustworkx_core::Result;
41-
/// use ahash::HashSet;
41+
/// use foldhash::HashSet;
4242
///
4343
/// let mut graph : Graph<(), (), Directed>= Graph::new();
4444
/// let a = graph.add_node(()); // node with no weight

rustworkx-core/tests/graph_ext/contraction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// License for the specific language governing permissions and limitations
1111
// under the License.
1212

13-
use ahash::HashSet;
13+
use foldhash::HashSet;
1414
use hashbrown::HashMap;
1515
use petgraph::data::Build;
1616
use petgraph::visit::{

0 commit comments

Comments
 (0)