use std::alloc::{alloc, Layout}; use const_lru::ConstLru; use num_traits::{PrimInt, Unsigned}; use super::traits::Insert; #[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)] pub struct BigStruct { pub a1: [usize; 32], pub a2: [usize; 32], pub a3: [usize; 32], pub a4: [usize; 32], } impl From for BigStruct { fn from(value: u8) -> Self { let mut s: Self = Default::default(); s.a3[0] = value.into(); s } } impl From for BigStruct { fn from(value: u16) -> Self { let mut s: Self = Default::default(); s.a3[0] = value.into(); s } } pub fn fill_up_all_u8_keys, K: From, V: From>(container: &mut C) { for k in 0..u8::MAX { container.insert_no_ret(k.into(), k.into()); } } pub fn fill_up_all_10k_keys, K: From, V: From>(container: &mut C) { for k in 0..10_000 { container.insert_no_ret(k.into(), k.into()); } } pub fn boxed_const_lru( ) -> Box> { let layout = Layout::new::>(); unsafe { let ptr = alloc(layout) as *mut ConstLru; ConstLru::init_at_alloc(ptr); Box::from_raw(ptr) } }