use std::fmt::Debug;
use xxh3::hash64_with_seed;
pub trait Hashable: PartialEq + Debug {
fn to_bytes(&self) -> Vec<u8>;
fn hash_to_index(&self, seed: u64, modulus: usize) -> usize {
hash64_with_seed(&self.to_bytes(), seed) as usize % modulus
}
fn hash_to_bytes<const U64_COUNT: usize>(&self, seed: u64) -> [u64; U64_COUNT] {
let mut randomness = [0u64; U64_COUNT];
let bytes = self.to_bytes();
for i in 0..U64_COUNT {
randomness[i] = hash64_with_seed(&bytes, seed + i as u64);
}
randomness
}
}
impl Hashable for u64 {
fn to_bytes(&self) -> Vec<u8> {
self.to_ne_bytes().to_vec()
}
}