|
|
|
@ -22,17 +22,12 @@ pub trait Indexable<I: HashableId>: Clone + Send {
|
|
|
|
|
|
|
|
|
|
impl<I: HashableId, T: Indexable<I>> MemCache<I, T> {
|
|
|
|
|
pub fn new() -> MemCache<I, T> {
|
|
|
|
|
MemCache::with_capacity(unsafe { NonZeroUsize::new_unchecked(256) })
|
|
|
|
|
MemCache::with_capacity(NonZeroUsize::new(1024).unwrap())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_capacity(capacity: NonZeroUsize) -> MemCache<I, T> {
|
|
|
|
|
let capacity = capacity.get();
|
|
|
|
|
let mut lines = Vec::with_capacity(capacity);
|
|
|
|
|
for _ in 0..capacity {
|
|
|
|
|
lines.push(RwLock::new(None));
|
|
|
|
|
}
|
|
|
|
|
MemCache {
|
|
|
|
|
lines,
|
|
|
|
|
lines: (0..capacity.get()).map(|_| RwLock::new(None)).collect(),
|
|
|
|
|
_phantom: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|