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

Function hash_string_modulo

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

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)

Source from the content-addressed store, hash-verified

30/// Hash `s` into `[0, modulus)` via modulo. Used by tile-index
31/// bucketing where the extent isn't necessarily a power of two.
32pub 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)]
43mod tests {

Callers 1

tile_indices_for_cellFunction · 0.85

Calls 4

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

Tested by

no test coverage detected