Skip to content

Commit 7f34f68

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

File tree

5 files changed

+70
-50
lines changed

5 files changed

+70
-50
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coreutils (uutils)
22
# * see the repository LICENSE, README, and CONTRIBUTING files for more information
33

4-
# spell-checker:ignore (libs) bigdecimal datetime serde wincode gethostid kqueue libselinux mangen memmap uuhelp startswith constness expl unnested logind cfgs interner
4+
# spell-checker:ignore (libs) ahash bigdecimal datetime serde wincode gethostid kqueue libselinux mangen memmap uuhelp startswith constness expl unnested logind cfgs interner
55

66
[package]
77
name = "coreutils"
@@ -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"

fuzz/Cargo.lock

Lines changed: 42 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/sort/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# spell-checker:ignore bigdecimal
1+
# spell-checker:ignore ahash bigdecimal
22

33
[package]
44
name = "uu_sort"
@@ -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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@ 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::Hash;
37+
use std::hash::Hasher as _;
3738
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
3839
use std::num::{IntErrorKind, NonZero};
3940
use std::ops::Range;
@@ -1681,7 +1682,7 @@ fn index_legacy_warnings(processed_args: &[OsString], legacy_warnings: &mut [Leg
16811682
return;
16821683
}
16831684

1684-
let mut index_by_arg = std::collections::HashMap::new();
1685+
let mut index_by_arg = HashMap::default();
16851686
for (warning_idx, warning) in legacy_warnings.iter().enumerate() {
16861687
index_by_arg.insert(warning.arg_index, warning_idx);
16871688
}
@@ -2909,7 +2910,7 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
29092910
let mut reader = open_with_open_failed_error(path)?;
29102911
let mut buf = [0u8; BUF_LEN];
29112912
let mut total = 0usize;
2912-
let mut hasher = FnvHasher::default();
2913+
let mut hasher = Hasher::default();
29132914

29142915
loop {
29152916
let n = reader
@@ -2934,7 +2935,7 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
29342935
}
29352936

29362937
let first = hasher.finish();
2937-
let mut second_hasher = FnvHasher::default();
2938+
let mut second_hasher = Hasher::default();
29382939
second_hasher.write(RANDOM_SOURCE_TAG);
29392940
second_hasher.write_u64(first);
29402941
let second = second_hasher.finish();
@@ -2946,9 +2947,8 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
29462947
}
29472948

29482949
fn get_hash<T: Hash>(t: &T) -> u64 {
2949-
let mut s = FnvHasher::default();
2950-
t.hash(&mut s);
2951-
s.finish()
2950+
// Is reproducibility of get_hash itself needed for --random-source ?
2951+
ahash::RandomState::with_seeds(0, 0, 0, 0).hash_one(t)
29522952
}
29532953

29542954
fn random_shuffle(a: &[u8], b: &[u8], salt: &[u8]) -> Ordering {
@@ -3090,7 +3090,7 @@ mod tests {
30903090
fn test_get_hash() {
30913091
let a = "Ted".to_string();
30923092

3093-
assert_eq!(2_646_829_031_758_483_623, get_hash(&a));
3093+
assert_eq!(6_449_979_114_061_965_534, get_hash(&a));
30943094
}
30953095

30963096
#[test]

0 commit comments

Comments
 (0)