use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tokio::sync::RwLock;
#[derive(Clone, Default)]
pub struct IndexedFiles {
inner: Arc<RwLock<HashMap<PathBuf, Vec<String>>>>,
}
impl IndexedFiles {
pub fn new() -> Self {
Self::default()
}
pub async fn record(&self, path: PathBuf, chunk_ids: Vec<String>) {
self.inner.write().await.insert(path, chunk_ids);
}
pub async fn take(&self, path: &Path) -> Option<Vec<String>> {
self.inner.write().await.remove(path)
}
#[cfg(test)]
pub async fn len(&self) -> usize {
self.inner.read().await.len()
}
#[cfg(test)]
pub async fn is_empty(&self) -> bool {
self.inner.read().await.is_empty()
}
}