use crate::bitvec::prelude::{BitVec, Msb0};
use super::letter::HuffLetter;
use std::cmp::Ordering;
#[derive(Debug, Eq, Clone)]
pub struct HuffLeaf<L: HuffLetter>{
letter: Option<L>,
weight: usize,
code: Option<BitVec<Msb0, u8>>,
}
impl<L: HuffLetter> Ord for HuffLeaf<L> {
fn cmp(&self, other: &Self) -> Ordering {
self.weight.cmp(&other.weight)
}
}
impl<L: HuffLetter> PartialOrd for HuffLeaf<L> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<L: HuffLetter> PartialEq for HuffLeaf<L>{
fn eq(&self, other: &Self) -> bool {
self.weight == other.weight
}
}
impl<L: HuffLetter> HuffLeaf<L>{
pub fn new(letter: Option<L>, weight: usize) -> Self{
HuffLeaf{
letter,
weight,
code: None,
}
}
pub fn letter(&self) -> Option<&L>{
self.letter.as_ref()
}
pub fn weight(&self) -> usize{
self.weight
}
pub fn code(&self) -> Option<&BitVec<Msb0, u8>>{
self.code.as_ref()
}
pub fn set_code(&mut self, code: BitVec<Msb0, u8>){
self.code = Some(code);
}
}