X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Falgorithm.c;h=3c1aed90e2be95ed75b8a9033aadd5b1cb5c47f2;hb=e35ff8ccb29404f2098e6f2fccace1c99c61b7be;hp=230b1437f214ca6090979679bed2be9747051625;hpb=bd244987b9175ae3edf7c5f7417340a0a37427a8;p=pspp diff --git a/src/algorithm.c b/src/algorithm.c index 230b1437f2..3c1aed90e2 100644 --- a/src/algorithm.c +++ b/src/algorithm.c @@ -91,11 +91,12 @@ #include #include "algorithm.h" +#include #include #include #include #include "alloc.h" -#include "random.h" +#include "settings.h" /* Some of the assertions in this file are very expensive. We don't use them by default. */ @@ -310,7 +311,8 @@ is_partitioned (const void *array, size_t count, size_t size, unsigned algo_default_random (unsigned max, void *aux UNUSED) { - return rng_get_unsigned (pspp_rng ()) % max; + unsigned long r_min = gsl_rng_min (get_rng ()); + return (gsl_rng_get (get_rng ()) - r_min) % max; } /* Randomly reorders ARRAY, which contains COUNT elements of SIZE @@ -363,6 +365,34 @@ copy_if (const void *array, size_t count, size_t size, return nonzero_cnt; } +/* Removes N elements starting at IDX from ARRAY, which consists + of COUNT elements of SIZE bytes each, by shifting the elements + following them, if any, into its position. */ +void +remove_range (void *array_, size_t count, size_t size, + size_t idx, size_t n) +{ + char *array = array_; + + assert (array != NULL); + assert (idx <= count); + assert (idx + n <= count); + + if (idx + n < count) + memmove (array + idx * size, array + (idx + n) * size, + size * (count - idx - n)); +} + +/* Removes element IDX from ARRAY, which consists of COUNT + elements of SIZE bytes each, by shifting the elements + following it, if any, into its position. */ +void +remove_element (void *array, size_t count, size_t size, + size_t idx) +{ + remove_range (array, count, size, idx, 1); +} + /* A predicate and its auxiliary data. */ struct pred_aux {