use std::borrow::Borrow;
use std::collections::HashMap;
use super::long::Myers as MyersLong;
use super::{BitVec, Myers};
#[derive(Default, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
pub struct MyersBuilder {
ambigs: HashMap<u8, Vec<u8>>,
wildcards: Vec<u8>,
}
impl MyersBuilder {
pub fn new() -> MyersBuilder {
Self::default()
}
pub fn ambig<I, B>(&mut self, byte: u8, equivalents: I) -> &mut Self
where
I: IntoIterator<Item = B>,
B: Borrow<u8>,
{
let eq = self.ambigs.entry(byte).or_insert_with(Vec::new);
eq.extend(equivalents.into_iter().map(|b| *b.borrow()));
self
}
pub fn text_wildcard(&mut self, wildcard: u8) -> &mut Self {
self.wildcards.push(wildcard);
self
}
pub fn build_64<C, P>(&self, pattern: P) -> Myers<u64>
where
C: Borrow<u8>,
P: IntoIterator<Item = C>,
P::IntoIter: ExactSizeIterator,
{
self.build(pattern)
}
pub fn build_128<C, P>(&self, pattern: P) -> Myers<u128>
where
C: Borrow<u8>,
P: IntoIterator<Item = C>,
P::IntoIter: ExactSizeIterator,
{
self.build(pattern)
}
pub fn build<T, C, P>(&self, pattern: P) -> Myers<T>
where
T: BitVec,
C: Borrow<u8>,
P: IntoIterator<Item = C>,
P::IntoIter: ExactSizeIterator,
{
Myers::new_ambig(pattern, Some(&self.ambigs), Some(&self.wildcards))
}
pub fn build_long_64<C, P>(&self, pattern: P) -> MyersLong<u64>
where
C: Borrow<u8>,
P: IntoIterator<Item = C>,
P::IntoIter: ExactSizeIterator,
{
self.build_long(pattern)
}
pub fn build_long_128<C, P>(&self, pattern: P) -> MyersLong<u128>
where
C: Borrow<u8>,
P: IntoIterator<Item = C>,
P::IntoIter: ExactSizeIterator,
{
self.build_long(pattern)
}
pub fn build_long<T, C, P>(&self, pattern: P) -> MyersLong<T>
where
T: BitVec,
C: Borrow<u8>,
P: IntoIterator<Item = C>,
P::IntoIter: ExactSizeIterator,
{
MyersLong::new_ambig(pattern, Some(&self.ambigs), Some(&self.wildcards))
}
}