#include "alloc.h"
#include "random.h"
-/* Some of the assertions in this file are very expensive. If
- we're optimizing, don't include them. */
-#if __OPTIMIZE__
-#define NDEBUG
+/* Some of the assertions in this file are very expensive. We
+ don't use them by default. */
+#ifdef EXTRA_CHECKS
+#define expensive_assert(X) assert(X)
+#else
+#define expensive_assert(X) ((void) 0)
#endif
-#include <assert.h>
+#include "error.h"
\f
/* Finds an element in ARRAY, which contains COUNT elements of
SIZE bytes each, using COMPARE for comparisons. Returns the
first += size;
if (first >= last)
{
- assert (adjacent_find_equal (array, count, size, compare, aux) == NULL);
+ assert (adjacent_find_equal (array, count,
+ size, compare, aux) == NULL);
return count;
}
}
}
- assert (find (array, count, size, value, compare, aux) == NULL);
+ expensive_assert (find (array, count, size, value, compare, aux) == NULL);
return NULL;
}
\f
Engineering a sort function; Jon Bentley and M. Douglas McIlroy;
Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */
+#ifdef HAVE_ALLOCA_H
#include <alloca.h>
+#endif
+
#include <limits.h>
#include <stdlib.h>
#include <string.h>
unsigned char *first = array;
size_t i;
- assert (count < 1 || is_heap (array, count - 1, size, compare, aux));
+ 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;
else
break;
}
- assert (is_heap (array, count, size, compare, aux));
+ expensive_assert (is_heap (array, count, size, compare, aux));
}
/* ARRAY contains COUNT elements of SIZE bytes each. Initially
{
unsigned char *first = array;
- assert (is_heap (array, count, size, compare, aux));
+ expensive_assert (is_heap (array, count, size, compare, aux));
SWAP (first, first + (count - 1) * size, size);
heapify (first, count - 1, size, 1, compare, aux);
- assert (count < 1 || is_heap (array, count - 1, size, compare, aux));
+ expensive_assert (count < 1 || is_heap (array, count - 1,
+ size, compare, aux));
}
/* Turns ARRAY, which contains COUNT elements of SIZE bytes, into
for (idx = count / 2; idx >= 1; idx--)
heapify (array, count, size, idx, compare, aux);
- assert (count < 1 || is_heap (array, count, size, compare, aux));
+ expensive_assert (count < 1 || is_heap (array, count, size, compare, aux));
}
/* ARRAY contains COUNT elements of SIZE bytes each. Initially
unsigned char *first = array;
size_t idx;
- assert (is_heap (array, count, size, compare, aux));
+ expensive_assert (is_heap (array, count, size, compare, aux));
for (idx = count; idx >= 2; idx--)
{
SWAP (first, first + (idx - 1) * size, size);
heapify (array, idx - 1, size, 1, compare, aux);
}
- assert (is_sorted (array, count, size, compare, aux));
+ expensive_assert (is_sorted (array, count, size, compare, aux));
}
/* ARRAY contains COUNT elements of SIZE bytes each. This