Bug 22313 - sort -R не перемешивает дублирующиеся строки
Summary: sort -R не перемешивает дублирующиеся строки
Status: CLOSED NOTABUG
Alias: None
Product: Sisyphus
Classification: Development
Component: coreutils (show other bugs)
Version: unstable
Hardware: all Linux
: P3 normal
Assignee: placeholder@altlinux.org
QA Contact: qa-sisyphus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-17 01:51 MSK by Alexey Gladkov
Modified: 2009-11-17 14:12 MSK (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Gladkov 2009-11-17 01:51:02 MSK
Если в входном потоке есть повторяющиеся строки, то на выходе они всегда оказываются рядом:

$ export LANG=C
$ for i in `seq 1 1000`; do printf 'aaa\nbbb\naaa\nccc\nddd\naaa\neee\n' |sort -R |uniq |wc -l; done |uniq
5

Опция --random-source эффекта не оказывает.
Comment 1 Slava Semushin 2009-11-17 07:24:14 MSK
Это by design; опция -R не совсем сортирует в случайном порядке, она берёт случайную хэш функцию, применяет её к каждой строке и потом сортирует их по полученным хэшам, т.о. выглядит это очень похоже на случайное перемешивание, но это не совсем так.
Comment 2 Alexey Gladkov 2009-11-17 13:26:25 MSK
Тогда в ман странице нужно написать правду. Так как лично я фразу "sort by random hash of keys" понял как "сортировка по случайному хэшу от ключа". Из описания не понятно, применяется ли одинаковая процедура хэширования ко всем ключам или нет.
Comment 3 Dmitry V. Levin 2009-11-17 14:04:38 MSK
sort(1) manpage выглядит лаконичной версией info sort, в котором написано:
"Sort by hashing the input keys and then sorting the hash values. Choose the hash function at random, ensuring that it is free of collisions so that differing keys have differing hash values. This is like a random permutation of the inputs, except that keys with the same value sort together."
Comment 4 Alexey Gladkov 2009-11-17 14:12:31 MSK
(В ответ на комментарий №3)
> sort(1) manpage выглядит лаконичной версией info sort, в котором написано:
> "Sort by hashing the input keys and then sorting the hash values. Choose the
> hash function at random, ensuring that it is free of collisions so that
> differing keys have differing hash values. This is like a random permutation of
> the inputs, except that keys with the same value sort together."

Тогда вопросов не имею. Сам виноват.