summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2018-11-04 20:23:32 +0100
committersharkdp <davidpeter@web.de>2018-11-04 20:23:32 +0100
commitc9c8412dc829b3e60a1f6577c85d4c1363a5dfab (patch)
treef91b7eb25215bb9201728729ea541106f7cc0656
parentb4c571d0341fdc5f523b134d23aed9915a3f29a4 (diff)
Code cleanup
-rw-r--r--src/main.rs3
-rw-r--r--src/walk.rs11
2 files changed, 8 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 966c3b3..83b1027 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -51,7 +51,8 @@ fn main() {
.and_then(|t| t.parse().ok())
.unwrap_or(3 * num_cpus::get());
- let paths = &[PathBuf::from(".")];
+ let root = PathBuf::from(".");
+ let paths = &[root];
let walk = Walk::new(paths, num_threads);
let size = walk.run();
print_result(size);
diff --git a/src/walk.rs b/src/walk.rs
index 9b660d7..a5daac6 100644
--- a/src/walk.rs
+++ b/src/walk.rs
@@ -8,9 +8,10 @@ use crossbeam_channel as channel;
use rayon::prelude::*;
-type UniqueID = (u64, u64);
+#[derive(Eq,PartialEq,Hash)]
+struct UniqueID(u64, u64);
-type SizeEntry = (Option<UniqueID>, u64);
+struct SizeEntry(Option<UniqueID>, u64);
fn walk(tx: channel::Sender<SizeEntry>, entries: &[PathBuf]) {
entries.into_par_iter().for_each_with(tx, |tx_ref, entry| {
@@ -19,14 +20,14 @@ fn walk(tx: channel::Sender<SizeEntry>, entries: &[PathBuf]) {
// a unique ID consisting of device and inode in order
// not to count this entry twice.
let unique_id = if metadata.is_file() && metadata.nlink() > 1 {
- Some((metadata.dev(), metadata.ino()))
+ Some(UniqueID(metadata.dev(), metadata.ino()))
} else {
None
};
let size = metadata.len();
- tx_ref.send((unique_id, size)).unwrap();
+ tx_ref.send(SizeEntry(unique_id, size)).unwrap();
if metadata.is_dir() {
let mut children = vec![];
@@ -63,7 +64,7 @@ impl<'a> Walk<'a> {
let receiver_thread = thread::spawn(move || {
let mut total = 0;
let mut ids = HashSet::new();
- for (unique_id, size) in rx {
+ for SizeEntry(unique_id, size) in rx {
if let Some(unique_id) = unique_id {
// Only count this entry if the ID has not been seen
if ids.insert(unique_id) {