Compare commits
No commits in common. "wip/vec_cmp" and "master" have entirely different histories.
wip/vec_cm
...
master
37
src/main.rs
37
src/main.rs
|
@ -19,8 +19,6 @@ use std::fmt;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 1024;
|
const BUFFER_SIZE: usize = 1024;
|
||||||
|
|
||||||
/* Note for myself : CLAP = _C_ommand _L_ine _A_rgument _P_arser */
|
/* Note for myself : CLAP = _C_ommand _L_ine _A_rgument _P_arser */
|
||||||
|
@ -247,14 +245,12 @@ fn main() {
|
||||||
let chunk_size = (files_candidate_len / num_cpus) + 1;
|
let chunk_size = (files_candidate_len / num_cpus) + 1;
|
||||||
let modulus = files_candidate_len % num_cpus;
|
let modulus = files_candidate_len % num_cpus;
|
||||||
|
|
||||||
println!("Compute Hash of {} file(s)", files_candidate_len);
|
println!("Calculate {} file(s)", files_candidate_len);
|
||||||
println!("Use {} chunk(s) of size {}", modulus, chunk_size);
|
println!("Use {} chunk(s) of size {}", modulus, chunk_size);
|
||||||
println!("Use {} chunk(s) of size {}", num_cpus - modulus, chunk_size - 1);
|
println!("Use {} chunk(s) of size {}", num_cpus - modulus, chunk_size - 1);
|
||||||
|
|
||||||
let mut work = files_candidate.lock().unwrap();
|
let mut work = files_candidate.lock().unwrap();
|
||||||
|
|
||||||
println!("\n=Starting Hash compute in Thread");
|
|
||||||
|
|
||||||
// Example from :
|
// Example from :
|
||||||
// https://stackoverflow.com/questions/33818141/how-do-i-pass-disjoint-slices-from-a-vector-to-different-threads
|
// https://stackoverflow.com/questions/33818141/how-do-i-pass-disjoint-slices-from-a-vector-to-different-threads
|
||||||
// Scoped threads allow the compiler to prove that no threads will outlive
|
// Scoped threads allow the compiler to prove that no threads will outlive
|
||||||
|
@ -285,39 +281,16 @@ fn main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("=End");
|
|
||||||
|
|
||||||
// Sort Unique element in hashmap
|
|
||||||
let uniques: HashMap<_, _> = work.iter()
|
|
||||||
.map(|c| (&c.hash, c.name.as_str()))
|
|
||||||
.collect();
|
|
||||||
let num_dups = work.len() - uniques.len();
|
|
||||||
|
|
||||||
println!("Duplicate : {}", num_dups);
|
|
||||||
|
|
||||||
// for (bytes, name) in uniques.iter() {
|
|
||||||
// println!("Name : {:#?}", name);
|
|
||||||
// print!("[");
|
|
||||||
// for byte in *bytes {
|
|
||||||
// print!("{:02x}", byte);
|
|
||||||
// }
|
|
||||||
// println!("]");
|
|
||||||
// }
|
|
||||||
|
|
||||||
println!("\n=Result");
|
|
||||||
for _i in work.iter() {
|
|
||||||
}
|
|
||||||
println!("=End");
|
|
||||||
|
|
||||||
for i in work.iter() {
|
for i in work.iter() {
|
||||||
println!("{}", i);
|
println!("{}", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO with work !
|
||||||
|
// check for each hash duplication
|
||||||
|
// if so --> log to file and remove from list (store to done vector)
|
||||||
|
|
||||||
t.fg(term::color::CYAN).unwrap();
|
t.fg(term::color::CYAN).unwrap();
|
||||||
let end = PreciseTime::now();
|
let end = PreciseTime::now();
|
||||||
|
|
||||||
println!("");
|
|
||||||
println!("=End");
|
|
||||||
println!("{} seconds.", start.to(end));
|
println!("{} seconds.", start.to(end));
|
||||||
|
|
||||||
t.reset().unwrap();
|
t.reset().unwrap();
|
||||||
|
|
Loading…
Reference in New Issue