aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-26 08:36:42 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-26 08:36:42 +0200
commitc4184968ec1cf9bcf8a9305ce858d5a56d34468d (patch)
treea7bd0aa2a1797222bac61c251911f7451b78c34d /src/main.rs
parent063afb1650160c8973de51603be0acca53b39e5d (diff)
downloadhuffman-c4184968ec1cf9bcf8a9305ce858d5a56d34468d.tar.gz
huffman-c4184968ec1cf9bcf8a9305ce858d5a56d34468d.tar.bz2
huffman-c4184968ec1cf9bcf8a9305ce858d5a56d34468d.zip
Added tree to bits
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 2b4e6c5..920aee2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,30 @@
use std::env;
+use std::fs;
+use std::io::Read;
-pub mod symbols;
-// pub mod tree;
-//
-use symbols::Tree;
+pub mod tree;
+pub mod bits;
+
+use tree::Tree;
+use bits::BitSet;
fn main() {
let file_path = env::args().nth(1).unwrap();
- let tree = Tree::from_file(&file_path).unwrap();
+
+ let f = fs::File::open(file_path).unwrap();
+ let data: Vec<u8> = f.bytes().map(|x| x.unwrap()).collect();
+
+ let tree = Tree::from_data(&data);
tree.put();
+
+ let bitmap = tree.to_bit_map();
+ for (k, v) in bitmap.iter() {
+ println!("{:4} {:?}", format!("{:?}", *k as char), v);
+ }
+
+ let mut bitset = BitSet::new();
+ for byte in data {
+ bitset.concat(&bitmap[&byte]);
+ }
+ println!("{:?}", bitset);
}