Skip to content

Commit

Permalink
Make -s output like: sort | uniq -c | sort -n
Browse files Browse the repository at this point in the history
  • Loading branch information
ahcm committed Apr 12, 2022
1 parent f691c9b commit dde119d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/bin/hist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ fn save(counts : &BTreeMap<String, usize>, path : &std::path::Path)
Box::new(File::create(&path).unwrap())
};

for (key, count) in counts
let mut entries = Vec::from_iter(counts);
entries.sort_by(|&(_, a), &(_, b)| a.cmp(&b)); // sort by value


for (key, count) in entries
{
out.write_fmt(format_args!("{}\t{}\n", key, count)).expect("Write to save file failed");
out.write_fmt(format_args!("{}\t{}\n", count, key)).expect("Write to save file failed");
}
}

Expand Down

0 comments on commit dde119d

Please sign in to comment.