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

Function hash_field_bytes

nodedb-query/src/msgpack_scan/compare.rs:19–28  ·  view source on GitHub ↗

Hash the raw bytes of a MessagePack value at `range` within `buf`. Uses a fast non-cryptographic hash suitable for hash joins and GROUP BY. For canonical-encoded documents (integers in smallest form, sorted keys), semantically equal values produce identical byte sequences and thus identical hashes.

(buf: &[u8], range: (usize, usize))

Source from the content-addressed store, hash-verified

17/// semantically equal values produce identical byte sequences and thus
18/// identical hashes.
19pub fn hash_field_bytes(buf: &[u8], range: (usize, usize)) -> u64 {
20 let slice = match buf.get(range.0..range.1) {
21 Some(s) => s,
22 None => return 0,
23 };
24 let hasher_builder = std::collections::hash_map::RandomState::new();
25 let mut hasher = hasher_builder.build_hasher();
26 hasher.write(slice);
27 hasher.finish()
28}
29
30/// Hash the raw bytes using a provided `RandomState` for consistent hashing
31/// within a single query (all docs hashed with the same seed).

Callers 1

Calls 4

build_hasherMethod · 0.80
getMethod · 0.45
writeMethod · 0.45
finishMethod · 0.45

Tested by 1