Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coreutils (uutils)
# * see the repository LICENSE, README, and CONTRIBUTING files for more information

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

[package]
name = "coreutils"
Expand Down Expand Up @@ -311,6 +311,7 @@ readme = "README.package.md"
version = "0.6.0"

[workspace.dependencies]
ahash = "0.8.12"
ansi-width = "0.1.0"
bigdecimal = "0.4"
binary-heap-plus = "0.5.0"
Expand All @@ -329,7 +330,6 @@ dns-lookup = { version = "3.0.0" }
exacl = "0.12.0"
file_diff = "1.0.0"
filetime = "0.2.23"
fnv = "1.0.7"
fs_extra = "1.3.0"
fts-sys = "0.2.16"
gcd = "2.3"
Expand Down
77 changes: 42 additions & 35 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/uu/sort/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# spell-checker:ignore bigdecimal
# spell-checker:ignore ahash bigdecimal

[package]
name = "uu_sort"
Expand Down Expand Up @@ -29,7 +29,6 @@ bigdecimal = { workspace = true }
binary-heap-plus = { workspace = true }
clap = { workspace = true }
compare = { workspace = true }
fnv = { workspace = true }
itertools = { workspace = true }
memchr = { workspace = true }
rand = { workspace = true }
Expand All @@ -45,6 +44,7 @@ uucore = { workspace = true, features = [
"i18n-collator",
] }
fluent = { workspace = true }
ahash = { workspace = true }

[target.'cfg(not(target_os = "redox"))'.dependencies]
ctrlc = { workspace = true }
Expand Down
25 changes: 9 additions & 16 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ mod merge;
mod numeric_str_cmp;
mod tmp_dir;

use ahash::AHashMap;
use bigdecimal::BigDecimal;
use chunks::LineData;
use clap::builder::ValueParser;
use clap::{Arg, ArgAction, ArgMatches, Command};
use custom_str_cmp::custom_str_cmp;

use ext_sort::ext_sort;
use fnv::FnvHasher;
use numeric_str_cmp::{NumInfo, NumInfoParseSettings, human_numeric_str_cmp, numeric_str_cmp};
use rand::{Rng, rng};
use rayon::prelude::*;
use std::cmp::Ordering;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs::{File, OpenOptions};
use std::hash::{Hash, Hasher};
use std::hash::{BuildHasher, Hash, Hasher};
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
use std::num::{IntErrorKind, NonZero};
use std::ops::Range;
Expand Down Expand Up @@ -1681,7 +1680,7 @@ fn index_legacy_warnings(processed_args: &[OsString], legacy_warnings: &mut [Leg
return;
}

let mut index_by_arg = std::collections::HashMap::new();
let mut index_by_arg = AHashMap::default();
for (warning_idx, warning) in legacy_warnings.iter().enumerate() {
index_by_arg.insert(warning.arg_index, warning_idx);
}
Expand Down Expand Up @@ -2909,7 +2908,8 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
let mut reader = open_with_open_failed_error(path)?;
let mut buf = [0u8; BUF_LEN];
let mut total = 0usize;
let mut hasher = FnvHasher::default();
// freeze seed for --random-source
let mut hasher = ahash::RandomState::with_seeds(1, 1, 1, 1).build_hasher();

loop {
let n = reader
Expand All @@ -2934,7 +2934,8 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
}

let first = hasher.finish();
let mut second_hasher = FnvHasher::default();
// freeze seed for --random-source
let mut second_hasher = ahash::RandomState::with_seeds(2, 2, 2, 2).build_hasher();
second_hasher.write(RANDOM_SOURCE_TAG);
second_hasher.write_u64(first);
let second = second_hasher.finish();
Expand All @@ -2946,9 +2947,8 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> {
}

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

fn random_shuffle(a: &[u8], b: &[u8], salt: &[u8]) -> Ordering {
Expand Down Expand Up @@ -3086,13 +3086,6 @@ mod tests {
buffer
}

#[test]
fn test_get_hash() {
let a = "Ted".to_string();

assert_eq!(2_646_829_031_758_483_623, get_hash(&a));
}

#[test]
fn test_random_shuffle() {
let a = b"Ted";
Expand Down
Loading