pub trait HashFunction {
// Required method
fn hash(&self, key: &str) -> i64;
}Expand description
Trait for hashing string keys to long integer values
Implementations of this trait provide different hash algorithms that can be used in consistent hashing rings to distribute keys across nodes.
§Example
use rocketmq_common::common::consistenthash::HashFunction;
struct SimpleHashFunction;
impl HashFunction for SimpleHashFunction {
fn hash(&self, key: &str) -> i64 {
// Simple example: sum of character codes
key.chars().map(|c| c as i64).sum()
}
}
let hasher = SimpleHashFunction;
let hash_value = hasher.hash("test-key");
assert!(hash_value > 0);Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".