Skip to content

Commit 233bc6c

Browse files
authored
Add docs on customizing string hashing (#90)
Closes #89.
1 parent 56a198c commit 233bc6c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,31 @@
123123
//! Some operations are even slightly more efficient and it consumes less memory.
124124
//! However, all this is at the costs of a less efficient resolution of symbols.
125125
//! Note that the symbols generated by the `BufferBackend` are not contiguous.
126+
//!
127+
//! ## Customizing String Hashing
128+
//!
129+
//! To ensure only one copy of each string is interned, [`StringInterner`] relies on [hashbrown]'s
130+
//! [hashmap](hashbrown::HashMap), which necessitates choosing a hashing function for hashing the
131+
//! strings.
132+
//!
133+
//! By default, [`StringInterner`] will use hashbrown's [`DefaultHashBuilder`], which should be
134+
//! appropriate for most users. However, you may customize the hash function via
135+
//! [`StringInterner`]'s second type parameter:
136+
//!
137+
//! ```
138+
//! use std::hash::RandomState;
139+
//! use string_interner::{StringInterner, DefaultBackend};
140+
//!
141+
//! // create a StringInterner with the default backend but using std's RandomState hasher
142+
//! let interned_strs: StringInterner<DefaultBackend, RandomState> = StringInterner::new();
143+
//! ```
144+
//!
145+
//! NB: as of hashbrown v0.15.2, the [`DefaultHashBuilder`] is [foldhash's
146+
//! RandomState](https://docs.rs/foldhash/latest/foldhash/fast/struct.RandomState.html), which
147+
//! relies on a one-time random initialization of shared global state; if you need stable hashes
148+
//! then you may wish to use [foldhash's
149+
//! FixedState](https://docs.rs/foldhash/latest/foldhash/fast/struct.FixedState.html) (or similar)
150+
//! instead.
126151
127152
extern crate alloc;
128153
#[cfg(feature = "std")]

0 commit comments

Comments
 (0)