summaryrefslogtreecommitdiff
path: root/tests/misc/shuf
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2011-05-13 18:41:42 +0100
committerPádraig Brady <P@draigBrady.com>2011-05-14 10:30:12 +0100
commit27873f1deb69745c79d403bbb8e1145bc18f55b8 (patch)
treed3b752eed0035e9ce767ea73c07f3b8577deaead /tests/misc/shuf
parent9d152a1ed72968ae3624a76e155fe16b240348dc (diff)
downloadcoreutils-27873f1deb69745c79d403bbb8e1145bc18f55b8.tar.xz
shuf: use memory more efficiently when returning a subset
* gl/lib/randperm.c (randperm_new): When the number of items to return H, is much smaller than the total number of items N, use a hash to represent the sparse permutations of the set N. This is currently enabled for N > 128K and N/H > 32. * tests/misc/shuf: Ensure shuf can quickly return 2 numbers from a large range. * gl/modules/randperm: Depend on hash. * NEWS: Mention the change.
Diffstat (limited to 'tests/misc/shuf')
-rwxr-xr-xtests/misc/shuf6
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/misc/shuf b/tests/misc/shuf
index cdfe7052b..10d285846 100755
--- a/tests/misc/shuf
+++ b/tests/misc/shuf
@@ -18,6 +18,7 @@
. "${srcdir=.}/init.sh"; path_prepend_ ../src
print_ver_ shuf
+getlimits_
seq 100 > in || framework_failure
@@ -51,4 +52,9 @@ shuf --zero-terminated -i 1-1 > out || fail=1
printf '1\0' > exp || framework_failure
cmp out exp || { fail=1; echo "missing NUL terminator?" 1>&2; }
+# Ensure shuf -n operates efficiently for small n. Before coreutils-8.13
+# this would try to allocate $SIZE_MAX * sizeof(size_t)
+timeout 10 shuf -i1-$SIZE_MAX -n2 >/dev/null ||
+ { fail=1; echo "couldn't get a small subset" >&2; }
+
Exit $fail