Dispatch a key through the configured placement hash, returning a deterministic 64-bit value. The caller is responsible for reducing the output into a vShard ID (e.g. `% vshard_count`).
(id: PlacementHashId, key: &[u8])
| 88 | /// deterministic 64-bit value. The caller is responsible for reducing |
| 89 | /// the output into a vShard ID (e.g. `% vshard_count`). |
| 90 | pub fn placement_hash(id: PlacementHashId, key: &[u8]) -> u64 { |
| 91 | match id { |
| 92 | PlacementHashId::Fnv1a => { |
| 93 | // FNV-1a 64-bit (offset basis 0xcbf29ce484222325, prime 0x100000001b3). |
| 94 | let mut hash: u64 = 0xcbf29ce484222325; |
| 95 | for byte in key { |
| 96 | hash ^= *byte as u64; |
| 97 | hash = hash.wrapping_mul(0x100000001b3); |
| 98 | } |
| 99 | hash |
| 100 | } |
| 101 | PlacementHashId::XxHash3 => xxhash_rust::xxh3::xxh3_64(key), |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // ── ClusterCatalog methods ─────────────────────────────────────────────────── |
| 106 |
no outgoing calls