use std::fmt::Display;
use crate::bits::BitFieldVec;
use crate::func::VBuilder;
use crate::func::shard_edge::ShardEdge;
#[derive(clap::ValueEnum, Clone, Debug)]
pub enum HashTypes {
U8,
U16,
U32,
U64,
}
impl Display for HashTypes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
HashTypes::U8 => write!(f, "u8"),
HashTypes::U16 => write!(f, "u16"),
HashTypes::U32 => write!(f, "u32"),
HashTypes::U64 => write!(f, "u64"),
}
}
}
#[derive(clap::Args, Debug)]
pub struct BuilderArgs {
#[arg(short, long)]
pub threads: Option<usize>,
#[arg(short, long)]
pub offline: bool,
#[arg(short, long)]
pub check_dups: bool,
#[arg(long)]
pub seed: Option<u64>,
#[arg(long, default_value_t = 0.001)]
pub eps: f64,
#[arg(long)]
pub low_mem: bool,
#[arg(long, conflicts_with = "low_mem")]
pub high_mem: bool,
}
impl BuilderArgs {
pub fn configure<D: Send + Sync, S, E: ShardEdge<S, 3>>(
&self,
builder: VBuilder<D, S, E>,
) -> VBuilder<D, S, E> {
let mut builder = builder
.offline(self.offline)
.check_dups(self.check_dups)
.eps(self.eps);
if let Some(seed) = self.seed {
builder = builder.seed(seed);
}
if let Some(threads) = self.threads {
builder = builder.max_num_threads(threads);
}
if self.low_mem {
builder = builder.low_mem(true);
}
if self.high_mem {
builder = builder.low_mem(false);
}
builder
}
pub fn to_builder(&self) -> VBuilder<BitFieldVec<Box<[usize]>>> {
self.configure(VBuilder::default())
}
}