Skip to content

Commit 8b9fa90

Browse files
inspracmockersf
authored andcommitted
Add additional FixedHasher details in HashSet and HashMap docs (#21266)
# Objective - Make information about why to use bevy's `HashMap` and `HashSet` types more accessible. ## Solution - Copy part of the module docs of `hash_set` and `hash_map` into the struct docs as it is where people will be looking for this info.
1 parent a48805f commit 8b9fa90

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

crates/bevy_platform/src/collections/hash_map.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ pub type Entry<'a, K, V, S = FixedHasher> = hb::Entry<'a, K, V, S>;
4040
///
4141
/// A new-type is used instead of a type alias due to critical methods like [`new`](hb::HashMap::new)
4242
/// being incompatible with Bevy's choice of default hasher.
43+
///
44+
/// Unlike [`hashbrown::HashMap`], [`HashMap`] defaults to [`FixedHasher`]
45+
/// instead of [`RandomState`].
46+
/// This provides determinism by default with an acceptable compromise to denial
47+
/// of service resistance in the context of a game engine.
4348
#[repr(transparent)]
4449
pub struct HashMap<K, V, S = FixedHasher>(hb::HashMap<K, V, S>);
4550

crates/bevy_platform/src/collections/hash_set.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ pub type Entry<'a, T, S = FixedHasher> = hb::Entry<'a, T, S>;
3434
///
3535
/// A new-type is used instead of a type alias due to critical methods like [`new`](hb::HashSet::new)
3636
/// being incompatible with Bevy's choice of default hasher.
37+
///
38+
/// Unlike [`hashbrown::HashSet`], [`HashSet`] defaults to [`FixedHasher`]
39+
/// instead of [`RandomState`](crate::hash::RandomState).
40+
/// This provides determinism by default with an acceptable compromise to denial
41+
/// of service resistance in the context of a game engine.
3742
#[repr(transparent)]
3843
pub struct HashSet<T, S = FixedHasher>(hb::HashSet<T, S>);
3944

0 commit comments

Comments
 (0)