first commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sparse_compress"
|
||||||
|
version = "0.1.0"
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "sparse_compress"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
2
spec.txt
Normal file
2
spec.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
cmd::compress_in_time::compress_in_size
|
||||||
|
zip::3m18.627::1%
|
48
src/main.rs
Normal file
48
src/main.rs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
use core::num;
|
||||||
|
use std::fs::{self, File};
|
||||||
|
use std::io::{self, BufReader, Read};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn create_matrix_wigh_given_size(size: usize) {}
|
||||||
|
|
||||||
|
fn calculate_matrix_size(num_elements: usize) -> (usize, usize) {
|
||||||
|
let sqrt_elements = num_elements as f64().sqrt() as usize;
|
||||||
|
|
||||||
|
let mut best_x = sqrt_elements;
|
||||||
|
let mut best_y = sqrt_elements;
|
||||||
|
let mut best_dff = usize::MAX;
|
||||||
|
|
||||||
|
for x in (1..=sqrt_elements).rev() {
|
||||||
|
let y = num_elements/x;
|
||||||
|
if y * x == num_elements {
|
||||||
|
return (x, y)
|
||||||
|
}
|
||||||
|
let diff = (num_elements - x * y).abs();
|
||||||
|
if diff < best_diff {
|
||||||
|
best_x = x;
|
||||||
|
best_y = y;
|
||||||
|
best_diff = diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(best_x, best_y)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> io::Result<()> {
|
||||||
|
let input_file_path: &str = "/mnt/c/Users/dongho/Desktop/sparse_compress/ubuntu.iso";
|
||||||
|
let output_file_path: &str = "/mnt/c/Users/dongho/Desktop/sparse_compress/ubuntu.dhm";
|
||||||
|
let path: &Path = Path::new(input_file_path);
|
||||||
|
|
||||||
|
if !path.exists() {
|
||||||
|
println!("File does not exists");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let metadata = fs::metadata(path).unwrap();
|
||||||
|
let file_size = metadata.len();
|
||||||
|
let file_size_usize:usize = (file_size*8) as usize;
|
||||||
|
println!("File size: {} bytes", file_size);
|
||||||
|
println!("File size: {} bits", file_size * 8);
|
||||||
|
let (x, y) = calculate_matrix_size(fil);
|
||||||
|
println!("Optimal Matrix size: {} x {}", x, y);
|
||||||
|
Ok(())
|
||||||
|
}
|
Reference in New Issue
Block a user