Introduce a collections crate w/ deterministic hashmap, hashset in tests
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
5ec003530f
commit
1a91aa8194
8 changed files with 59 additions and 42 deletions
10
crates/collections/Cargo.toml
Normal file
10
crates/collections/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "collections"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
test-support = ["seahash"]
|
||||
|
||||
[dependencies]
|
||||
seahash = { version = "4.1", optional = true }
|
26
crates/collections/src/lib.rs
Normal file
26
crates/collections/src/lib.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#[cfg(feature = "test-support")]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct DeterministicState;
|
||||
|
||||
#[cfg(feature = "test-support")]
|
||||
impl std::hash::BuildHasher for DeterministicState {
|
||||
type Hasher = seahash::SeaHasher;
|
||||
|
||||
fn build_hasher(&self) -> Self::Hasher {
|
||||
seahash::SeaHasher::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "test-support")]
|
||||
pub type HashMap<K, V> = std::collections::HashMap<K, V, DeterministicState>;
|
||||
|
||||
#[cfg(feature = "test-support")]
|
||||
pub type HashSet<T> = std::collections::HashSet<T, DeterministicState>;
|
||||
|
||||
#[cfg(not(feature = "test-support"))]
|
||||
pub type HashMap<K, V> = std::collections::HashMap<K, V>;
|
||||
|
||||
#[cfg(not(feature = "test-support"))]
|
||||
pub type HashSet<T> = std::collections::HashSet<T>;
|
||||
|
||||
pub use std::collections::*;
|
Loading…
Add table
Add a link
Reference in a new issue