use super::*;
use std::hash::Hasher;
use std::sync::atomic::{AtomicUsize, Ordering};
impl<H> SelectionAlgorithm for H
where
H: Default + Hasher,
{
fn new() -> Self {
H::default()
}
fn next(&self, key: &[u8]) -> u64 {
let mut hasher = H::default();
hasher.write(key);
hasher.finish()
}
}
pub struct RoundRobin(AtomicUsize);
impl SelectionAlgorithm for RoundRobin {
fn new() -> Self {
Self(AtomicUsize::new(0))
}
fn next(&self, _key: &[u8]) -> u64 {
self.0.fetch_add(1, Ordering::Relaxed) as u64
}
}
pub struct Random;
impl SelectionAlgorithm for Random {
fn new() -> Self {
Self
}
fn next(&self, _key: &[u8]) -> u64 {
use rand::Rng;
let mut rng = rand::thread_rng();
rng.gen()
}
}