use super::types::Compression;
use lru::LruCache;
#[derive(Debug, Copy, Clone)]
pub struct BloomConfig {
pub bitmap_size: u32,
pub items_count: usize,
}
impl Default for BloomConfig {
fn default() -> Self {
return Self {
bitmap_size: 1_000_000,
items_count: 1_000_000,
};
}
}
#[derive(Debug, Copy, Clone)]
pub struct WriteOptions {
pub compression: Compression,
pub flush_every: usize,
pub bloom: BloomConfig,
}
impl WriteOptions {
pub fn new() -> Self {
Self::default()
}
pub fn compression(&mut self, compression: Compression) -> &mut Self {
self.compression = compression;
self
}
pub fn flush_every(&mut self, flush_every: usize) -> &mut Self {
self.flush_every = flush_every;
self
}
pub fn bloom(&mut self, bloom: BloomConfig) -> &mut Self {
self.bloom = bloom;
self
}
}
impl Default for WriteOptions {
fn default() -> Self {
WriteOptions {
compression: Compression::None,
flush_every: 4096,
bloom: BloomConfig::default(),
}
}
}
#[derive(Copy, Clone, Debug)]
pub enum ReadCache {
Blocks(usize),
Unbounded,
}
impl ReadCache {
pub fn lru<K, V>(&self) -> LruCache<K, V>
where
K: std::cmp::Eq + std::hash::Hash,
{
match self {
Self::Blocks(b) => LruCache::new(*b),
Self::Unbounded => LruCache::unbounded(),
}
}
}
impl Default for ReadCache {
fn default() -> Self {
Self::Unbounded
}
}
#[derive(Copy, Clone, Debug)]
pub struct ReadOptions {
pub cache: Option<ReadCache>,
pub use_mmap: bool,
pub thread_buckets: Option<usize>,
pub use_bloom: bool,
}
impl ReadOptions {
pub fn new() -> Self {
Self::default()
}
pub fn cache(&mut self, cache: Option<ReadCache>) -> &mut Self {
self.cache = cache;
self
}
pub fn use_mmap(&mut self, use_mmap: bool) -> &mut Self {
self.use_mmap = use_mmap;
self
}
pub fn use_bloom(&mut self, use_bloom: bool) -> &mut Self {
self.use_bloom = use_bloom;
self
}
pub fn thread_buckets(&mut self, thread_buckets: Option<usize>) -> &mut Self {
self.thread_buckets = thread_buckets;
self
}
}
impl Default for ReadOptions {
fn default() -> Self {
Self {
cache: Some(ReadCache::default()),
use_mmap: true,
thread_buckets: Some(num_cpus::get()),
use_bloom: true,
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct GetOptions {
pub use_bloom: bool,
}
impl GetOptions {
pub fn new() -> Self {
Self::default()
}
pub fn use_bloom(&mut self, use_bloom: bool) -> &mut Self {
self.use_bloom = use_bloom;
self
}
}
impl Default for GetOptions {
fn default() -> Self {
Self { use_bloom: true }
}
}