use bustle::*; use std::collections::HashMap; use std::sync::Mutex; #[derive(Clone)] struct Table(std::sync::Arc>>); impl Collection for Table where K: Send + From + Copy + 'static + std::hash::Hash + Eq, { type Handle = Self; fn with_capacity(capacity: usize) -> Self { Self(std::sync::Arc::new(Mutex::new(HashMap::with_capacity( capacity, )))) } fn pin(&self) -> Self::Handle { self.clone() } } impl CollectionHandle for Table where K: Send + From + Copy + 'static + std::hash::Hash + Eq, { type Key = K; fn get(&mut self, key: &Self::Key) -> bool { self.0.lock().unwrap().get(key).is_some() } fn insert(&mut self, key: &Self::Key) -> bool { self.0.lock().unwrap().insert(*key, ()).is_none() } fn remove(&mut self, key: &Self::Key) -> bool { self.0.lock().unwrap().remove(key).is_some() } fn update(&mut self, key: &Self::Key) -> bool { use std::collections::hash_map::Entry; let mut map = self.0.lock().unwrap(); if let Entry::Occupied(mut e) = map.entry(*key) { e.insert(()); true } else { false } } } fn main() { tracing_subscriber::fmt::init(); for n in 1..=num_cpus::get() { Workload::new(n, Mix::read_heavy()).run::>(); } }