pub mod btree;
pub mod hash_map;
pub(crate) mod factory;
use crate::cache::Key;
use anyhow::Result;
pub trait IndexTable: Send + Sync {
fn get(&self, key: &str) -> Option<crate::cache::Key>;
fn insert(&mut self, key: &str, value: crate::cache::Key) -> Result<()>;
fn delete(&mut self, key: &str) -> Result<()>;
fn load(&mut self) -> Result<()>;
fn persist(&self) -> Result<()>;
#[cfg(test)]
fn index_type(&self) -> &str;
fn all_key_values(&self) -> Vec<(String, Key)>;
fn replace_all(&mut self, key_values: Vec<(String, Key)>) -> Result<()>;
#[cfg(feature = "write")]
fn snapshot(&self) -> Box<dyn IndexTable>;
}
#[macro_export]
macro_rules! default_persist {
($self:expr, $file_path:expr, $table:expr) => {
let file = std::fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open($file_path)?;
file.lock_exclusive()?;
let writer = std::io::BufWriter::new(&file);
bincode::serialize_into(writer, &$table)?;
file.unlock()?;
};
}