Function lib_rapid::compsci::compression::huffman::huffman_encode
source · pub fn huffman_encode(s: &str, char_codes: &HashMap<char, BitVec>) -> BitVec
Expand description
Encodes a string.
Arguments
s
- The string to be encoded.char_codes
- The assigned Huffman codes of the characters.
Returns
A BitVec which contains the Huffman encoded string.
Examples
use lib_rapid::compsci::compression::huffman::{get_root, assign_codes, huffman_encode};
use bit_vec::BitVec;
use std::collections::HashMap;
let s = "Lorem Ipsum";
let root = get_root(s);
let mut char_codes:HashMap<char, BitVec> = HashMap::new();
assign_codes(&root, &mut char_codes, &mut BitVec::new()); // Assigns codes to characters of s and stores them in char_codes.
let enc = huffman_encode(s, &char_codes); // Encodes the String s into enc.