Hash `s` into `[0, modulus)` via modulo. Used by tile-index bucketing where the extent isn't necessarily a power of two.
(s: &str, modulus: u64)
| 30 | /// Hash `s` into `[0, modulus)` via modulo. Used by tile-index |
| 31 | /// bucketing where the extent isn't necessarily a power of two. |
| 32 | pub fn hash_string_modulo(s: &str, modulus: u64) -> u64 { |
| 33 | let mut h = std::collections::hash_map::RandomState::new().build_hasher(); |
| 34 | h.write(s.as_bytes()); |
| 35 | if modulus <= 1 { |
| 36 | 0 |
| 37 | } else { |
| 38 | h.finish() % modulus |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | #[cfg(test)] |
| 43 | mod tests { |
no test coverage detected