use std::hash::{DefaultHasher, Hash, Hasher};
use indexmap::IndexSet;
pub fn rendezvous_select<V: Hash, T: Hash + Copy>(value: &V, options: &IndexSet<T>) -> T {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
options
.iter()
.map(|x| {
let mut h = hasher.clone();
x.hash(&mut h);
(h.finish(), x)
})
.max_by_key(|x| x.0)
.map(|x| x.1)
.expect("Collection not empty")
.to_owned()
}
pub fn index_select<T: Copy>(i: &u64, s: &IndexSet<T>) -> T {
let idx = *i as usize;
*s.get_index(idx % s.len())
.expect("Expected a non-empty set")
}