mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 22:17:45 +00:00
sort: compare strings before comparing hashes
Since lines that compare equal should be sorted together, we need to first compare the lines (taking settings into account). Only if they do not compare equal we should compare the hashes.
This commit is contained in:
parent
f851fb6454
commit
3564dc5792
2 changed files with 26 additions and 1 deletions
|
@ -1398,7 +1398,22 @@ fn compare_by<'a>(
|
||||||
let settings = &selector.settings;
|
let settings = &selector.settings;
|
||||||
|
|
||||||
let cmp: Ordering = match settings.mode {
|
let cmp: Ordering = match settings.mode {
|
||||||
SortMode::Random => random_shuffle(a_str, b_str, &global_settings.salt.unwrap()),
|
SortMode::Random => {
|
||||||
|
// check if the two strings are equal
|
||||||
|
if custom_str_cmp(
|
||||||
|
a_str,
|
||||||
|
b_str,
|
||||||
|
settings.ignore_non_printing,
|
||||||
|
settings.dictionary_order,
|
||||||
|
settings.ignore_case,
|
||||||
|
) == Ordering::Equal
|
||||||
|
{
|
||||||
|
Ordering::Equal
|
||||||
|
} else {
|
||||||
|
// Only if they are not equal compare by the hash
|
||||||
|
random_shuffle(a_str, b_str, &global_settings.salt.unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
SortMode::Numeric => {
|
SortMode::Numeric => {
|
||||||
let a_num_info = &a_line_data.num_infos
|
let a_num_info = &a_line_data.num_infos
|
||||||
[a.index * global_settings.precomputed.num_infos_per_line + num_info_index];
|
[a.index * global_settings.precomputed.num_infos_per_line + num_info_index];
|
||||||
|
|
|
@ -235,6 +235,16 @@ fn test_random_shuffle_two_runs_not_the_same() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_random_ignore_case() {
|
||||||
|
let input = "ABC\nABc\nAbC\nAbc\naBC\naBc\nabC\nabc\n";
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-fR"])
|
||||||
|
.pipe_in(input)
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is(input);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_numeric_floats_and_ints() {
|
fn test_numeric_floats_and_ints() {
|
||||||
test_helper(
|
test_helper(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue