use std::cmp::Eq;
use std::hash::Hash;
use probminhash::probminhasher::*;
pub trait LabelT: Send + Sync + Eq + Hash + Clone + Default + std::fmt::Debug + sig::Sig {}
impl LabelT for u8 {}
impl LabelT for u16 {}
impl LabelT for u32 {}
impl LabelT for u64 {}
impl LabelT for i32 {}
impl LabelT for i16 {}
impl LabelT for String {}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Default)]
pub struct NElabel<Nlabel, Elabel>(pub(crate) Nlabel, pub(crate) Elabel);
impl<Nlabel, Elabel> sig::Sig for NElabel<Nlabel, Elabel>
where
Nlabel: LabelT,
Elabel: LabelT,
{
fn get_sig(&self) -> Vec<u8> {
let mut s = self.0.get_sig().clone();
s.append(&mut self.1.get_sig().clone());
s
}
}
#[derive(Clone, Debug)]
pub struct Nweight<Nlabel> {
labels: Vec<Nlabel>,
}
impl<Nlabel> Nweight<Nlabel>
where
Nlabel: LabelT,
{
pub fn new(labels: Vec<Nlabel>) -> Self {
Nweight { labels }
}
pub fn has_label(&self, label: &Nlabel) -> bool {
self.labels.iter().any(|l| l == label)
}
pub fn get_labels(&self) -> &[Nlabel] {
&self.labels
}
}
pub struct Eweight<Elabel> {
label: Option<Elabel>,
weight: f32,
}
impl<Elabel> Eweight<Elabel>
where
Elabel: LabelT,
{
pub fn new(label: Option<Elabel>, weight: f32) -> Self {
Eweight { label, weight }
}
pub fn get_label(&self) -> Option<&Elabel> {
self.label.as_ref()
}
pub fn get_weight(&self) -> f32 {
self.weight
}
}
impl<Elabel> Default for Eweight<Elabel>
where
Elabel: LabelT,
{
fn default() -> Self {
Eweight {
label: None,
weight: 1.,
}
}
}
pub trait HasNweight<Nlabel: LabelT> {
fn get_nweight(&self) -> &Nweight<Nlabel>;
}
pub trait HasEweight<Elabel: LabelT> {
fn get_eweight(&self) -> &Eweight<Elabel>;
}