fn huffman_decode_bin_string(encoded_data: &String,encoding_map: &HashMap<u8, String>) -> Vec<u8>{
    let inverted_encoding_map = invert_encoding_map(&encoding_map);
    let mut data: Vec<u8> = Vec::new();
    let mut temp_code = String::new();
    let mut encoded_data_rev = encoded_data.chars().rev().collect::<String>();
    loop {
        match inverted_encoding_map.get(&temp_code) {
            Some(byte) => {
                temp_code = "".to_string();
                data.push(*byte);
            }
            None =>{
                match encoded_data_rev.pop() {
                    Some(code) => {
                        temp_code.push(code);
                    }
                    None => {
                        break;
                    }
                }               
            }
        }
        
    }
    return data;
}
//Decodes Huffman encoded binary string using provided encoding HashMap
Decodes Huffman encoded binary string using provided encoding HashMap
Decodes Huffman encoded binary string using provided encoding HashMap
fn huffman_decode_bin_string(encoded_data: &String,encoding_map: &HashMap<u8, String>) -> Vec<u8>{
    let inverted_encoding_map = invert_encoding_map(&encoding_map);
    let mut data: Vec<u8> = Vec::new();
    let mut temp_code = String::new();
    let mut encoded_data_rev = encoded_data.chars().rev().collect::<String>();
    loop {
        match inverted_encoding_map.get(&temp_code) {
            Some(byte) => {
                temp_code = "".to_string();
                data.push(*byte);
            }
            None =>{
                match encoded_data_rev.pop() {
                    Some(code) => {
                        temp_code.push(code);
                    }
                    None => {
                        break;
                    }
                }               
            }
        }
    }
    return data;
}
fn huffman_decode_bin_string ( encoded_data : & String , encoding_map : & HashMap < u8 , String > ) -> Vec < u8 > { let inverted_encoding_map = invert_encoding_map ( & encoding_map ) ; let mut data : Vec < u8 > = Vec :: new ( ) ; let mut temp_code = String :: new ( ) ; let mut encoded_data_rev = encoded_data . chars ( ) . rev ( ) . collect :: < String > ( ) ; loop { match inverted_encoding_map . get ( & temp_code ) { Some ( byte ) => { temp_code = " " . to_string ( ) ; data . push ( * byte ) ; } None => { match encoded_data_rev . pop ( ) { Some ( code ) => { temp_code . push ( code ) ; } None => { break ; } } } } } return data ; }
Decodes Huffman encoded binary string using provided encoding HashMap
Decodes Huffman encoded binary string using provided encoding HashMap
encoded_data
&String
encoding_map
&HashMap<u8, String>
encoded_data
&String
encoding_map
&HashMap<u8, String>