pub fn new(alphabet: &[(T, u64)]) -> Self {
        let mut alph: BTreeMap<T, HuffmanValue> = BTreeMap::new();
        let mut queue: BinaryHeap<HuffmanNode<T>> = BinaryHeap::new();
        for (symbol, freq) in alphabet.iter() {
            queue.push(HuffmanNode {
                left: None,
                right: None,
                symbol: Some(*symbol),
                frequency: *freq,
            });
        }
        for _ in 1..alphabet.len() {
            let left = queue.pop().unwrap();
            let right = queue.pop().unwrap();
            let sm_freq = left.frequency + right.frequency;
            queue.push(HuffmanNode {
                left: Some(Box::new(left)),
                right: Some(Box::new(right)),
                symbol: None,
                frequency: sm_freq,
            });
        }
        let root = queue.pop().unwrap();
        root.get_alphabet(0, 0, &root, &mut alph);
        HuffmanDictionary {
            alphabet: alph,
            root,
        }
    }
/// The list of alphabet symbols and their respective frequency should
/// be given as input
The list of alphabet symbols and their respective frequency should
be given as input
The list of alphabet symbols and their respective frequency should be given as input
pub fn new(alphabet: &[(T, u64)]) -> Self {
        let mut alph: BTreeMap<T, HuffmanValue> = BTreeMap::new();
        let mut queue: BinaryHeap<HuffmanNode<T>> = BinaryHeap::new();
        for (symbol, freq) in alphabet.iter() {
            queue.push(HuffmanNode {
                left: None,
                right: None,
                symbol: Some(*symbol),
                frequency: *freq,
            });
        }
        for _ in 1..alphabet.len() {
            let left = queue.pop().unwrap();
            let right = queue.pop().unwrap();
            let sm_freq = left.frequency + right.frequency;
            queue.push(HuffmanNode {
                left: Some(Box::new(left)),
                right: Some(Box::new(right)),
                symbol: None,
                frequency: sm_freq,
            });
        }
        let root = queue.pop().unwrap();
        root.get_alphabet(0, 0, &root, &mut alph);
        HuffmanDictionary {
            alphabet: alph,
            root,
        }
    }
pub fn new ( alphabet : & [ ( T , u64 ) ] ) -> Self { let mut alph : BTreeMap < T , HuffmanValue > = BTreeMap :: new ( ) ; let mut queue : BinaryHeap < HuffmanNode < T > > = BinaryHeap :: new ( ) ; for ( symbol , freq ) in alphabet . iter ( ) { queue . push ( HuffmanNode { left : None , right : None , symbol : Some ( * symbol ) , frequency : * freq , } ) ; } for _ in 1 .. alphabet . len ( ) { let left = queue . pop ( ) . unwrap ( ) ; let right = queue . pop ( ) . unwrap ( ) ; let sm_freq = left . frequency + right . frequency ; queue . push ( HuffmanNode { left : Some ( Box :: new ( left ) ) , right : Some ( Box :: new ( right ) ) , symbol : None , frequency : sm_freq , } ) ; } let root = queue . pop ( ) . unwrap ( ) ; root . get_alphabet ( 0 , 0 , & root , & mut alph ) ; HuffmanDictionary { alphabet : alph , root , } }
The list of alphabet symbols and their respective frequency should
be given as input
The list of alphabet symbols and their respective frequency should be given as input
alphabet
&[(T, u64)]
alphabet
&[(T, u64)]