/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the COPYING file, which can be found at the root of the source code * * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Test HDF Skip List routines. REMARKS DESIGN BUGS/LIMITATIONS EXPORTED ROUTINES AUTHOR Quincey Koziol MODIFICATION HISTORY 11/15/04 - Started coding */ #include "testhdf5.h" #include "H5SLprivate.h" /* The number of elements in testing arrays */ #define NUM_ELEMS 1000 /* Random numbers */ static int *rand_num; static int *sort_rand_num; static int *rev_sort_rand_num; static int tst_sort(const void *i1, const void *i2) { return(*(const int *)i1-*(const int *)i2); } static int tst_rev_sort(const void *i1, const void *i2) { return(*(const int *)i2-*(const int *)i1); } /**************************************************************** ** ** test_skiplist_init(): Test H5SL (skiplist) code. ** Initialize data for skip list testing ** ****************************************************************/ static void test_skiplist_init(void) { time_t curr_time; /* Current time, for seeding random number generator */ int new_val; /* New value to insert */ unsigned found; /* Flag to indicate value was inserted already */ size_t u,v; /* Local index variables */ /* Allocate arrays */ rand_num = (int *)HDmalloc(sizeof(int) * NUM_ELEMS); CHECK(rand_num, NULL, "HDmalloc"); sort_rand_num = (int *)HDmalloc(sizeof(int) * NUM_ELEMS); CHECK(sort_rand_num, NULL, "HDmalloc"); rev_sort_rand_num = (int *)HDmalloc(sizeof(int) * NUM_ELEMS); CHECK(rev_sort_rand_num, NULL, "HDmalloc"); /* Initialize random number seed */ curr_time = HDtime(NULL); HDsrandom((unsigned)curr_time); /* Create randomized set of numbers */ for(u = 0; u < NUM_ELEMS; u++) { do { /* Reset flag */ found = 0; /* Generate random numbers from -5000 to 5000 */ new_val = (int)(HDrandom() % 10001) - 5001; /* Check if the value is already in the array */ for(v = 0; v < u; v++) if(rand_num[v] == new_val) found = 1; } while(found); /* Set unique value in array */ rand_num[u]=new_val; } /* end for */ /* Copy random values to sorted array */ HDmemcpy(sort_rand_num, rand_num, sizeof(int) * NUM_ELEMS); /* Sort random numbers */ HDqsort(sort_rand_num, (size_t)NUM_ELEMS, sizeof(int), tst_sort); /* Copy random values to reverse sorted array */ HDmemcpy(rev_sort_rand_num, rand_num, sizeof(int) * NUM_ELEMS); /* Sort random numbers */ HDqsort(rev_sort_rand_num, (size_t)NUM_ELEMS, sizeof(int), tst_rev_sort); } /* end test_skiplist_init() */ /**************************************************************** ** ** test_skiplist_create(): Test basic H5SL (skiplist) code. ** Tests creating and closing skip lists. ** ****************************************************************/ static void test_skiplist_create(void) { H5SL_t *slist; /* Skip list created */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(6, ("Testing Creating & Closing Skip Lists\n")); /* Try creating a skip list */ slist = H5SL_create(H5SL_TYPE_INT, NULL); CHECK(slist, NULL, "H5SL_create"); /* Try closing the skip list */ ret=H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_create() */ /**************************************************************** ** ** test_skiplist_insert(): Test H5SL (skip list) code. ** Tests inserting single object into skip list. ** ****************************************************************/ static void test_skiplist_insert(void) { H5SL_t *slist; /* Skip list created */ int key, /* Key of item to insert */ item; /* Item to insert */ int search_key; /* Key of item to search for in skip list */ int *found_item; /* Item found in skip list */ size_t num; /* Number of elements in skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Insertion Into Skip List\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_INT, NULL); CHECK(slist, NULL, "H5SL_create"); /* Check that the skip list has no elements */ num=H5SL_count(slist); VERIFY(num, 0, "H5SL_count"); /* Try searching for item in empty skip list */ key=37; found_item=(int *)H5SL_search(slist,&key); VERIFY(found_item, NULL, "H5SL_search"); /* Insert an object into the skip list */ key=2; item=10; ret=H5SL_insert(slist,&item,&key); CHECK(ret, FAIL, "H5SL_insert"); /* Check that the skip list has one element */ num=H5SL_count(slist); VERIFY(num, 1, "H5SL_count"); /* Search for the item just inserted */ found_item=(int *)H5SL_search(slist,&key); CHECK(found_item, NULL, "H5SL_search"); VERIFY(*found_item,item,"H5SL_search"); /* Search for an item not in list */ search_key=37; found_item=(int *)H5SL_search(slist,&search_key); VERIFY(found_item, NULL, "H5SL_search"); /* Attempt to insert duplicate key (should fail) */ search_key=2; ret=H5SL_insert(slist,&search_key,&search_key); VERIFY(ret, FAIL, "H5SL_insert"); /* Close the skip list */ ret=H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_insert() */ /**************************************************************** ** ** test_skiplist_insert_many(): Test H5SL (skip list) code. ** Tests inserting many objects into skip list. ** ****************************************************************/ static void test_skiplist_insert_many(void) { H5SL_t *slist; /* Skip list created */ size_t num; /* Number of elements in skip list */ size_t u; /* Local index variable */ int *found_item; /* Item found in skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Insertion of Many Items Into Skip List\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_INT, NULL); CHECK(slist, NULL, "H5SL_create"); /* Check that the skip list has no elements */ num=H5SL_count(slist); VERIFY(num, 0, "H5SL_count"); /* Insert many objects into the skip list */ for(u=0; ui, hashed_data[u].i, "H5SL_next"); u++; node=H5SL_next(node); } /* end while */ /* Close the skip list */ ret=H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_string() */ static herr_t test_skiplist_iter(void *item, void H5_ATTR_UNUSED *key, void *op_data) { size_t *up=(size_t *)op_data; VERIFY(*(int *)item,sort_rand_num[*up],"H5SL_iterate"); (*up)++; return(0); } /**************************************************************** ** ** test_skiplist_iterate(): Test H5SL (skip list) code. ** Tests iterating over nodes in skip list with callbacks. ** ****************************************************************/ static void test_skiplist_iterate(void) { H5SL_t *slist; /* Skip list created */ size_t num; /* Number of elements in skip list */ size_t u; /* Local index variable */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Iterating Over Skip List\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_INT, NULL); CHECK(slist, NULL, "H5SL_create"); /* Check that the skip list has no elements */ num=H5SL_count(slist); VERIFY(num, 0, "H5SL_count"); /* Insert many objects into the skip list */ for(u=0; ufileno,sorted_data[u].fileno,"H5SL_next"); VERIFY(found_item->addr,sorted_data[u].addr,"H5SL_next"); u++; node=H5SL_next(node); } /* end while */ /* Close the skip list */ ret=H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_obj() */ /**************************************************************** ** ** test_skiplist_generic(): Test H5SL (skip list) code. ** Tests using generic keys in skip lists. Define ** structure for keys, and define comparison using ** key.a-key.b. ** ****************************************************************/ typedef struct generic_t { unsigned a; unsigned b; } generic_t; static int test_skiplist_generic_cmp(const void *_key1, const void *_key2) { const generic_t *key1 = (const generic_t *)_key1; const generic_t *key2 = (const generic_t *)_key2; long long result = (long long)(key1->a) - (long long)(key1->b) - (long long)(key2->a) + (long long)(key2->b); if(result < 0) return -1; else if(result > 0) return 1; else return 0; } /* end test_skiplist_generic_cmp */ static void test_skiplist_generic(void) { H5SL_t *slist; /* Skip list created */ H5SL_node_t *node; /* Skip list node */ size_t num; /* Number of elements in skip list */ size_t u; /* Local index variable */ generic_t data[10]={ {10, 1}, {20, 13}, {15, 32}, {5, 2}, {50, 37}, {30, 100}, {31, 38}, {32, 34}, {80, 32}, {90, 0} }; generic_t sorted_data[10]={ {30, 100}, {15, 32}, {31, 38}, {32, 34}, {5, 2}, {20, 13}, {10, 1}, {50, 37}, {80, 32}, {90, 0} }; generic_t *found_item; /* Item found in skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List With generic Keys\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_GENERIC, test_skiplist_generic_cmp); CHECK(slist, NULL, "H5SL_create"); /* Check that the skip list has no elements */ num=H5SL_count(slist); VERIFY(num, 0, "H5SL_count"); /* Insert objects into the skip list */ for(u=0; u<10; u++) { ret=H5SL_insert(slist,&data[u],&data[u]); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Check that the skip list has correct # of elements */ num=H5SL_count(slist); VERIFY(num, 10, "H5SL_count"); /* Iterate over all the nodes in the skip list */ node=H5SL_first(slist); u=0; while(node!=NULL) { found_item=(generic_t *)H5SL_item(node); VERIFY(found_item->a,sorted_data[u].a,"H5SL_next"); VERIFY(found_item->b,sorted_data[u].b,"H5SL_next"); u++; node=H5SL_next(node); } /* end while */ /* Close the skip list */ ret=H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_generic() */ /**************************************************************** ** ** test_skiplist_lastprev(): Test H5SL (skip list) code. ** Tests iterating over nodes in skip list with last/prev calls. ** ****************************************************************/ static void test_skiplist_lastprev(void) { H5SL_t *slist; /* Skip list created */ H5SL_node_t *node; /* Skip list node */ size_t num; /* Number of elements in skip list */ size_t u; /* Local index variable */ int *found_item; /* Item found in skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Iterating Over Skip List With Last/Prev\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_INT, NULL); CHECK(slist, NULL, "H5SL_create"); /* Check that the skip list has no elements */ num=H5SL_count(slist); VERIFY(num, 0, "H5SL_count"); /* Check that the list appears empty */ node=H5SL_last(slist); VERIFY(node, NULL, "H5SL_last"); /* Insert many objects into the skip list */ for(u=0; uidx, key, "obj->idx"); VERIFY(obj, &udata->obj_list->list[obj->idx], "obj_list->list[obj->idx]"); /* Increment number of calls */ udata->ncalls++; /* Verify we were given the correct object */ do { udata->last_idx++; } while(udata->obj_list->list[udata->last_idx].nfrees != 0); VERIFY(udata->last_idx, obj->idx, "H5SL_iterate"); return 0; } /* end test_tfs_iter() */ /* try_free_safe callback */ static htri_t test_tfs_free(void *_obj, void *key, void *_obj_list) { test_tfs_obj_t *obj = (test_tfs_obj_t *)_obj; test_tfs_list_t *obj_list = (test_tfs_list_t *)_obj_list; test_tfs_it_ud_t iter_ud; int nrems, rem_idx, i, j; test_tfs_obj_t *obj_ret; herr_t ret; /* return value */ htri_t ret_value; /* Check consistency */ VERIFY((void *)&obj->idx, key, "obj->idx"); VERIFY(obj, &obj_list->list[obj->idx], "obj_list->list[obj->idx]"); /* Mark this object as freed (to make sure it isn't recursively freed, that * is not something we support, we will undo this if we decide later not to * free the object) */ obj->nfrees++; obj_list->nobjs_rem--; /* Decide how many objects to remove */ nrems = (int)(HDrandom() % (long)3); /* Remove objects */ for(i = 0; i < nrems; i++) /* Check nobjs_rem */ if(obj_list->nobjs_rem > 0) { /* Remove a random object from the list */ rem_idx = (int)(HDrandom() % (long)obj_list->nobjs_rem); /* Scan the list, finding the rem_idx'th object that has not been * freed */ for(j = 0; j < obj_list->nobjs; j++) if(obj_list->list[j].nfrees == 0) { if(rem_idx == 0) break; else rem_idx--; } /* end if */ if(j == obj_list->nobjs) ERROR("invalid obj_list"); else { /* Remove the object */ obj_ret = (test_tfs_obj_t *)H5SL_remove(obj_list->slist, &j); CHECK(obj_ret, NULL, "H5SL_remove"); obj_ret->nfrees++; obj_list->nobjs_rem--; } /* end else */ } /* end if */ /* Mark this object as not freed so we know to expect it in the iterate call */ obj->nfrees--; obj_list->nobjs_rem++; /* Iterate over skip list (maybe) */ if(HDrandom() % (long)5) { iter_ud.obj_list = obj_list; iter_ud.last_idx = -1; iter_ud.ncalls = 0; ret = H5SL_iterate(obj_list->slist, test_tfs_iter, &iter_ud); CHECK(ret, FAIL, "H5SL_iterate"); VERIFY(iter_ud.ncalls, obj_list->nobjs_rem, "H5SL_iterate"); } /* end if */ /* Verify nobjs_rem is non-negative */ if(obj_list->nobjs_rem < 0) ERROR("invalid nobjs_rem"); /* Decide whether this object should be freed */ if(HDrandom() % (long)2) { /* Free the object */ ret_value = TRUE; obj->nfrees++; obj_list->nobjs_rem--; } /* end if */ else /* Do not free the object */ ret_value = FALSE; return ret_value; } /* end test_tfs_free() */ /* Test function */ static void test_skiplist_try_free_safe(void) { test_tfs_list_t obj_list; test_tfs_obj_t list[TEST_TFS_MAX_NOBJS]; int i, j; int nobjs_found; hsize_t count; herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List 'Try Free Safe' Operation\n")); /* Create a skip list */ obj_list.slist = H5SL_create(H5SL_TYPE_INT, NULL); CHECK(obj_list.slist, NULL, "H5SL_create"); /* Init obj_list.list */ obj_list.list = list; for(j = 0; j < TEST_TFS_MAX_NOBJS; j++) list[j].idx = j; for(i = 0; i < TEST_TFS_NITER; i++) { /* Build object list */ obj_list.nobjs = obj_list.nobjs_rem = (int)(TEST_TFS_MIN_NOBJS + (HDrandom() % (long)(TEST_TFS_MAX_NOBJS - TEST_TFS_MIN_NOBJS + 1))); for(j = 0; j < obj_list.nobjs; j++) { list[j].nfrees = 0; ret = H5SL_insert(obj_list.slist, &list[j], &list[j].idx); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Call H5S_try_free_safe() - free most of the items in the skip list in * a safe manner */ ret = H5SL_try_free_safe(obj_list.slist, test_tfs_free, &obj_list); CHECK(ret, FAIL, "H5SL_try_free_safe"); /* Verify list */ nobjs_found = 0; for(j = 0; j < obj_list.nobjs; j++) if(list[j].nfrees == 0) nobjs_found++; else VERIFY(list[j].nfrees, (long)1, "list[j].nfrees"); /* Verify number of objects */ VERIFY(obj_list.nobjs_rem, nobjs_found, "obj_list.nobjs_rem"); count = H5SL_count(obj_list.slist); VERIFY(count, (size_t)nobjs_found, "H5SL_count"); /* Release the skip list, forcibly freeing all nodes (will not make * callbacks) */ ret = H5SL_release(obj_list.slist); CHECK(ret, FAIL, "H5SL_release"); /* Verify number of objects is 0 */ count = H5SL_count(obj_list.slist); VERIFY(count, (size_t)0, "H5SL_count"); } /* end for */ /* Close the skip list */ ret = H5SL_close(obj_list.slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_try_free_safe() */ /**************************************************************** ** ** test_skiplist_less(): Test H5SL (skip list) code. ** Tests 'less' operation in skip lists. ** ****************************************************************/ static void test_skiplist_less(void) { H5SL_t *slist; /* Skip list created */ size_t u; /* Local index variable */ unsigned data[10]={ 10, 20, 15, 5, 50, 30, 31, 32, 80, 90}; /* unsigned sorted_data[10]={ 5, 10, 15, 20, 30, 31, 32, 50, 80, 90}; */ unsigned *found_item; /* Item found in skip list */ unsigned find_item; /* Item to add to skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List 'Less' Operation\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL); CHECK(slist, NULL, "H5SL_create"); /* Insert objects into the skip list */ for(u=0; u<10; u++) { ret=H5SL_insert(slist,&data[u],&data[u]); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Check for exact match of items in various positions */ find_item=20; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(*found_item,find_item,"H5SL_less"); find_item=90; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(*found_item,find_item,"H5SL_less"); find_item=5; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(*found_item,find_item,"H5SL_less"); /* Find item less than a missing key, in various positions */ find_item=19; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(*found_item,15,"H5SL_less"); find_item=89; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(*found_item,80,"H5SL_less"); find_item=100; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(*found_item,90,"H5SL_less"); find_item=9; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(*found_item,5,"H5SL_less"); find_item=4; found_item=(unsigned *)H5SL_less(slist,&find_item); VERIFY(found_item,NULL,"H5SL_less"); /* Close the skip list */ ret=H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_less() */ /**************************************************************** ** ** test_skiplist_greater(): Test H5SL (skip list) code. ** Tests 'greater' operation in skip lists. ** ****************************************************************/ static void test_skiplist_greater(void) { H5SL_t *slist; /* Skip list created */ size_t u; /* Local index variable */ unsigned data[10]={ 10, 20, 15, 5, 50, 30, 31, 32, 80, 90}; /* unsigned sorted_data[10]={ 5, 10, 15, 20, 30, 31, 32, 50, 80, 90}; */ unsigned *found_item; /* Item found in skip list */ unsigned find_item; /* Item to add to skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List 'Greater' Operation\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL); CHECK(slist, NULL, "H5SL_create"); /* Insert objects into the skip list */ for(u = 0; u < 10; u++) { ret = H5SL_insert(slist, &data[u], &data[u]); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Check for exact match of items in various positions */ find_item = 20; found_item = (unsigned *)H5SL_greater(slist, &find_item); VERIFY(*found_item, find_item, "H5SL_greater"); find_item = 90; found_item = (unsigned *)H5SL_greater(slist, &find_item); VERIFY(*found_item, find_item, "H5SL_greater"); find_item = 5; found_item = (unsigned *)H5SL_greater(slist, &find_item); VERIFY(*found_item, find_item, "H5SL_greater"); /* Find item greater than a missing key, in various positions */ find_item = 19; found_item = (unsigned *)H5SL_greater(slist,&find_item); VERIFY(*found_item, 20, "H5SL_greater"); find_item = 89; found_item = (unsigned *)H5SL_greater(slist, &find_item); VERIFY(*found_item, 90, "H5SL_greater"); find_item = 100; found_item = (unsigned *)H5SL_greater(slist, &find_item); VERIFY(found_item, NULL, "H5SL_greater"); find_item = 6; found_item = (unsigned *)H5SL_greater(slist, &find_item); VERIFY(*found_item, 10, "H5SL_greater"); find_item = 4; found_item = (unsigned *)H5SL_greater(slist, &find_item); VERIFY(*found_item, 5, "H5SL_greater"); /* Close the skip list */ ret = H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_greater() */ /**************************************************************** ** ** test_skiplist_below(): Test H5SL (skip list) code. ** Tests 'below' operation in skip lists. ** ****************************************************************/ static void test_skiplist_below(void) { H5SL_t *slist; /* Skip list created */ H5SL_node_t *node; /* Skip list node */ size_t u; /* Local index variable */ unsigned data[10]={ 10, 20, 15, 5, 50, 30, 31, 32, 80, 90}; /* unsigned sorted_data[10]={ 5, 10, 15, 20, 30, 31, 32, 50, 80, 90}; */ unsigned *found_item; /* Item found in skip list */ unsigned find_item; /* Item to add to skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List 'Below' Operation\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL); CHECK(slist, NULL, "H5SL_create"); /* Insert objects into the skip list */ for(u = 0; u < 10; u++) { ret = H5SL_insert(slist, &data[u], &data[u]); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Check for exact match of items in various positions */ find_item = 20; node = H5SL_below(slist, &find_item); CHECK(node, NULL, "H5SL_below"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, find_item, "H5SL_below"); find_item = 90; node = H5SL_below(slist, &find_item); CHECK(node, NULL, "H5SL_below"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, find_item, "H5SL_below"); find_item = 5; node = H5SL_below(slist, &find_item); CHECK(node, NULL, "H5SL_below"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, find_item, "H5SL_below"); /* Find item less than a missing key, in various positions */ find_item = 19; node = H5SL_below(slist, &find_item); CHECK(node, NULL, "H5SL_below"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 15, "H5SL_below"); find_item = 89; node = H5SL_below(slist, &find_item); CHECK(node, NULL, "H5SL_below"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 80, "H5SL_below"); find_item = 100; node = H5SL_below(slist, &find_item); CHECK(node, NULL, "H5SL_below"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 90, "H5SL_below"); find_item = 9; node = H5SL_below(slist, &find_item); CHECK(node, NULL, "H5SL_below"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 5, "H5SL_below"); find_item = 4; node = (H5SL_node_t *)H5SL_less(slist, &find_item); VERIFY(node, NULL, "H5SL_below"); /* Close the skip list */ ret = H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_below() */ /**************************************************************** ** ** test_skiplist_above(): Test H5SL (skip list) code. ** Tests 'above' operation in skip lists. ** ****************************************************************/ static void test_skiplist_above(void) { H5SL_t *slist; /* Skip list created */ H5SL_node_t *node; /* Skip list node */ size_t u; /* Local index variable */ unsigned data[10]={ 10, 20, 15, 5, 50, 30, 31, 32, 80, 90}; /* unsigned sorted_data[10]={ 5, 10, 15, 20, 30, 31, 32, 50, 80, 90}; */ unsigned *found_item; /* Item found in skip list */ unsigned find_item; /* Item to add to skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List 'Above' Operation\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL); CHECK(slist, NULL, "H5SL_create"); /* Insert objects into the skip list */ for(u = 0; u < 10; u++) { ret = H5SL_insert(slist, &data[u], &data[u]); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Check for exact match of items in various positions */ find_item = 20; node = H5SL_above(slist, &find_item); CHECK(node, NULL, "H5SL_above"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, find_item, "H5SL_above"); find_item = 90; node = H5SL_above(slist, &find_item); CHECK(node, NULL, "H5SL_above"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, find_item, "H5SL_above"); find_item = 5; node = H5SL_above(slist, &find_item); CHECK(node, NULL, "H5SL_above"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, find_item, "H5SL_above"); /* Find item greater than a missing key, in various positions */ find_item = 19; node = H5SL_above(slist, &find_item); CHECK(node, NULL, "H5SL_above"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 20, "H5SL_above"); find_item = 89; node = H5SL_above(slist, &find_item); CHECK(node, NULL, "H5SL_above"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 90, "H5SL_above"); find_item = 100; node = H5SL_above(slist, &find_item); VERIFY(node, NULL, "H5SL_above"); find_item = 6; node = H5SL_above(slist, &find_item); CHECK(node, NULL, "H5SL_above"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 10, "H5SL_above"); find_item = 4; node = H5SL_above(slist, &find_item); CHECK(node, NULL, "H5SL_above"); found_item = (unsigned *)H5SL_item(node); VERIFY(*found_item, 5, "H5SL_above"); /* Close the skip list */ ret = H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_above() */ /**************************************************************** ** ** test_skiplist_remote_first(): Test H5SL (skip list) code. ** Tests 'remove first' operation in skip lists. ** ****************************************************************/ static void test_skiplist_remove_first(void) { H5SL_t *slist; /* Skip list created */ size_t u; /* Local index variable */ unsigned data[10]={ 10, 20, 15, 5, 50, 30, 31, 32, 80, 90}; unsigned sorted_data[10]={ 5, 10, 15, 20, 30, 31, 32, 50, 80, 90}; unsigned *found_item; /* Item found in skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List 'Remove First' Operation\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL); CHECK(slist, NULL, "H5SL_create"); /* Insert objects into the skip list */ for(u = 0; u < 10; u++) { ret = H5SL_insert(slist, &data[u], &data[u]); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Remove objects from the skip list */ for(u = 0; u < 10; u++) { found_item = (unsigned *)H5SL_remove_first(slist); VERIFY(*found_item, sorted_data[u], "H5SL_remove_first"); } /* end for */ /* Check for removing object from empty list */ found_item = (unsigned *)H5SL_remove_first(slist); VERIFY(found_item, NULL, "H5SL_remove_first"); /* Close the skip list */ ret = H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_remove_first() */ /**************************************************************** ** ** test_skiplist_remote_first_many(): Test H5SL (skip list) code. ** Tests 'remove first' operation in large skip lists. ** ****************************************************************/ static void test_skiplist_remove_first_many(void) { H5SL_t *slist; /* Skip list created */ size_t u; /* Local index variable */ int *found_item; /* Item found in skip list */ int prev_item = INT_MIN; /* Previously found item in skip list */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(7, ("Testing Skip List 'Remove First' Operation\n")); /* Create a skip list */ slist = H5SL_create(H5SL_TYPE_INT, NULL); CHECK(slist, NULL, "H5SL_create"); /* Insert objects into the skip list */ for(u = 0; u < NUM_ELEMS; u++) { ret = H5SL_insert(slist, &rand_num[u], &rand_num[u]); CHECK(ret, FAIL, "H5SL_insert"); } /* end for */ /* Remove objects from the skip list */ for(u = 0; u < NUM_ELEMS; u++) { found_item = (int *)H5SL_remove_first(slist); VERIFY(*found_item > prev_item, TRUE, "H5SL_remove_first"); prev_item = *found_item; } /* end for */ /* Check for removing object from empty list */ found_item = (int *)H5SL_remove_first(slist); VERIFY(found_item, NULL, "H5SL_remove_first"); /* Close the skip list */ ret = H5SL_close(slist); CHECK(ret, FAIL, "H5SL_close"); } /* end test_skiplist_remove_first() */ /**************************************************************** ** ** test_skiplist_term(): Test H5SL (skiplist) code. ** Release data for skip list testing ** ****************************************************************/ static void test_skiplist_term(void) { /* Release arrays */ if(rand_num) HDfree(rand_num); if(sort_rand_num) HDfree(sort_rand_num); if(rev_sort_rand_num) HDfree(rev_sort_rand_num); } /* end test_skiplist_term() */ /**************************************************************** ** ** test_skiplist(): Main H5SL testing routine. ** ****************************************************************/ void test_skiplist(void) { /* Output message about test being performed */ MESSAGE(5, ("Testing Skip Lists\n")); /* Initialize skip list testing data */ test_skiplist_init(); /* Actual skip list tests */ test_skiplist_create(); /* Test skip list creation */ test_skiplist_insert(); /* Test basic skip list insertion */ test_skiplist_insert_many(); /* Test insertion of many items into skip list */ test_skiplist_remove(); /* Test basic skip list removal */ test_skiplist_remove_many(); /* Test removal of many items from skip list */ test_skiplist_firstnext(); /* Test iteration over skip list nodes with first/next */ test_skiplist_string(); /* Test skip list string keys */ test_skiplist_iterate(); /* Test iteration over skip list nodes with callback */ test_skiplist_hsize(); /* Test skip list hsize_t keys */ test_skiplist_unsigned(); /* Test skip list unsigned keys */ test_skiplist_obj(); /* Test skip list H5_obj_t keys */ test_skiplist_generic(); /* Test skip list generic keys */ test_skiplist_lastprev(); /* Test iteration over skip list nodes with last/prev */ test_skiplist_find(); /* Test 'find' operation */ test_skiplist_add(); /* Test 'add' operation */ test_skiplist_destroy(); /* Test 'destroy' operation */ test_skiplist_free(); /* Test 'free' operation */ test_skiplist_try_free_safe(); /* Test 'try_free_safe' operation */ test_skiplist_less(); /* Test 'less' operation */ test_skiplist_greater(); /* Test 'greater' operation */ test_skiplist_below(); /* Test 'below' operation */ test_skiplist_above(); /* Test 'above' operation */ test_skiplist_remove_first(); /* Test 'remove first' operation */ test_skiplist_remove_first_many(); /* Test 'remove first' operation on large skip lists */ /* Release skip list testing data */ test_skiplist_term(); } /* end test_skiplist() */