diff --git a/src/in_memory_blockstore.rs b/src/in_memory_blockstore.rs index 956a2be..302cff7 100644 --- a/src/in_memory_blockstore.rs +++ b/src/in_memory_blockstore.rs @@ -4,6 +4,7 @@ use dashmap::DashMap; use crate::{convert_cid, Blockstore, Result}; /// Simple in-memory blockstore implementation. +#[derive(Clone, Debug)] pub struct InMemoryBlockstore { map: DashMap, Vec>, } @@ -16,6 +17,16 @@ impl InMemoryBlockstore { } } + /// Get the number of elements in the blockstore + pub fn len(&self) -> usize { + self.map.len() + } + + /// Check if the blockstore is empty + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + fn get_cid(&self, cid: &CidGeneric) -> Result>> { Ok(self.map.get(cid).as_deref().cloned()) } diff --git a/src/lru_blockstore.rs b/src/lru_blockstore.rs index 6d8a3f7..419178a 100644 --- a/src/lru_blockstore.rs +++ b/src/lru_blockstore.rs @@ -6,6 +6,7 @@ use lru::LruCache; use crate::{convert_cid, Blockstore, Result}; /// An LRU cached [`Blockstore`]. +#[derive(Debug)] pub struct LruBlockstore { cache: Mutex, Vec>>, } @@ -17,6 +18,16 @@ impl LruBlockstore { cache: Mutex::new(LruCache::new(capacity)), } } + + /// Get the number of elements in the blockstore + pub fn len(&self) -> usize { + self.cache.lock().expect("lock failed").len() + } + + /// Check if the blockstore is empty + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } impl Blockstore for LruBlockstore {