Skip to content

Commit

Permalink
use fxhash
Browse files Browse the repository at this point in the history
  • Loading branch information
lrubasze committed Oct 14, 2024
1 parent c3227e5 commit 5dc0cb7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

16 changes: 16 additions & 0 deletions radix-engine-tests/assets/blueprints/Cargo.lock

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

4 changes: 2 additions & 2 deletions radix-engine-toolkit-common/src/receipt/receipt/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl TryFrom<TransactionReceipt> for RuntimeToolkitTransactionReceipt {
.collect(),
// We get the newly minted non-fungibles from the events.
newly_minted_non_fungibles: application_events.iter().fold(
IndexSet::new(),
radix_rust::indexset!(),
|mut acc, (EventTypeIdentifier(emitter, event_name), event_data)| {
match emitter {
Emitter::Method(node_id, ModuleId::Main) => {
Expand Down Expand Up @@ -234,7 +234,7 @@ fn get_metadata_updates(
.map(|partition_state_updates| (node_id, partition_state_updates))
})
.fold(
IndexMap::new(),
radix_rust::indexmap!(),
|mut acc, (node_id, partition_state_updates)| {
acc.entry(*node_id).or_default().extend(
partition_state_updates
Expand Down
1 change: 1 addition & 0 deletions radix-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/radixdlt/radixdlt-scrypto"
serde = { workspace = true, optional = true }
hashbrown = { workspace = true, optional = true }
indexmap = { workspace = true }
fxhash = { version = "0.2.1" }

[features]
default = ["std"]
Expand Down
22 changes: 11 additions & 11 deletions radix-rust/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,19 @@ pub mod collections {
#[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
#[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
pub type DefaultHashBuilder = fxhash::FxBuildHasher;

#[cfg(feature = "alloc")]
pub use hashbrown::hash_map::*;
#[cfg(not(feature = "alloc"))]
pub use std::collections::hash_map::*;

#[cfg(not(feature = "alloc"))]
pub use fxhash::FxHashMap as ext_HashMap;
#[cfg(feature = "alloc")]
pub use hashbrown::HashMap as ext_HashMap;
#[cfg(not(feature = "alloc"))]
pub use std::collections::HashMap as ext_HashMap;

pub type HashMap<K, V, S = DefaultHashBuilder> = ext_HashMap<K, V, S>;
pub type HashMap<K, V> = ext_HashMap<K, V>;

/// Creates an empty map with capacity 0 and default Hasher
pub fn new<K, V>() -> HashMap<K, V> {
Expand Down Expand Up @@ -319,19 +319,19 @@ pub mod collections {
#[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
#[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
pub type DefaultHashBuilder = fxhash::FxBuildHasher;

#[cfg(feature = "alloc")]
pub use hashbrown::hash_set::*;
#[cfg(not(feature = "alloc"))]
pub use std::collections::hash_set::*;

#[cfg(not(feature = "alloc"))]
pub use fxhash::FxHashSet as ext_HashSet;
#[cfg(feature = "alloc")]
pub use hashbrown::HashSet as ext_HashSet;
#[cfg(not(feature = "alloc"))]
pub use std::collections::HashSet as ext_HashSet;

pub type HashSet<K> = ext_HashSet<K, DefaultHashBuilder>;
pub type HashSet<V> = ext_HashSet<V>;

/// Creates an empty set with capacity 0 and default Hasher
pub fn new<K>() -> HashSet<K> {
Expand Down Expand Up @@ -394,7 +394,7 @@ pub mod collections {
#[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
#[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
pub type DefaultHashBuilder = fxhash::FxBuildHasher;

// See https://github.com/bluss/indexmap/pull/207
// By defining an alias with a default `DefaultHashBuilder`, we ensure that this type works as `IndexMap<K, V>` and that the `FromIter` impl works in no-std.
Expand Down Expand Up @@ -456,7 +456,7 @@ pub mod collections {
#[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
#[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
pub type DefaultHashBuilder = fxhash::FxBuildHasher;

// See https://github.com/bluss/indexmap/pull/207
// By defining an alias with a default `DefaultHashBuilder`, we ensure that this type works as `IndexSet<K>` and that the `FromIter` impl works in no-std.
Expand Down Expand Up @@ -516,7 +516,7 @@ pub mod collections {
#[cfg(all(not(feature = "fuzzing"), feature = "alloc"))]
pub type DefaultHashBuilder = hashbrown::hash_map::DefaultHashBuilder;
#[cfg(all(not(feature = "fuzzing"), not(feature = "alloc")))]
pub type DefaultHashBuilder = std::collections::hash_map::RandomState;
pub type DefaultHashBuilder = fxhash::FxBuildHasher;

/// A thin wrapper around a `HashMap`, which guarantees that a `HashMap` usage will not
/// result in a non-deterministic execution (simply by disallowing the iteration over its
Expand Down

0 comments on commit 5dc0cb7

Please sign in to comment.