X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Falgorithm.c;h=cfb1ba9fbf533ef55baefbeb06c594eaf9220611;hb=8fa7f3f6640c0eec450149cf5ccfab15d5391f55;hp=54103b36d639f518a1db498947c431bf2e021242;hpb=6dce32fd36df874826cbcac0e5e9b4efd218d32c;p=pspp diff --git a/src/algorithm.c b/src/algorithm.c index 54103b36d6..cfb1ba9fbf 100644 --- a/src/algorithm.c +++ b/src/algorithm.c @@ -96,7 +96,6 @@ #include #include #include "alloc.h" -#include "settings.h" /* Some of the assertions in this file are very expensive. We don't use them by default. */ @@ -117,7 +116,7 @@ find (const void *array, size_t count, size_t size, const void *target, algo_compare_func *compare, void *aux) { - const unsigned char *element = array; + const char *element = array; while (count-- > 0) { @@ -139,7 +138,7 @@ count_equal (const void *array, size_t count, size_t size, const void *element, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t equal_cnt = 0; while (count-- > 0) @@ -161,7 +160,7 @@ size_t count_if (const void *array, size_t count, size_t size, algo_predicate_func *predicate, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t nonzero_cnt = 0; while (count-- > 0) @@ -294,7 +293,7 @@ is_partitioned (const void *array, size_t count, size_t size, size_t nonzero_cnt, algo_predicate_func *predicate, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t idx; assert (nonzero_cnt <= count); @@ -307,32 +306,6 @@ is_partitioned (const void *array, size_t count, size_t size, return 1; } -/* A algo_random_func that uses random.h. */ -unsigned -algo_default_random (unsigned max, void *aux UNUSED) -{ - 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 - bytes each. Uses RANDOM as a source of random data, passing - AUX as the auxiliary data. RANDOM may be null to use a - default random source. */ -void -random_shuffle (void *array_, size_t count, size_t size, - algo_random_func *random, void *aux) -{ - unsigned char *array = array_; - int i; - - if (random == NULL) - random = algo_default_random; - - for (i = 1; i < count; i++) - SWAP (array + i * size, array + random (i + 1, aux) * size, size); -} - /* Copies the COUNT elements of SIZE bytes each from ARRAY to RESULT, except that elements for which PREDICATE is false are not copied. Returns the number of elements copied. AUX is @@ -342,9 +315,9 @@ copy_if (const void *array, size_t count, size_t size, void *result, algo_predicate_func *predicate, void *aux) { - const unsigned char *input = array; - const unsigned char *last = input + size * count; - unsigned char *output = result; + const char *input = array; + const char *last = input + size * count; + char *output = result; size_t nonzero_cnt = 0; while (input < last) @@ -447,9 +420,9 @@ remove_equal (void *array, size_t count, size_t size, void *element, algo_compare_func *compare, void *aux) { - unsigned char *first = array; - unsigned char *last = first + count * size; - unsigned char *result; + char *first = array; + char *last = first + count * size; + char *result; for (;;) { @@ -515,14 +488,14 @@ binary_search (const void *array, size_t count, size_t size, if (count != 0) { - const unsigned char *first = array; + const char *first = array; int low = 0; int high = count - 1; while (low <= high) { int middle = (low + high) / 2; - const unsigned char *element = first + middle * size; + const char *element = first + middle * size; int cmp = compare (value, element, aux); if (cmp > 0) @@ -549,8 +522,8 @@ lexicographical_compare_3way (const void *array1, size_t count1, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first1 = array1; - const unsigned char *first2 = array2; + const char *first1 = array1; + const char *first2 = array2; size_t min_count = count1 < count2 ? count1 : count2; while (min_count > 0) @@ -790,7 +763,7 @@ int is_sorted (const void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t idx; for (idx = 0; idx + 1 < count; idx++) @@ -814,11 +787,11 @@ size_t set_difference (const void *array1, size_t count1, void *result_, algo_compare_func *compare, void *aux) { - const unsigned char *first1 = array1; - const unsigned char *last1 = first1 + count1 * size; - const unsigned char *first2 = array2; - const unsigned char *last2 = first2 + count2 * size; - unsigned char *result = result_; + const char *first1 = array1; + const char *last1 = first1 + count1 * size; + const char *first2 = array2; + const char *last2 = first2 + count2 * size; + char *result = result_; size_t result_count = 0; while (first1 != last1 && first2 != last2) @@ -861,8 +834,8 @@ void * adjacent_find_equal (const void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; - const unsigned char *last = first + count * size; + const char *first = array; + const char *last = first + count * size; while (first < last && first + size < last) { @@ -884,15 +857,15 @@ void push_heap (void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; size_t i; expensive_assert (count < 1 || is_heap (array, count - 1, size, compare, aux)); for (i = count; i > 1; i /= 2) { - unsigned char *parent = first + (i / 2 - 1) * size; - unsigned char *element = first + (i - 1) * size; + char *parent = first + (i / 2 - 1) * size; + char *element = first + (i - 1) * size; if (compare (parent, element, aux) < 0) SWAP (parent, element, size); else @@ -911,7 +884,7 @@ heapify (void *array, size_t count, size_t size, size_t idx, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; for (;;) { @@ -947,7 +920,7 @@ void pop_heap (void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; expensive_assert (is_heap (array, count, size, compare, aux)); SWAP (first, first + (count - 1) * size, size); @@ -978,7 +951,7 @@ void sort_heap (void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; size_t idx; expensive_assert (is_heap (array, count, size, compare, aux)); @@ -998,7 +971,7 @@ int is_heap (const void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t child; for (child = 2; child <= count; child++)