mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 02:06:08 +03:00
fix(fast-graph): Use fxhash instead of ahash to make iteration order consistent (#7133)
**Description:** Some operations of `petgraph` assumes the same iteration order.
This commit is contained in:
parent
b178ff5661
commit
b13eb4c811
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4201,9 +4201,9 @@ dependencies = [
|
|||||||
name = "swc_fast_graph"
|
name = "swc_fast_graph"
|
||||||
version = "0.17.40"
|
version = "0.17.40"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"petgraph",
|
"petgraph",
|
||||||
|
"rustc-hash",
|
||||||
"swc_common",
|
"swc_common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||||
description = "Faster version of petgraph"
|
description = "Faster version of petgraph"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
include = ["Cargo.toml", "src/**/*.rs"]
|
include = ["Cargo.toml", "src/**/*.rs"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
name = "swc_fast_graph"
|
name = "swc_fast_graph"
|
||||||
repository = "https://github.com/swc-project/swc.git"
|
repository = "https://github.com/swc-project/swc.git"
|
||||||
version = "0.17.40"
|
version = "0.17.40"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ahash = "0.7.6"
|
indexmap = "1.6.1"
|
||||||
indexmap = "1.6.1"
|
petgraph = "0.6"
|
||||||
petgraph = "0.6"
|
|
||||||
swc_common = { version = "0.29.39", path = "../swc_common" }
|
swc_common = { version = "0.29.39", path = "../swc_common" }
|
||||||
|
rustc-hash = "1.1.0"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
fmt,
|
fmt,
|
||||||
hash::{self, Hash},
|
hash::{self, BuildHasherDefault, Hash},
|
||||||
iter::{Cloned, DoubleEndedIterator, FromIterator},
|
iter::{Cloned, DoubleEndedIterator, FromIterator},
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
@ -25,8 +25,11 @@ use petgraph::{
|
|||||||
},
|
},
|
||||||
Directed, Direction, EdgeType, Incoming, IntoWeightedEdge, Outgoing, Undirected,
|
Directed, Direction, EdgeType, Incoming, IntoWeightedEdge, Outgoing, Undirected,
|
||||||
};
|
};
|
||||||
|
use rustc_hash::FxHasher;
|
||||||
use swc_common::collections::AHashSet;
|
use swc_common::collections::AHashSet;
|
||||||
|
|
||||||
|
type FxBuildHasher = BuildHasherDefault<FxHasher>;
|
||||||
|
|
||||||
/// A `GraphMap` with directed edges.
|
/// A `GraphMap` with directed edges.
|
||||||
///
|
///
|
||||||
/// For example, an edge from *1* to *2* is distinct from an edge from *2* to
|
/// For example, an edge from *1* to *2* is distinct from an edge from *2* to
|
||||||
@ -59,8 +62,8 @@ pub type FastDiGraphMap<N, E> = FastGraphMap<N, E, Directed>;
|
|||||||
/// Depends on crate feature `graphmap` (default).
|
/// Depends on crate feature `graphmap` (default).
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FastGraphMap<N, E, Ty> {
|
pub struct FastGraphMap<N, E, Ty> {
|
||||||
nodes: IndexMap<N, Vec<(N, CompactDirection)>, ahash::RandomState>,
|
nodes: IndexMap<N, Vec<(N, CompactDirection)>, FxBuildHasher>,
|
||||||
edges: IndexMap<(N, N), E, ahash::RandomState>,
|
edges: IndexMap<(N, N), E, FxBuildHasher>,
|
||||||
ty: PhantomData<Ty>,
|
ty: PhantomData<Ty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,7 +587,7 @@ where
|
|||||||
Ty: EdgeType,
|
Ty: EdgeType,
|
||||||
{
|
{
|
||||||
from: N,
|
from: N,
|
||||||
edges: &'a IndexMap<(N, N), E, ahash::RandomState>,
|
edges: &'a IndexMap<(N, N), E, FxBuildHasher>,
|
||||||
iter: Neighbors<'a, N, Ty>,
|
iter: Neighbors<'a, N, Ty>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user