[−][src]Function huff_coding::comp::decompress
pub fn decompress<L: HuffLetter>(comp_data: &CompressData<L>) -> Vec<L>
Decompress the provided CompressData<L>
into a Vec<L>
.
How it works
- Start at the root branch of the tree
- Go bit by bit through the provided
CompressData
's comp_bytes - Every time a 0 is found, go to the left branch, and every 1 means going to the right branch
- When it finally a letter branch is found, it push the letter into the vec, and return to the root branch.
Example
use huff_coding::prelude::{ compress, decompress }; let bytes = b"deefff"; let nums = &[-100, -101, -101, -102, -102, -102]; let chars = &['d', 'e', 'e', 'f', 'f', 'f']; let strs = &["dee", "e", "e", "ef", "ef", "ef"]; let comp_bytes = compress(bytes); let comp_nums = compress(nums); let comp_chars = compress(chars); let comp_strs = compress(strs); assert_eq!(bytes.to_vec(), decompress(&comp_bytes)); assert_eq!(nums.to_vec(), decompress(&comp_nums)); assert_eq!(chars.to_vec(), decompress(&comp_chars)); assert_eq!(strs.to_vec(), decompress(&comp_strs));