1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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_PTR(rand_num, "HDmalloc");
sort_rand_num = (int *)HDmalloc(sizeof(int) * NUM_ELEMS);
CHECK_PTR(sort_rand_num, "HDmalloc");
rev_sort_rand_num = (int *)HDmalloc(sizeof(int) * NUM_ELEMS);
CHECK_PTR(rev_sort_rand_num, "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_PTR(slist, "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_PTR(slist, "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);
CHECK_PTR_NULL(found_item, "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_PTR(found_item, "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);
CHECK_PTR_NULL(found_item, "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_PTR(slist, "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; u<NUM_ELEMS; u++) {
ret=H5SL_insert(slist,&rand_num[u],&rand_num[u]);
CHECK(ret, FAIL, "H5SL_insert");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Search for all objects in the skip list */
for(u=0; u<NUM_ELEMS; u++) {
found_item=(int *)H5SL_search(slist,&rand_num[u]);
CHECK_PTR(found_item, "H5SL_search");
VERIFY(*found_item,rand_num[u],"H5SL_search");
} /* end for */
/* Release all the items from the list */
ret=H5SL_release(slist);
CHECK(ret, FAIL, "H5SL_release");
/* 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; u<NUM_ELEMS; u++) {
ret=H5SL_insert(slist,&rand_num[u],&rand_num[u]);
CHECK(ret, FAIL, "H5SL_insert");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Release all the items from the list */
ret=H5SL_release(slist);
CHECK(ret, FAIL, "H5SL_release");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_insert_many() */
/****************************************************************
**
** test_skiplist_remove(): Test H5SL (skip list) code.
** Tests basic object removal from skip list.
**
****************************************************************/
static void
test_skiplist_remove(void)
{
H5SL_t *slist; /* Skip list created */
int key1, /* Key of 1st item to insert */
key2, /* Key of 2nd item to insert */
key3; /* Key of 3rd 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 Removal From Skip List\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_INT, NULL);
CHECK_PTR(slist, "H5SL_create");
/* Check that the skip list has no elements */
num=H5SL_count(slist);
VERIFY(num, 0, "H5SL_count");
/* Try removing an item in empty skip list */
search_key=37;
found_item=(int *)H5SL_remove(slist,&search_key);
CHECK_PTR_NULL(found_item, "H5SL_remove");
/* Insert three objects into the skip list */
key1=15;
ret=H5SL_insert(slist,&key1,&key1);
CHECK(ret, FAIL, "H5SL_insert");
key2=10;
ret=H5SL_insert(slist,&key2,&key2);
CHECK(ret, FAIL, "H5SL_insert");
key3=20;
ret=H5SL_insert(slist,&key3,&key3);
CHECK(ret, FAIL, "H5SL_insert");
/* Check that the skip list has three elements */
num=H5SL_count(slist);
VERIFY(num, 3, "H5SL_count");
/* Try removing items from skip list */
search_key=key1;
found_item=(int *)H5SL_remove(slist,&search_key);
CHECK_PTR(found_item, "H5SL_remove");
CHECK_PTR_EQ(found_item, &key1, "H5SL_remove");
search_key=key2;
found_item=(int *)H5SL_remove(slist,&search_key);
CHECK_PTR(found_item, "H5SL_remove");
CHECK_PTR_EQ(found_item, &key2, "H5SL_remove");
search_key=key3;
found_item=(int *)H5SL_remove(slist,&search_key);
CHECK_PTR(found_item, "H5SL_remove");
CHECK_PTR_EQ(found_item, &key3, "H5SL_remove");
/* Check that the skip list has no elements */
num=H5SL_count(slist);
VERIFY(num, 0, "H5SL_count");
/* Try removing items from empty skip list (after its been worked on) */
search_key=key1;
found_item=(int *)H5SL_remove(slist,&search_key);
CHECK_PTR_NULL(found_item, "H5SL_remove");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_remove() */
/****************************************************************
**
** test_skiplist_remove_many(): Test H5SL (skip list) code.
** Tests removing many objects from skip list.
**
****************************************************************/
static void
test_skiplist_remove_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 Removal of Many Items From Skip List\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_INT, NULL);
CHECK_PTR(slist, "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; u<NUM_ELEMS; u++) {
ret=H5SL_insert(slist,&rand_num[u],&rand_num[u]);
CHECK(ret, FAIL, "H5SL_insert");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Remove all objects from the skip list (in random order) */
for(u=0; u<NUM_ELEMS; u++) {
found_item=(int *)H5SL_remove(slist,&rand_num[u]);
CHECK_PTR(found_item, "H5SL_remove");
VERIFY(*found_item,rand_num[u],"H5SL_remove");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, 0, "H5SL_count");
/* Insert & remove again (in sorted order), to check that completely empty skip lists can be added again */
/* Insert many 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 */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Remove all objects from the skip list */
for(u=0; u<NUM_ELEMS; u++) {
found_item=(int *)H5SL_remove(slist,&sort_rand_num[u]);
CHECK_PTR(found_item, "H5SL_remove");
VERIFY(*found_item,sort_rand_num[u],"H5SL_remove");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, 0, "H5SL_count");
/* Insert & remove again (in reverse sorted order), to check that completely empty skip lists can be added again */
/* Insert many 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 */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Remove all objects from the skip list */
for(u=0; u<NUM_ELEMS; u++) {
found_item=(int *)H5SL_remove(slist,&rev_sort_rand_num[u]);
CHECK_PTR(found_item, "H5SL_remove");
VERIFY(*found_item,rev_sort_rand_num[u],"H5SL_remove");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, 0, "H5SL_count");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_remove_many() */
/****************************************************************
**
** test_skiplist_firstnext(): Test H5SL (skip list) code.
** Tests iterating over nodes in skip list with first/next calls.
**
****************************************************************/
static void
test_skiplist_firstnext(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 First/Next\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_INT, NULL);
CHECK_PTR(slist, "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_first(slist);
CHECK_PTR_NULL(node, "H5SL_first");
/* Insert many 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 */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Iterate over all the nodes in the skip list */
node=H5SL_first(slist);
CHECK_PTR(node, "H5SL_first");
u=0;
while(node!=NULL) {
found_item=(int *)H5SL_item(node);
VERIFY(*found_item,sort_rand_num[u],"H5SL_next");
u++;
node=H5SL_next(node);
} /* end while */
/* Release all the items from the list */
ret=H5SL_release(slist);
CHECK(ret, FAIL, "H5SL_release");
/* Check that the list appears empty again */
node=H5SL_first(slist);
CHECK_PTR_NULL(node, "H5SL_first");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_firstnext() */
/****************************************************************
**
** test_skiplist_string(): Test H5SL (skip list) code.
** Tests using strings for keys in skip lists.
**
****************************************************************/
static void
test_skiplist_string(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 */
typedef struct string_node {
int i;
const char *s;
} string_node;
string_node data[10]={
{10,"10"},
{20,"20"},
{15,"15"},
{ 5,"05"},
{50,"50"},
{30,"30"},
{31,"31"},
{32,"32"},
{80,"80"},
{90,"90"}};
string_node hashed_data[10]={
{ 5,"05"},
{10,"10"},
{15,"15"},
{20,"20"},
{30,"30"},
{31,"31"},
{32,"32"},
{50,"50"},
{80,"80"},
{90,"90"}
};
string_node *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 String Keys\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_STR, NULL);
CHECK_PTR(slist, "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].s);
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=(string_node *)H5SL_item(node);
VERIFY(found_item->i, 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_PTR(slist, "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; u<NUM_ELEMS; u++) {
ret=H5SL_insert(slist,&rand_num[u],&rand_num[u]);
CHECK(ret, FAIL, "H5SL_insert");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Iterate over all the nodes in the skip list */
u=0;
ret=H5SL_iterate(slist,test_skiplist_iter,&u);
CHECK(ret, FAIL, "H5SL_iterate");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_iterate() */
/****************************************************************
**
** test_skiplist_hsize(): Test H5SL (skip list) code.
** Tests using hsize_t for keys in skip lists.
**
****************************************************************/
static void
test_skiplist_hsize(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 */
hsize_t data[10]={ 10, 20, 15, 5, 50, 30, 31, 32, 80, 90};
hsize_t sorted_data[10]={ 5, 10, 15, 20, 30, 31, 32, 50, 80, 90};
hsize_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 hsize_t Keys\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_HSIZE, NULL);
CHECK_PTR(slist, "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=(hsize_t *)H5SL_item(node);
VERIFY(*found_item,sorted_data[u],"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_hsize() */
/****************************************************************
**
** test_skiplist_unsigned(): Test H5SL (skip list) code.
** Tests using unsigned for keys in skip lists.
**
****************************************************************/
static void
test_skiplist_unsigned(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 */
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 With unsigned Keys\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL);
CHECK_PTR(slist, "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=(unsigned *)H5SL_item(node);
VERIFY(*found_item,sorted_data[u],"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_unsigned() */
/****************************************************************
**
** test_skiplist_obj(): Test H5SL (skip list) code.
** Tests using H5_obj_t's for keys in skip lists.
**
****************************************************************/
static void
test_skiplist_obj(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 */
H5_obj_t data[10]={ {10, 12}, {20, 12}, {10, 32}, {10, 11}, {50, 1}, {8, 12}, {31, 12}, {20, 11}, {31, 11}, {8, 32} };
H5_obj_t sorted_data[10]={ {8, 12}, {8, 32}, {10, 11}, {10, 12}, {10, 32}, {20, 11}, {20, 12}, {31, 11}, {31, 12}, {50, 1} };
H5_obj_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 H5_obj_t Keys\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_OBJ, NULL);
CHECK_PTR(slist, "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=(H5_obj_t *)H5SL_item(node);
VERIFY(found_item->fileno,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_PTR(slist, "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_PTR(slist, "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);
CHECK_PTR_NULL(node, "H5SL_last");
/* Insert many 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 */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Iterate over all the nodes in the skip list */
node=H5SL_last(slist);
CHECK_PTR(node, "H5SL_last");
u=NUM_ELEMS-1;
while(node!=NULL) {
found_item=(int *)H5SL_item(node);
VERIFY(*found_item,sort_rand_num[u],"H5SL_prev");
u--;
node=H5SL_prev(node);
} /* end while */
/* Release all the items from the list */
ret=H5SL_release(slist);
CHECK(ret, FAIL, "H5SL_release");
/* Check that the list appears empty again */
node=H5SL_last(slist);
CHECK_PTR_NULL(node, "H5SL_last");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_lastprev() */
/****************************************************************
**
** test_skiplist_find(): Test H5SL (skip list) code.
** Tests 'find' operation in skip lists.
**
****************************************************************/
static void
test_skiplist_find(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 find in skip list */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(7, ("Testing Skip List 'Find' Operation\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL);
CHECK_PTR(slist, "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 */
/* Find the element with key==30 in the skip list */
find_item=30;
node=H5SL_find(slist,&find_item);
CHECK_PTR(node, "H5SL_find");
/* Iterate over the rest of the nodes in the skip list */
u=4;
while(node!=NULL) {
found_item=(unsigned *)H5SL_item(node);
VERIFY(*found_item,sorted_data[u],"H5SL_next");
u++;
node=H5SL_next(node);
} /* end while */
/* Check for trying to locate non-existent item */
find_item=81;
node=H5SL_find(slist,&find_item);
CHECK_PTR_NULL(node, "H5SL_find");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_find() */
/****************************************************************
**
** test_skiplist_add(): Test H5SL (skip list) code.
** Tests 'add' operation in skip lists.
**
****************************************************************/
static void
test_skiplist_add(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 new_item; /* Item to add to skip list */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(7, ("Testing Skip List 'Add' Operation\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_UNSIGNED, NULL);
CHECK_PTR(slist, "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 */
/* Add the element with key==12 in the skip list */
new_item=12;
node=H5SL_add(slist,&new_item,&new_item);
CHECK_PTR(node, "H5SL_add");
/* Advance to next node in list */
node=H5SL_next(node);
CHECK_PTR(node, "H5SL_next");
/* Iterate over the rest of the nodes in the skip list */
u=2;
while(node!=NULL) {
found_item=(unsigned *)H5SL_item(node);
VERIFY(*found_item,sorted_data[u],"H5SL_item");
u++;
node=H5SL_next(node);
} /* end while */
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_add() */
static herr_t
test_skiplist_destroy_free(void *item, void H5_ATTR_UNUSED *key, void *op_data)
{
unsigned *free_count=(unsigned *)op_data;
VERIFY(*(int *)item,sort_rand_num[*free_count],"H5SL_destroy");
(*free_count)++;
return(0);
}
/****************************************************************
**
** test_skiplist_destroy(): Test H5SL (skip list) code.
** Tests 'destroy' operation in skip lists.
**
****************************************************************/
static void
test_skiplist_destroy(void)
{
H5SL_t *slist; /* Skip list created */
size_t u; /* Local index variable */
unsigned free_count; /* Number of items freed */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(7, ("Testing Skip List 'Destroy' Operation\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_INT, NULL);
CHECK_PTR(slist, "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 */
/* Destroy the skip list */
free_count=0;
ret=H5SL_destroy(slist,test_skiplist_destroy_free,&free_count);
CHECK(ret, FAIL, "H5SL_destroy");
VERIFY(free_count, NUM_ELEMS, "H5SL_destroy");
} /* end test_skiplist_destroy() */
/****************************************************************
**
** test_skiplist_free(): Test H5SL (skip list) code.
** Tests 'free' operation in skip lists.
**
****************************************************************/
static void
test_skiplist_free(void)
{
H5SL_t *slist; /* Skip list created */
size_t num; /* Number of elements in skip list */
size_t u; /* Local index variable */
unsigned free_count; /* Number of items freed */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(7, ("Testing Skip List 'Free' Operation\n"));
/* Create a skip list */
slist = H5SL_create(H5SL_TYPE_INT, NULL);
CHECK_PTR(slist, "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 */
/* Destroy the skip list */
free_count=0;
ret=H5SL_free(slist,test_skiplist_destroy_free,&free_count);
CHECK(ret, FAIL, "H5SL_destroy");
VERIFY(free_count, NUM_ELEMS, "H5SL_free");
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, 0, "H5SL_count");
/* Insert objects into the skip list again */
for(u=0; u<NUM_ELEMS; u++) {
ret=H5SL_insert(slist,&rand_num[u],&rand_num[u]);
CHECK(ret, FAIL, "H5SL_insert");
} /* end for */
/* Check that the skip list has correct # of elements */
num=H5SL_count(slist);
VERIFY(num, NUM_ELEMS, "H5SL_count");
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");
} /* end test_skiplist_free() */
/****************************************************************
**
** test_skiplist_try_free_safe(): Test H5SL (skip list) code.
** Tests 'try_free_safe' operation in skip lists.
**
****************************************************************/
/* Macro definitions */
#define TEST_TFS_MAX_NOBJS 100
#define TEST_TFS_MIN_NOBJS 5
#define TEST_TFS_NITER 50
/* Structure to hold the list of objects */
typedef struct {
H5SL_t *slist; /* Skiplist holding the objects */
struct test_tfs_obj_t *list; /* Linear list of objects */
int nobjs; /* Number of objects in list */
int nobjs_rem; /* Number of objects in list that have not been freed */
} test_tfs_list_t;
/* Structure for an object */
typedef struct test_tfs_obj_t {
int idx; /* Index (key) for this object */
int nfrees; /* Number of times this object has been freed */
} test_tfs_obj_t;
/* op_data struct for H5SL_iterate() */
typedef struct test_tfs_it_ud_t {
test_tfs_list_t *obj_list; /* List of objects */
int last_idx; /* Index of last object visited in iteration */
int ncalls; /* Number of times this callback was called */
} test_tfs_it_ud_t;
/* iterate callback */
static herr_t test_tfs_iter(void *_obj, void *key, void *_udata) {
test_tfs_obj_t *obj = (test_tfs_obj_t *)_obj;
test_tfs_it_ud_t *udata = (test_tfs_it_ud_t *)_udata;
/* Check consistency */
CHECK_PTR_EQ((void *)&obj->idx, key, "obj->idx");
CHECK_PTR_EQ(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 */
CHECK_PTR_EQ((void *)&obj->idx, key, "obj->idx");
CHECK_PTR_EQ(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_PTR(obj_ret, "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_PTR(obj_list.slist, "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_PTR(slist, "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);
CHECK_PTR_NULL(found_item, "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_PTR(slist, "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);
CHECK_PTR_NULL(found_item, "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_PTR(slist, "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_PTR(node, "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_PTR(node, "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_PTR(node, "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_PTR(node, "H5SL_below");
found_item = (unsigned *)H5SL_item(node);
VERIFY(*found_item, 15, "H5SL_below");
find_item = 89;
node = H5SL_below(slist, &find_item);
CHECK_PTR(node, "H5SL_below");
found_item = (unsigned *)H5SL_item(node);
VERIFY(*found_item, 80, "H5SL_below");
find_item = 100;
node = H5SL_below(slist, &find_item);
CHECK_PTR(node, "H5SL_below");
found_item = (unsigned *)H5SL_item(node);
VERIFY(*found_item, 90, "H5SL_below");
find_item = 9;
node = H5SL_below(slist, &find_item);
CHECK_PTR(node, "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);
CHECK_PTR_NULL(node, "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_PTR(slist, "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_PTR(node, "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_PTR(node, "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_PTR(node, "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_PTR(node, "H5SL_above");
found_item = (unsigned *)H5SL_item(node);
VERIFY(*found_item, 20, "H5SL_above");
find_item = 89;
node = H5SL_above(slist, &find_item);
CHECK_PTR(node, "H5SL_above");
found_item = (unsigned *)H5SL_item(node);
VERIFY(*found_item, 90, "H5SL_above");
find_item = 100;
node = H5SL_above(slist, &find_item);
CHECK_PTR_NULL(node, "H5SL_above");
find_item = 6;
node = H5SL_above(slist, &find_item);
CHECK_PTR(node, "H5SL_above");
found_item = (unsigned *)H5SL_item(node);
VERIFY(*found_item, 10, "H5SL_above");
find_item = 4;
node = H5SL_above(slist, &find_item);
CHECK_PTR(node, "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_PTR(slist, "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);
CHECK_PTR_NULL(found_item, "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_PTR(slist, "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);
CHECK_PTR_NULL(found_item, "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() */
|