From 27873f1deb69745c79d403bbb8e1145bc18f55b8 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Fri, 13 May 2011 18:41:42 +0100 Subject: 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. --- tests/misc/shuf | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/misc/shuf') 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 -- cgit v1.2.3-70-g09d2