Convert to lib
This commit is contained in:
5
src/lib.rs
Normal file
5
src/lib.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
// https://marknelson.us/posts/2014/10/19/data-compression-with-arithmetic-coding.html
|
||||
#[allow(non_snake_case)]
|
||||
pub mod modelA;
|
||||
|
||||
mod bit_buffer;
|
||||
50
src/main.rs
50
src/main.rs
@@ -1,50 +0,0 @@
|
||||
// https://marknelson.us/posts/2014/10/19/data-compression-with-arithmetic-coding.html
|
||||
#[allow(non_snake_case)]
|
||||
mod modelA;
|
||||
|
||||
mod bit_buffer;
|
||||
//mod model;
|
||||
use modelA::ModelA;
|
||||
|
||||
fn main() {
|
||||
let data = b"
|
||||
I'd just like to interject for a moment. What you're refering to as Linux, is in fact, GNU/Linux, or as I've re
|
||||
aken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free compo
|
||||
a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components com
|
||||
a full OS as defined by POSIX.
|
||||
|
||||
Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculia
|
||||
f events, the version of GNU which is widely used today is often called Linux, and many of its users are not aw
|
||||
it is basically the GNU system, developed by the GNU Project.
|
||||
|
||||
There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is
|
||||
el: the program in the system that allocates the machine's resources to the other programs that you run. The ke
|
||||
an essential part of an operating system, but useless by itself; it can only function in the context of a compl
|
||||
ating system. Linux is normally used in combination with the GNU operating system: the whole system is basicall
|
||||
th Linux added, or GNU/Linux. All the so-called Linux distributions are really distributions of GNU/Linux!
|
||||
";
|
||||
type CodeValue = u32;
|
||||
println!(
|
||||
"Using model: ModelA<{}>",
|
||||
std::any::type_name::<CodeValue>()
|
||||
);
|
||||
let model: ModelA<CodeValue> = ModelA::default();
|
||||
model.print_metrics();
|
||||
println!("");
|
||||
|
||||
let mut compressed = Vec::new();
|
||||
println!("compressing...");
|
||||
model.compress(&data[..], &mut compressed).unwrap();
|
||||
println!("ModelA compressed to {} bytes", compressed.len());
|
||||
println!(
|
||||
"Compression Ratio: {}",
|
||||
data.len() as f64 / compressed.len() as f64
|
||||
);
|
||||
println!("");
|
||||
|
||||
println!("decompressing...");
|
||||
let mut decompressed = Vec::new();
|
||||
let model: ModelA<CodeValue> = ModelA::default();
|
||||
model.decompress(&compressed, &mut decompressed).unwrap();
|
||||
println!("{}", String::from_utf8_lossy(&decompressed));
|
||||
}
|
||||
Reference in New Issue
Block a user