summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2000-05-08 23:09:09 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2000-05-08 23:09:09 (GMT)
commit04152995a9dbeed0bb4def400456bf3a9118d9aa (patch)
treed686863f122d6b0364afb1239e4aa346baf5db8e
parentcf6470e7f0ddb439a77382136a708131f3255471 (diff)
downloadhdf5-04152995a9dbeed0bb4def400456bf3a9118d9aa.zip
hdf5-04152995a9dbeed0bb4def400456bf3a9118d9aa.tar.gz
hdf5-04152995a9dbeed0bb4def400456bf3a9118d9aa.tar.bz2
[svn-r2222] Added TBBT testing code.
-rw-r--r--test/Makefile.in8
-rw-r--r--test/testhdf5.c1
-rw-r--r--test/testhdf5.h1
-rw-r--r--test/ttbbt.c146
4 files changed, 152 insertions, 4 deletions
diff --git a/test/Makefile.in b/test/Makefile.in
index f78fe78..2f0912d 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -57,9 +57,9 @@ TEST_SRC=big.c bittests.c chunk.c cmpd_dset.c dsets.c dtypes.c extend.c \
external.c fillval.c flush1.c flush2.c gheap.c h5test.c hyperslab.c \
iopipe.c istore.c lheap.c links.c mount.c mtime.c ohdr.c overhead.c \
ragged.c stab.c tattr.c testhdf5.c tfile.c th5s.c titerate.c tmeta.c \
- trefer.c tselect.c tvltypes.c tvlstr.c unlink.c enum.c gass_write.c \
- gass_read.c gass_append.c dpss_read.c dpss_write.c srb_read.c \
- srb_write.c srb_append.c
+ trefer.c tselect.c ttbbt.c tvltypes.c tvlstr.c unlink.c enum.c \
+ gass_write.c gass_read.c gass_append.c dpss_read.c dpss_write.c \
+ srb_read.c srb_write.c srb_append.c
TEST_OBJ=$(TEST_SRC:.c=.lo)
@@ -78,7 +78,7 @@ timings _timings: $(TIMINGS)
## How to build the tests... They all depend on the test and hdf5 libraries.
$(TEST_PROGS): $(LIB) $(LIBHDF5)
-TESTHDF5_OBJ=testhdf5.lo tattr.lo tfile.lo titerate.lo tmeta.lo trefer.lo tselect.lo tvltypes.lo tvlstr.lo th5s.lo
+TESTHDF5_OBJ=testhdf5.lo tattr.lo tfile.lo titerate.lo tmeta.lo trefer.lo tselect.lo ttbbt.lo tvltypes.lo tvlstr.lo th5s.lo
testhdf5: $(TESTHDF5_OBJ)
@$(LT_LINK_EXE) $(CFLAGS) -o $@ $(TESTHDF5_OBJ) $(LIB) $(LIBHDF5) $(LDFLAGS) $(LIBS)
diff --git a/test/testhdf5.c b/test/testhdf5.c
index 42577a4..ea88a7c 100644
--- a/test/testhdf5.c
+++ b/test/testhdf5.c
@@ -163,6 +163,7 @@ main(int argc, char *argv[])
/* Tests are generally arranged from least to most complexity... */
InitTest("metadata", test_metadata, cleanup_metadata, "Encode/decode metadata code");
+ InitTest("tbbt", test_tbbt, NULL, "Threaded, Balanced, Binary Trees");
InitTest("file", test_file, cleanup_file, "Low-Level File I/O");
InitTest("h5s", test_h5s, cleanup_h5s, "Dataspaces");
InitTest("attr", test_attr, cleanup_attr, "Attributes");
diff --git a/test/testhdf5.h b/test/testhdf5.h
index 8266d3b..ad0d19b 100644
--- a/test/testhdf5.h
+++ b/test/testhdf5.h
@@ -118,6 +118,7 @@ int print_func(const char *,...);
/* Prototypes for the test routines */
void test_metadata(void);
+void test_tbbt(void);
void test_file(void);
void test_h5t(void);
void test_h5s(void);
diff --git a/test/ttbbt.c b/test/ttbbt.c
new file mode 100644
index 0000000..c8006e0
--- /dev/null
+++ b/test/ttbbt.c
@@ -0,0 +1,146 @@
+/****************************************************************************
+ * NCSA HDF *
+ * Software Development Group *
+ * National Center for Supercomputing Applications *
+ * University of Illinois at Urbana-Champaign *
+ * 605 E. Springfield, Champaign IL 61820 *
+ * *
+ * For conditions of distribution and use, see the accompanying *
+ * hdf/COPYING file. *
+ * *
+ ****************************************************************************/
+
+#ifdef RCSID
+static char RcsId[] = "@(#)$Revision$";
+#endif
+
+/* $Id$ */
+
+/*
+ FILE
+ tbbt.c
+ Test HDF Threaded-Balanced-Binary Tree (tbbt) routines.
+
+ REMARKS
+
+ DESIGN
+
+ BUGS/LIMITATIONS
+
+ EXPORTED ROUTINES
+
+ AUTHOR
+ Quincey Koziol
+
+ MODIFICATION HISTORY
+ 4/22/00 - Converted from HDF4 test routine.
+ */
+
+#include <time.h>
+#include "testhdf5.h"
+#include "H5TBprivate.h"
+
+#define MAX_TEST_SIZE 31 /* maximum number of elements to insert */
+#define NUM_TEST_RUNS 100 /* number of times to insert & remove each size */
+
+#define RandInt(a,b) ((rand()%(((b)-(a))+1))+(a))
+
+intn tcompare (void * k1, void * k2, intn cmparg);
+
+static void swap_arr(int *arr, intn a, intn b)
+{
+ int t;
+
+ if (a != b)
+ {
+ t = arr[a];
+ arr[a] = arr[b];
+ arr[b] = t;
+ } /* end if */
+} /* end swap_arr() */
+
+intn
+tcompare(void * k1, void * k2, intn cmparg)
+{
+ /* shut compiler up */
+ cmparg=cmparg;
+ return ((intn) ((*(int *) k1) - (*(int *) k2)));
+}
+
+void
+test_tbbt(void)
+{
+ intn test_size;
+ intn i, j;
+ int ins_arr[MAX_TEST_SIZE];
+ int rem_arr[MAX_TEST_SIZE];
+ intn t;
+ TBBT_TREE *tree;
+ void * *r;
+
+ t = (intn)time(NULL);
+ srand((uintn)t);
+
+ for (test_size = 3; test_size <= MAX_TEST_SIZE; test_size++)
+ {
+ MESSAGE(7, ("\nTesting trees with %d elements\n", test_size));
+ MESSAGE(8, ("Testing tree #:"));
+ for (j = 0; j < NUM_TEST_RUNS; j++)
+ {
+ MESSAGE(8, (" %d", j));
+ for (i = 0; i < test_size; i++)
+ { /* initialize the arrays */
+ ins_arr[i] = i;
+ rem_arr[i] = i;
+ } /* end for */
+ for (i = 0; i < test_size; i++)
+ { /* shuffle the arrays */
+ t = RandInt(i, test_size - 1);
+ swap_arr(ins_arr, i, t);
+ t = RandInt(i, test_size - 1);
+ swap_arr(rem_arr, i, t);
+ } /* end for */
+
+ if (Verbosity > 9)
+ {
+ printf("ins_arr: \n");
+ for (i = 0; i < test_size; i++) /* print the arrays */
+ printf("%d \n", (int) ins_arr[i]);
+ printf("\nrem_arr: \n");
+ for (i = 0; i < test_size; i++) /* print the arrays */
+ printf("%d \n", (int) rem_arr[i]);
+ printf("\n");
+ } /* end if */
+
+ tree = H5TB_dmake(tcompare, sizeof(int),0);
+ for (i = 0; i < test_size; i++)
+ {
+ MESSAGE(9, ("inserting %d\n", (int) ins_arr[i]));
+ H5TB_dins(tree, (void *) &ins_arr[i], NULL);
+#ifdef H5TB_DEBUG
+ if(Verbosity>9)
+ H5TB_dump(tree, -1);
+#endif /* H5TB_DEBUG */
+ }
+#ifdef H5TB_DEBUG
+ if(Verbosity>9)
+ H5TB_dump(tree, -1);
+#endif /* H5TB_DEBUG */
+ for (i = 0; i < test_size; i++)
+ {
+ int key;
+
+ key = rem_arr[i];
+ r = (void * *) H5TB_dfind(tree, (void *) &key, NULL);
+ MESSAGE(9, ("removing %d\n", (int) key));
+ H5TB_rem((TBBT_NODE **) tree, (TBBT_NODE *) r, NULL);
+#ifdef H5TB_DEBUG
+ if(Verbosity>9)
+ H5TB_dump(tree, -1);
+#endif /* H5TB_DEBUG */
+ } /* end for */
+ H5TB_dfree(tree, NULL, NULL);
+ } /* end for */
+ } /* end for */
+} /* end test_tbbt() */
+