/* Test program for tsearch et al.
- Copyright (C) 1997, 2000-2001, 2007-2008 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2000-2001, 2007-2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software: you can redistribute it and/or
#include <search.h>
+#include "signature.h"
+SIGNATURE_CHECK (tdelete, void *, (void const *, void **,
+ int (*) (void const *, void const *)));
+SIGNATURE_CHECK (tfind, void *, (void const *, void * const *,
+ int (*) (void const *, void const *)));
+SIGNATURE_CHECK (tsearch, void *, (void const *, void **,
+ int (*) (void const *, void const *)));
+SIGNATURE_CHECK (twalk, void, (void const *,
+ void (*) (void const *, VISIT, int)));
+
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
else
{
if (depths[key] != depth)
- {
- fputs ("Depth for one element is not constant during tree walk.\n",
- stdout);
- }
+ {
+ fputs ("Depth for one element is not constant during tree walk.\n",
+ stdout);
+ }
}
}
for (i = 0; i < expected_count; ++i)
if (z[i] != 1)
{
- fputs ("Node was not visited.\n", stdout);
- error = 1;
+ fputs ("Node was not visited.\n", stdout);
+ error = 1;
}
#if BALANCED
if (how == randomorder)
{
for (i = 0; i < SIZE; ++i)
- y[i] = i;
+ y[i] = i;
memfry (y);
}
int j, k;
switch (how)
- {
- case randomorder:
- if (i >= lag)
- k = y[i - lag];
- else
- /* Ensure that the array index is within bounds. */
- k = y[(SIZE - i - 1 + lag) % SIZE];
- j = y[i % SIZE];
- break;
-
- case ascending:
- k = i - lag;
- j = i;
- break;
-
- case descending:
- k = SIZE - i - 1 + lag;
- j = SIZE - i - 1;
- break;
-
- default:
- /* This never should happen, but gcc isn't smart enough to
- recognize it. */
- abort ();
- }
+ {
+ case randomorder:
+ if (i >= lag)
+ k = y[i - lag];
+ else
+ /* Ensure that the array index is within bounds. */
+ k = y[(SIZE - i - 1 + lag) % SIZE];
+ j = y[i % SIZE];
+ break;
+
+ case ascending:
+ k = i - lag;
+ j = i;
+ break;
+
+ case descending:
+ k = SIZE - i - 1 + lag;
+ j = SIZE - i - 1;
+ break;
+
+ default:
+ /* This never should happen, but gcc isn't smart enough to
+ recognize it. */
+ abort ();
+ }
switch (what)
- {
- case build_and_del:
- case build:
- if (i < SIZE)
- {
- if (tfind (x + j, (void *const *) root, cmp_fn) != NULL)
- {
- fputs ("Found element which is not in tree yet.\n", stdout);
- error = 1;
- }
- elem = tsearch (x + j, root, cmp_fn);
- if (elem == 0
- || tfind (x + j, (void *const *) root, cmp_fn) == NULL)
- {
- fputs ("Couldn't find element after it was added.\n",
- stdout);
- error = 1;
- }
- }
-
- if (what == build || i < lag)
- break;
-
- j = k;
- /* fall through */
-
- case delete:
- elem = tfind (x + j, (void *const *) root, cmp_fn);
- if (elem == NULL || tdelete (x + j, root, cmp_fn) == NULL)
- {
- fputs ("Error deleting element.\n", stdout);
- error = 1;
- }
- break;
-
- case find:
- if (tfind (x + j, (void *const *) root, cmp_fn) == NULL)
- {
- fputs ("Couldn't find element after it was added.\n", stdout);
- error = 1;
- }
- break;
-
- }
+ {
+ case build_and_del:
+ case build:
+ if (i < SIZE)
+ {
+ if (tfind (x + j, (void *const *) root, cmp_fn) != NULL)
+ {
+ fputs ("Found element which is not in tree yet.\n", stdout);
+ error = 1;
+ }
+ elem = tsearch (x + j, root, cmp_fn);
+ if (elem == 0
+ || tfind (x + j, (void *const *) root, cmp_fn) == NULL)
+ {
+ fputs ("Couldn't find element after it was added.\n",
+ stdout);
+ error = 1;
+ }
+ }
+
+ if (what == build || i < lag)
+ break;
+
+ j = k;
+ /* fall through */
+
+ case delete:
+ elem = tfind (x + j, (void *const *) root, cmp_fn);
+ if (elem == NULL || tdelete (x + j, root, cmp_fn) == NULL)
+ {
+ fputs ("Error deleting element.\n", stdout);
+ error = 1;
+ }
+ break;
+
+ case find:
+ if (tfind (x + j, (void *const *) root, cmp_fn) == NULL)
+ {
+ fputs ("Couldn't find element after it was added.\n", stdout);
+ error = 1;
+ }
+ break;
+
+ }
}
}
mangle_tree (randomorder, delete, &root, 0);
for (j = 1; j < SIZE; j *= 2)
- {
- mangle_tree (randomorder, build_and_del, &root, j);
- }
+ {
+ mangle_tree (randomorder, build_and_del, &root, j);
+ }
fputs (error ? " failed!\n" : " ok.\n", stdout);
total_error |= error;