Hash `s` into the range `[0, bound]` (inclusive) by masking with `bound`. Caller passes `bound = (1 << bits) - 1` for power-of-two curve buckets, or `extent - 1` style values for tile bucketing (where `bound + 1` is a power of two); for arbitrary `bound`, callers should use [`hash_string_modulo`] instead.
(s: &str, bound: u64)
| 22 | /// (where `bound + 1` is a power of two); for arbitrary `bound`, |
| 23 | /// callers should use [`hash_string_modulo`] instead. |
| 24 | pub fn hash_string_masked(s: &str, bound: u64) -> u64 { |
| 25 | let mut h = std::collections::hash_map::RandomState::new().build_hasher(); |
| 26 | h.write(s.as_bytes()); |
| 27 | if bound == 0 { 0 } else { h.finish() & bound } |
| 28 | } |
| 29 | |
| 30 | /// Hash `s` into `[0, modulus)` via modulo. Used by tile-index |
| 31 | /// bucketing where the extent isn't necessarily a power of two. |
no test coverage detected