From 2cfb298468ca91036ce1dd3a72bcc9be619902b9 Mon Sep 17 00:00:00 2001 From: sreedev Date: Fri, 30 Dec 2022 00:25:07 -0500 Subject: [PATCH] faster hashing algorithm --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 2 +- src/database.rs | 1 + src/output.rs | 2 +- src/scanner.rs | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d84c0e6..4574b86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,12 @@ version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.3.0" @@ -238,6 +244,7 @@ dependencies = [ "chrono", "clap", "colored", + "fxhash", "glob", "humansize", "itertools", @@ -275,6 +282,15 @@ dependencies = [ "libc", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "glob" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index d047305..87cad63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ anyhow = "1.0.68" chrono = "0.4.23" clap = { version = "4.0.32", features = ["derive"] } colored = "2.0.0" +fxhash = "0.2.1" glob = "0.3.0" humansize = "2.1.2" itertools = "0.10.5" @@ -17,4 +18,3 @@ rayon = "1.6.1" sqlite = "0.30.3" thiserror = "1.0.38" tokio = { version = "1.23.0", features = ["full"] } -xxhash-rust = { version = "0.8.6", features = ["xxh3"] } diff --git a/src/database.rs b/src/database.rs index 147d997..2ecd934 100644 --- a/src/database.rs +++ b/src/database.rs @@ -67,6 +67,7 @@ pub fn duplicate_hashes(connection: &sqlite::Connection, path: &String) -> Resul ORDER BY a.file_identifier ", path ); + let result: Vec = connection .prepare(query)? .into_iter() diff --git a/src/output.rs b/src/output.rs index 4cd267a..3e933bf 100644 --- a/src/output.rs +++ b/src/output.rs @@ -48,7 +48,7 @@ pub fn print(duplicates: Vec) { group.into_iter().for_each(|file| { println!( "| {0: <16} | {1: <35} | {2: <16} | {3: <32} |", - &file.hash[0..16].red(), + file.hash.red(), format_path(&file.path).yellow(), file_size(&file.path).blue(), modified_time(&file.path).blue() diff --git a/src/scanner.rs b/src/scanner.rs index 977b302..d77dfeb 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -6,7 +6,7 @@ use itertools::Itertools; use rayon::prelude::*; use std::fs; use std::path::PathBuf; -use xxhash_rust::xxh3::xxh3_64 as hasher; +use fxhash::hash32 as hasher; pub fn duplicates(app_opts: &App, connection: &sqlite::Connection) -> Result> { let scan_results = scan(app_opts, connection)?;