From deaacd73fb6134b36aed6ee9bb0705a586832fab Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 16 Mar 2020 09:50:10 +0900 Subject: [PATCH] Reuse same hash function for ints and floats. The code was simply duplicated before, for no real reason. --- src/hash.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/hash.rs b/src/hash.rs index 362b560..d923da2 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -24,13 +24,6 @@ pub fn hash_u64(n: u64, seed: u64) -> u64 { /// Generally use n for getting a bunch of different random /// numbers, and use seed to vary between runs. pub fn hash_u32_to_f32(n: u32, seed: u32) -> f32 { - let mut hash = n; - for _ in 0..3 { - hash = hash.wrapping_mul(1_936_502_639); - hash ^= hash.wrapping_shr(16); - hash ^= seed; - } const INV_MAX: f32 = 1.0 / std::u32::MAX as f32; - - hash as f32 * INV_MAX + hash_u32(n, seed) as f32 * INV_MAX }