Remove bool flag for rehashing

This commit is contained in:
Jon Moroney 2018-07-03 20:47:34 -10:00
parent 22d5795d9b
commit c8c5e48f7a
2 changed files with 6 additions and 8 deletions

View file

@ -32,14 +32,13 @@ pub struct Fileinfo{
partial_hash: u64,
file_length: u64,
pub file_paths: Vec<PathBuf>,
pub second_hash: bool,
}
impl Fileinfo{
pub fn new(hash: u64, partial_hash: u64, length: u64, path: PathBuf) -> Self{
let mut set = Vec::<PathBuf>::new();
set.push(path);
Fileinfo{full_hash: hash, partial_hash: partial_hash, file_length: length, file_paths: set, second_hash: false}
Fileinfo{full_hash: hash, partial_hash: partial_hash, file_length: length, file_paths: set}
}
pub fn get_length(&self) -> u64{
self.file_length

View file

@ -121,17 +121,16 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) ->
n if n>1 => {
//Hash stage one
files.par_iter_mut().for_each(|file_ref| {
let p_hash = file_ref.generate_partial_hash().unwrap();
file_ref.set_full_hash(p_hash);
file_ref.generate_partial_hash().unwrap();
});
files.par_sort_unstable_by(|a, b| b.get_full_hash().cmp(&a.get_full_hash())); //O(nlog(n))
files.par_sort_unstable_by(|a, b| b.get_partial_hash().cmp(&a.get_partial_hash())); //O(nlog(n))
if file_length>4096 /*4KB*/ { //only hash again if we are not done hashing
files.dedup_by(|a, b| if a==b{ //O(n)
a.second_hash=true;
b.second_hash=true;
a.set_full_hash(1);
b.set_full_hash(1);
false
}else{false});
files.par_iter_mut().filter(|x| x.second_hash==true).for_each(|file_ref| {
files.par_iter_mut().filter(|x| x.get_full_hash()==1).for_each(|file_ref| {
hash_and_update(file_ref); //Skip 4KB
});
}