MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / hash_string_masked

Function hash_string_masked

nodedb-array/src/coord/string_hash.rs:24–28  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

22/// (where `bound + 1` is a power of two); for arbitrary `bound`,
23/// callers should use [`hash_string_modulo`] instead.
24pub 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.

Callers 1

map_stringFunction · 0.85

Calls 4

build_hasherMethod · 0.80
writeMethod · 0.45
as_bytesMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected