Function lib_rapid::compsci::compression::huffman::huffman_decode[][src]

pub fn huffman_decode(bitvec: &BitVec, root: &Box<Node>) -> String
Expand description

Decodes a Huffman encoded BitVec.

Arguments

  • bitvec - The assigned Huffman codes of the characters.
  • root - The Huffman tree.

Returns

A BitVec which contains the Huffman encoded string.

Examples

use lib_rapid::compsci::compression::huffman::{get_root, assign_codes, huffman_encode, huffman_decode};
use bit_vec::BitVec;
use std::collections::HashMap;

let s: &str = "Lorem Ipsum";
let root = get_root(s);
let mut bitvec = BitVec::new();
let mut char_codes: HashMap<char, BitVec> = HashMap::new();
assign_codes(&root, &mut char_codes, &mut bitvec); // Assigns codes to characters of s and stores them in char_codes.

let enc = huffman_encode(s, &mut char_codes); // Encodes the String s into enc.
let dec = huffman_decode(&bitvec, &root); // Decodes the BitVec which was created by the last line.