fix: ensure `ConsistenHasher` is consistent
The std `DefaultHasher` is NOT guaranteed to stay the same, so let's directly use the `SipHasher13` which at the moment (2021-11-15) is used by the standard lib. Fixes #3063.pull/24376/head
parent
3cd7d2eda2
commit
4e71de508e
|
@ -792,6 +792,7 @@ dependencies = [
|
|||
"ordered-float 2.8.0",
|
||||
"percent-encoding",
|
||||
"regex",
|
||||
"siphasher",
|
||||
"snafu",
|
||||
"test_helpers",
|
||||
"time 0.1.0",
|
||||
|
@ -3974,6 +3975,12 @@ dependencies = [
|
|||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.5"
|
||||
|
|
|
@ -13,6 +13,7 @@ observability_deps = { path = "../observability_deps" }
|
|||
ordered-float = "2"
|
||||
percent-encoding = "2.1.0"
|
||||
regex = "1.4"
|
||||
siphasher = "0.3"
|
||||
snafu = "0.6"
|
||||
time = { path = "../time" }
|
||||
uuid = { version = "0.8", features = ["v4"] }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use siphasher::sip::SipHasher13;
|
||||
|
||||
/// A ConsistentHasher implements a simple consistent hashing mechanism
|
||||
/// that maps a point to the nearest "node" N.
|
||||
///
|
||||
|
@ -47,7 +48,7 @@ where
|
|||
}
|
||||
|
||||
fn hash<H: Hash>(h: H) -> u64 {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
let mut hasher = SipHasher13::new();
|
||||
h.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
@ -86,9 +87,6 @@ where
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_roundtrip() {}
|
||||
|
||||
#[test]
|
||||
fn test_consistent_hasher() {
|
||||
let ch = ConsistentHasher::new(&[10, 20, 30, 40]);
|
||||
|
|
Loading…
Reference in New Issue