Skip to content

Commit fc7cd70

Browse files
committed
sort: Use ahash
1 parent 0bec48f commit fc7cd70

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ readme = "README.package.md"
310310
version = "0.6.0"
311311

312312
[workspace.dependencies]
313+
ahash = "0.8.12"
313314
ansi-width = "0.1.0"
314315
bigdecimal = "0.4"
315316
binary-heap-plus = "0.5.0"
@@ -328,7 +329,6 @@ dns-lookup = { version = "3.0.0" }
328329
exacl = "0.12.0"
329330
file_diff = "1.0.0"
330331
filetime = "0.2.23"
331-
fnv = "1.0.7"
332332
fs_extra = "1.3.0"
333333
fts-sys = "0.2.16"
334334
gcd = "2.3"

src/uu/sort/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ bigdecimal = { workspace = true }
2828
binary-heap-plus = { workspace = true }
2929
clap = { workspace = true }
3030
compare = { workspace = true }
31-
fnv = { workspace = true }
3231
itertools = { workspace = true }
3332
memchr = { workspace = true }
3433
rand = { workspace = true }
@@ -44,6 +43,7 @@ uucore = { workspace = true, features = [
4443
"i18n-collator",
4544
] }
4645
fluent = { workspace = true }
46+
ahash = { workspace = true }
4747

4848
[target.'cfg(not(target_os = "redox"))'.dependencies]
4949
ctrlc = { workspace = true }

src/uu/sort/src/sort.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,24 @@ mod merge;
1818
mod numeric_str_cmp;
1919
mod tmp_dir;
2020

21+
use ahash::AHashMap as HashMap;
22+
use ahash::AHasher as Hasher;
2123
use bigdecimal::BigDecimal;
2224
use chunks::LineData;
2325
use clap::builder::ValueParser;
2426
use clap::{Arg, ArgAction, ArgMatches, Command};
2527
use custom_str_cmp::custom_str_cmp;
26-
2728
use ext_sort::ext_sort;
28-
use fnv::FnvHasher;
2929
use numeric_str_cmp::{NumInfo, NumInfoParseSettings, human_numeric_str_cmp, numeric_str_cmp};
3030
use rand::{Rng, rng};
3131
use rayon::prelude::*;
3232
use std::cmp::Ordering;
3333
use std::env;
3434
use std::ffi::{OsStr, OsString};
3535
use std::fs::{File, OpenOptions};
36-
use std::hash::{Hash, Hasher};
36+
use std::hash::BuildHasher as _;
37+
use std::hash::Hash;
38+
use std::hash::Hasher as _;
3739
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
3840
use std::num::{IntErrorKind, NonZero};
3941
use std::ops::Range;
@@ -1681,7 +1683,7 @@ fn index_legacy_warnings(processed_args: &[OsString], legacy_warnings: &mut [Leg
16811683
return;
16821684
}
16831685

1684-
let mut index_by_arg = std::collections::HashMap::new();
1686+
let mut index_by_arg = HashMap::default();
16851687
for (warning_idx, warning) in legacy_warnings.iter().enumerate() {
16861688
index_by_arg.insert(warning.arg_index, warning_idx);
16871689
}
@@ -2909,7 +2911,7 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
29092911
let mut reader = open_with_open_failed_error(path)?;
29102912
let mut buf = [0u8; BUF_LEN];
29112913
let mut total = 0usize;
2912-
let mut hasher = FnvHasher::default();
2914+
let mut hasher = Hasher::default();
29132915

29142916
loop {
29152917
let n = reader
@@ -2934,7 +2936,7 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
29342936
}
29352937

29362938
let first = hasher.finish();
2937-
let mut second_hasher = FnvHasher::default();
2939+
let mut second_hasher = Hasher::default();
29382940
second_hasher.write(RANDOM_SOURCE_TAG);
29392941
second_hasher.write_u64(first);
29402942
let second = second_hasher.finish();
@@ -2946,7 +2948,8 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
29462948
}
29472949

29482950
fn get_hash<T: Hash>(t: &T) -> u64 {
2949-
let mut s = FnvHasher::default();
2951+
// Is reproducibility of get_hash itself needed for --random-source ?
2952+
let mut s = ahash::RandomState::with_seeds(0, 0, 0, 0).build_hasher();
29502953
t.hash(&mut s);
29512954
s.finish()
29522955
}
@@ -3090,7 +3093,7 @@ mod tests {
30903093
fn test_get_hash() {
30913094
let a = "Ted".to_string();
30923095

3093-
assert_eq!(2_646_829_031_758_483_623, get_hash(&a));
3096+
assert_eq!(6_449_979_114_061_965_534, get_hash(&a));
30943097
}
30953098

30963099
#[test]

0 commit comments

Comments
 (0)