summaryrefslogtreecommitdiffstats
path: root/src/H5SL.c
blob: a9c231d0efddb690ca6ab70a523eabb2185279f8 (plain)
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
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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://www.hdfgroup.org/licenses.               *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Purpose:	Provides a skip list abstract data type.
 *
 *              (See "Deterministic Skip Lists" by Munro, Papadakis & Sedgewick)
 *
 *              (Implementation changed to a deterministic skip list from a
 *               probabilistic one.  This implementation uses a 1-2-3 skip list
 *               using arrays, as described by Munro, Papadakis & Sedgewick.
 *
 *               Arrays are allocated using a free list factory for each size
 *               that is a power of two.  Factories are created as soon as they
 *               are needed, and are never destroyed until the package is shut
 *               down.  There is no longer a maximum level or "p" value.
 *               -NAF 2008/11/05)
 *
 *              (See "Skip Lists: A Probabilistic Alternative to Balanced Trees"
 *               by William Pugh for additional information)
 *
 *              (This implementation has the optimization for reducing key
 *               key comparisons mentioned in section 3.5 of "A Skip List
 *               Cookbook" by William Pugh
 *              -Removed as our implementation of this was useless for a 1-2-3
 *               skip list.  The implementation in that document hurts
 *               performance, at least for integer keys. -NAF)
 *
 *              (Note: This implementation does not have the information for
 *               implementing the "Linear List Operations" (like insert/delete/
 *               search by position) in section 3.4 of "A Skip List Cookbook",
 *               but they shouldn't be that hard to add, if necessary)
 *
 *              (This implementation has an additional backward pointer, which
 *               allows the list to be iterated in reverse)
 *
 *              (There's also an article on "Alternating Skip Lists", which
 *              are similar to deterministic skip lists, in the August 2000
 *              issue of Dr. Dobb's Journal)
 *
 */

#include "H5SLmodule.h" /* This source code file is part of the H5SL module */

/* Private headers needed */
#include "H5private.h"   /* Generic Functions			*/
#include "H5Eprivate.h"  /* Error handling		  	*/
#include "H5FLprivate.h" /* Free Lists                           */
#include "H5MMprivate.h" /* Memory management                    */
#include "H5SLprivate.h" /* Skip list routines			*/

/* Local Macros */

/* Define the code template for searches for the "OP" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_SEARCH_FOUND(SLIST, X, I)                                                                \
    {                                                                                                        \
        HGOTO_DONE(X->item);                                                                                 \
    }

/* Define the code template for finds for the "OP" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_FIND_FOUND(SLIST, X, I)                                                                  \
    {                                                                                                        \
        HGOTO_DONE(X);                                                                                       \
    }

/* Define a code template for comparing scalar keys for the "CMP" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_SCALAR_CMP(SLIST, TYPE, PNODE, PKEY, HASHVAL) (*(TYPE *)((PNODE)->key) < *(TYPE *)PKEY)

/* Define a code template for comparing string keys for the "CMP" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_STRING_CMP(SLIST, TYPE, PNODE, PKEY, HASHVAL)                                            \
    (((PNODE)->hashval == HASHVAL) ? (HDstrcmp((const char *)(PNODE)->key, (const char *)PKEY) < 0)          \
                                   : ((PNODE)->hashval < HASHVAL))

/* Define a code template for comparing H5_obj_t keys for the "CMP" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_OBJ_CMP(SLIST, TYPE, PNODE, PKEY, HASHVAL)                                               \
    ((((TYPE *)((PNODE)->key))->fileno == ((TYPE *)PKEY)->fileno)                                            \
         ? (((TYPE *)((PNODE)->key))->addr < ((TYPE *)PKEY)->addr)                                           \
         : (((TYPE *)((PNODE)->key))->fileno < ((TYPE *)PKEY)->fileno))

/* Define a code template for comparing generic keys for the "CMP" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_GENERIC_CMP(SLIST, TYPE, PNODE, PKEY, HASHVAL)                                           \
    ((SLIST)->cmp((TYPE *)((PNODE)->key), (TYPE *)PKEY) < 0)

/* Define a code template for comparing scalar keys for the "EQ" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_SCALAR_EQ(SLIST, TYPE, PNODE, PKEY, HASHVAL) (*(TYPE *)((PNODE)->key) == *(TYPE *)PKEY)

/* Define a code template for comparing string keys for the "EQ" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_STRING_EQ(SLIST, TYPE, PNODE, PKEY, HASHVAL)                                             \
    (((PNODE)->hashval == HASHVAL) && (HDstrcmp((const char *)(PNODE)->key, (const char *)PKEY) == 0))

/* Define a code template for comparing H5_obj_t keys for the "EQ" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_OBJ_EQ(SLIST, TYPE, PNODE, PKEY, HASHVAL)                                                \
    ((((TYPE *)((PNODE)->key))->fileno == ((TYPE *)PKEY)->fileno) &&                                         \
     (((TYPE *)((PNODE)->key))->addr == ((TYPE *)PKEY)->addr))

/* Define a code template for comparing generic keys for the "EQ" in the H5SL_LOCATE macro */
#define H5SL_LOCATE_GENERIC_EQ(SLIST, TYPE, PNODE, PKEY, HASHVAL)                                            \
    ((SLIST)->cmp((TYPE *)((PNODE)->key), (TYPE *)PKEY) == 0)

/* Define a code template for initializing the hash value for scalar keys for the "HASHINIT" in the
 * H5SL_LOCATE macro */
#define H5SL_LOCATE_SCALAR_HASHINIT(KEY, HASHVAL)

/* Define a code template for initializing the hash value for string keys for the "HASHINIT" in the
 * H5SL_LOCATE macro */
#define H5SL_LOCATE_STRING_HASHINIT(KEY, HASHVAL) HASHVAL = H5_hash_string((const char *)KEY);

/* Define a code template for initializing the hash value for H5_obj_t keys for the "HASHINIT" in the
 * H5SL_LOCATE macro */
#define H5SL_LOCATE_OBJ_HASHINIT(KEY, HASHVAL)

/* Define a code template for initializing the hash value for generic keys for the "HASHINIT" in the
 * H5SL_LOCATE macro */
#define H5SL_LOCATE_GENERIC_HASHINIT(KEY, HASHVAL)

/* Macro used to find node for operation, if all keys are valid */
#define H5SL_LOCATE_OPT(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL)                                               \
    {                                                                                                        \
        int      _i;     /* Local index variable */                                                          \
        unsigned _count; /* Num nodes searched at this height */                                             \
                                                                                                             \
        H5_GLUE3(H5SL_LOCATE_, CMP, _HASHINIT)                                                               \
        (KEY, HASHVAL) for (_i = (int)SLIST->curr_level; _i >= 0; _i--)                                      \
        {                                                                                                    \
            _count = 0;                                                                                      \
            while (_count < 3 && X->forward[_i] &&                                                           \
                   H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, X->forward[_i], KEY, HASHVAL)) {           \
                X = X->forward[_i];                                                                          \
                _count++;                                                                                    \
            }                                                                                                \
        }                                                                                                    \
        X = X->forward[0];                                                                                   \
        if (X != NULL && H5_GLUE3(H5SL_LOCATE_, CMP, _EQ)(SLIST, TYPE, X, KEY, HASHVAL)) {                   \
            /* What to do when a node is found */                                                            \
            H5_GLUE3(H5SL_LOCATE_, OP, _FOUND)(SLIST, X, _i)                                                 \
        }                                                                                                    \
    }

/* Macro used to find node for operation */
#define H5SL_LOCATE(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL)                                                   \
    {                                                                                                        \
        H5SL_LOCATE_OPT(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL)                                               \
    }

/* Macro used to grow a node by 1.  Does not update pointers. LVL is the current
 * level of X.  Does not update LVL but does update X->lvl. */
#define H5SL_GROW(X, LVL, ERR)                                                                               \
    {                                                                                                        \
        /* Check if we need to increase allocation of forward pointers */                                    \
        if (LVL + 1 >= 1u << X->log_nalloc) {                                                                \
            H5SL_node_t **_tmp;                                                                              \
            HDassert(LVL + 1 == 1U << X->log_nalloc);                                                        \
            /* Double the amount of allocated space */                                                       \
            X->log_nalloc++;                                                                                 \
                                                                                                             \
            /* Check if we need to create a new factory */                                                   \
            if (X->log_nalloc >= H5SL_fac_nused_g) {                                                         \
                HDassert(X->log_nalloc == H5SL_fac_nused_g);                                                 \
                                                                                                             \
                /* Check if we need to allocate space for the factory pointer*/                              \
                if (H5SL_fac_nused_g >= H5SL_fac_nalloc_g) {                                                 \
                    HDassert(H5SL_fac_nused_g == H5SL_fac_nalloc_g);                                         \
                    /* Double the size of the array of factory pointers */                                   \
                    H5SL_fac_nalloc_g *= 2;                                                                  \
                    if (NULL == (H5SL_fac_g = (H5FL_fac_head_t **)H5MM_realloc(                              \
                                     (void *)H5SL_fac_g, H5SL_fac_nalloc_g * sizeof(H5FL_fac_head_t *))))    \
                        HGOTO_ERROR(H5E_SLIST, H5E_CANTALLOC, ERR, "memory allocation failed")               \
                }                                                                                            \
                                                                                                             \
                /* Create the new factory */                                                                 \
                H5SL_fac_g[H5SL_fac_nused_g] =                                                               \
                    H5FL_fac_init((1u << H5SL_fac_nused_g) * sizeof(H5SL_node_t *));                         \
                H5SL_fac_nused_g++;                                                                          \
            }                                                                                                \
                                                                                                             \
            /* Allocate space for new forward pointers */                                                    \
            if (NULL == (_tmp = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[X->log_nalloc])))                 \
                HGOTO_ERROR(H5E_SLIST, H5E_CANTALLOC, ERR, "memory allocation failed")                       \
            H5MM_memcpy((void *)_tmp, (const void *)X->forward, (LVL + 1) * sizeof(H5SL_node_t *));          \
            X->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[X->log_nalloc - 1], (void *)X->forward);   \
            X->forward = _tmp;                                                                               \
        }                                                                                                    \
                                                                                                             \
        X->level++;                                                                                          \
    }

/* Macro used to shrink a node by 1.  Does not update pointers.  LVL is the
 * current level of X.  Does not update LVL but does update X->level. */
#define H5SL_SHRINK(X, LVL)                                                                                  \
    {                                                                                                        \
        /* Check if we can reduce the allocation of forward pointers */                                      \
        if (LVL <= 1u << (X->log_nalloc - 1)) {                                                              \
            H5SL_node_t **_tmp;                                                                              \
            HDassert(LVL == 1U << (X->log_nalloc - 1));                                                      \
            X->log_nalloc--;                                                                                 \
                                                                                                             \
            /* Allocate space for new forward pointers */                                                    \
            if (NULL == (_tmp = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[X->log_nalloc])))                 \
                HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed")                        \
            H5MM_memcpy((void *)_tmp, (const void *)X->forward, (LVL) * sizeof(H5SL_node_t *));              \
            X->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[X->log_nalloc + 1], (void *)X->forward);   \
            X->forward = _tmp;                                                                               \
        }                                                                                                    \
                                                                                                             \
        X->level--;                                                                                          \
    }

/* Macro used to grow the level of a node by 1, with appropriate changes to the
 * head node if necessary.  PREV is the previous node of the height that X is to
 * grow to. */
#define H5SL_PROMOTE(SLIST, X, PREV, ERR)                                                                    \
    {                                                                                                        \
        size_t _lvl = X->level;                                                                              \
                                                                                                             \
        H5SL_GROW(X, _lvl, ERR);                                                                             \
                                                                                                             \
        if (_lvl == (size_t)SLIST->curr_level) {                                                             \
            HDassert(PREV == SLIST->header);                                                                 \
            /* Grow the head */                                                                              \
            H5SL_GROW(PREV, _lvl, ERR)                                                                       \
            SLIST->curr_level++;                                                                             \
            X->forward[_lvl + 1] = NULL;                                                                     \
        }                                                                                                    \
        else {                                                                                               \
            HDassert(_lvl < (size_t)SLIST->curr_level);                                                      \
            X->forward[_lvl + 1] = PREV->forward[_lvl + 1];                                                  \
        }                                                                                                    \
        PREV->forward[_lvl + 1] = X;                                                                         \
    }

/* Macro used to reduce the level of a node by 1.  Does not update the head node
 * "current level".  PREV is the previous node of the current height of X. */
#define H5SL_DEMOTE(X, PREV)                                                                                 \
    {                                                                                                        \
        size_t _lvl = X->level;                                                                              \
                                                                                                             \
        HDassert(PREV->forward[_lvl] == X);                                                                  \
        PREV->forward[_lvl] = X->forward[_lvl];                                                              \
        H5SL_SHRINK(X, _lvl);                                                                                \
    }

/* Macro used to insert node.  Does not actually insert the node.  After running
 * this macro, X will contain the node before where the new node should be
 * inserted (at level 0). */
#define H5SL_INSERT(CMP, SLIST, X, TYPE, KEY, HASHVAL)                                                       \
    {                                                                                                        \
        H5SL_node_t *_last = X;    /* Lowest node in the current gap */                                      \
        H5SL_node_t *_next = NULL; /* Highest node in the current gap */                                     \
        H5SL_node_t *_drop;        /* Low node of the gap to drop into */                                    \
        int          _count;       /* Number of nodes in the current gap */                                  \
        int          _i;                                                                                     \
                                                                                                             \
        H5_GLUE3(H5SL_LOCATE_, CMP, _HASHINIT)                                                               \
        (KEY, HASHVAL) for (_i = (int)SLIST->curr_level; _i >= 0; _i--)                                      \
        {                                                                                                    \
            /* Search for the node to drop into, also count the number of nodes */                           \
            /* of height _i in this gap */                                                                   \
            _drop = NULL;                                                                                    \
            for (_count = 0;; _count++) {                                                                    \
                /* Terminate if this is the last node in the gap */                                          \
                if (X->forward[_i] == _next) {                                                               \
                    if (!_drop)                                                                              \
                        _drop = X;                                                                           \
                    break;                                                                                   \
                }                                                                                            \
                                                                                                             \
                /* Check if this node is the start of the next gap */                                        \
                if (!_drop && !H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, X->forward[_i], KEY, HASHVAL)) \
                    _drop = X;                                                                               \
                                                                                                             \
                /* No need to check the last node in the gap if there are 3, as */                           \
                /* there cannot be a fourth */                                                               \
                if (_count == 2) {                                                                           \
                    if (!_drop)                                                                              \
                        _drop = X->forward[_i];                                                              \
                    _count = 3;                                                                              \
                    break;                                                                                   \
                }                                                                                            \
                X = X->forward[_i];                                                                          \
            }                                                                                                \
            HDassert(!_drop->forward[_i] ||                                                                  \
                     !H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, _drop->forward[_i], KEY, HASHVAL));     \
                                                                                                             \
            /* Promote the middle node if necessary */                                                       \
            if (_count == 3) {                                                                               \
                HDassert(X == _last->forward[_i]->forward[_i]);                                              \
                H5SL_PROMOTE(SLIST, X, _last, NULL)                                                          \
            }                                                                                                \
                                                                                                             \
            /* Prepare to drop down */                                                                       \
            X = _last = _drop;                                                                               \
            _next     = _drop->forward[_i];                                                                  \
        }                                                                                                    \
                                                                                                             \
        if (_next && H5_GLUE3(H5SL_LOCATE_, CMP, _EQ)(SLIST, TYPE, _next, KEY, HASHVAL))                     \
            HGOTO_ERROR(H5E_SLIST, H5E_CANTINSERT, NULL, "can't insert duplicate key")                       \
    }

/* Macro used to remove node */
#define H5SL_REMOVE(CMP, SLIST, X, TYPE, KEY, HASHVAL)                                                       \
    {                                                                                                        \
        H5SL_node_t *_last  = X;             /* Lowest node in the current gap */                            \
        H5SL_node_t *_llast = X;             /* Lowest node in the previous gap */                           \
        H5SL_node_t *_next  = NULL;          /* Highest node in the current gap */                           \
        H5SL_node_t *_drop  = NULL;          /* Low node of the gap to drop into */                          \
        H5SL_node_t *_ldrop = NULL;          /* Low node of gap before the one to drop into */               \
        H5SL_node_t *_head  = SLIST->header; /* Head of the skip list */                                     \
        int          _count;                 /* Number of nodes in the current gap */                        \
        int          _i = (int)SLIST->curr_level;                                                            \
                                                                                                             \
        if (_i < 0)                                                                                          \
            HGOTO_DONE(NULL);                                                                                \
                                                                                                             \
        H5_GLUE3(H5SL_LOCATE_, CMP, _HASHINIT)                                                               \
        (KEY, HASHVAL)                                                                                       \
                                                                                                             \
            /* Find the gap to drop in to at the highest level */                                            \
            while (X && (!X->key || H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, X, KEY, HASHVAL)))        \
        {                                                                                                    \
            _llast = _last;                                                                                  \
            _last  = X;                                                                                      \
            X      = X->forward[_i];                                                                         \
        }                                                                                                    \
        _next = X;                                                                                           \
                                                                                                             \
        /* Main loop */                                                                                      \
        for (_i--; _i >= 0; _i--) {                                                                          \
            /* Search for the node to drop into, also count the number of */                                 \
            /* nodes of height _i in this gap and keep track of of the node */                               \
            /* before the one to drop into (_ldrop will become _llast, */                                    \
            /* _drop will become _last). */                                                                  \
            X = _ldrop = _last;                                                                              \
            _drop      = NULL;                                                                               \
            for (_count = 0;; _count++) {                                                                    \
                /* Terminate if this is the last node in the gap */                                          \
                if (X->forward[_i] == _next) {                                                               \
                    if (!_drop)                                                                              \
                        _drop = X;                                                                           \
                    break;                                                                                   \
                }                                                                                            \
                                                                                                             \
                /* If we have already found the node to drop into and there */                               \
                /* is more than one node in this gap, we can stop searching */                               \
                if (_drop) {                                                                                 \
                    HDassert(_count >= 1);                                                                   \
                    _count = 2;                                                                              \
                    break;                                                                                   \
                }                                                                                            \
                else { /* !_drop */                                                                          \
                    /* Check if this node is the start of the next gap */                                    \
                    if (!H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, X->forward[_i], KEY, HASHVAL)) {     \
                        _drop = X;                                                                           \
                        /* Again check if we can stop searching */                                           \
                        if (_count) {                                                                        \
                            _count = 2;                                                                      \
                            break;                                                                           \
                        }                                                                                    \
                    }                                                                                        \
                    else                                                                                     \
                        _ldrop = X;                                                                          \
                }                                                                                            \
                                                                                                             \
                /* No need to check the last node in the gap if there are */                                 \
                /* 3, as there cannot be a fourth */                                                         \
                if (_count == 2) {                                                                           \
                    if (!_drop)                                                                              \
                        _drop = X->forward[_i];                                                              \
                    break;                                                                                   \
                }                                                                                            \
                X = X->forward[_i];                                                                          \
            }                                                                                                \
            HDassert(_count >= 1 && _count <= 3);                                                            \
            HDassert(!_drop->forward[_i] ||                                                                  \
                     !H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, _drop->forward[_i], KEY, HASHVAL));     \
                                                                                                             \
            /* Check if we need to adjust node heights */                                                    \
            if (_count == 1) {                                                                               \
                /* Check if we are in the first gap */                                                       \
                if (_llast == _last) {                                                                       \
                    /* We are in the first gap, count the number of nodes */                                 \
                    /* of height _i in the next gap.  We need only check */                                  \
                    /* onenode to see if we should promote the first node */                                 \
                    /* in the next gap */                                                                    \
                    _llast = _next->forward[_i + 1];                                                         \
                                                                                                             \
                    /* Demote the separator node */                                                          \
                    H5SL_DEMOTE(_next, _last)                                                                \
                                                                                                             \
                    /* If there are 2 or more nodes, promote the first */                                    \
                    if (_next->forward[_i]->forward[_i] != _llast) {                                         \
                        X = _next->forward[_i];                                                              \
                        H5SL_PROMOTE(SLIST, X, _last, NULL)                                                  \
                    }                                                                                        \
                    else if (!_head->forward[_i + 1]) {                                                      \
                        /* shrink the header */                                                              \
                        HDassert(_i == SLIST->curr_level - 1);                                               \
                        HDassert((size_t)SLIST->curr_level == _head->level);                                 \
                                                                                                             \
                        H5SL_SHRINK(_head, (size_t)(_i + 1))                                                 \
                        SLIST->curr_level--;                                                                 \
                    }                                                                                        \
                }                                                                                            \
                else {                                                                                       \
                    /* We are not in the first gap, count the number of */                                   \
                    /* nodes of height _i in the previous gap.  Note we */                                   \
                    /* "look ahead" in this loop so X has the value of the */                                \
                    /* last node in the previous gap. */                                                     \
                    X = _llast->forward[_i];                                                                 \
                    for (_count = 1; _count < 3 && X->forward[_i] != _last; _count++)                        \
                        X = X->forward[_i];                                                                  \
                    HDassert(X->forward[_i] == _last);                                                       \
                                                                                                             \
                    /* Demote the separator node */                                                          \
                    H5SL_DEMOTE(_last, _llast)                                                               \
                                                                                                             \
                    /* If there are 2 or more nodes, promote the last */                                     \
                    if (_count >= 2)                                                                         \
                        H5SL_PROMOTE(SLIST, X, _llast, NULL)                                                 \
                    else if (!_head->forward[_i + 1]) {                                                      \
                        /* shrink the header */                                                              \
                        HDassert(_i == SLIST->curr_level - 1);                                               \
                        HDassert((size_t)SLIST->curr_level == _head->level);                                 \
                                                                                                             \
                        H5SL_SHRINK(_head, (size_t)(_i + 1))                                                 \
                        SLIST->curr_level--;                                                                 \
                    }                                                                                        \
                }                                                                                            \
            }                                                                                                \
                                                                                                             \
            /* Prepare to drop down */                                                                       \
            _llast = _ldrop;                                                                                 \
            _last  = _drop;                                                                                  \
            _next  = _drop->forward[_i];                                                                     \
        }                                                                                                    \
                                                                                                             \
        /* Check if we've found the node */                                                                  \
        if (_next && H5_GLUE3(H5SL_LOCATE_, CMP, _EQ)(SLIST, TYPE, _next, KEY, HASHVAL)) {                   \
            void *tmp = _next->item;                                                                         \
            X         = _next;                                                                               \
                                                                                                             \
            /* If the node has a height > 0, swap it with its (lower) */                                     \
            /* neighbor */                                                                                   \
            if (X->level) {                                                                                  \
                X              = X->backward;                                                                \
                _next->key     = X->key;                                                                     \
                _next->item    = X->item;                                                                    \
                _next->hashval = X->hashval;                                                                 \
            }                                                                                                \
            HDassert(!X->level);                                                                             \
                                                                                                             \
            /* Remove the node */                                                                            \
            X->backward->forward[0] = X->forward[0];                                                         \
            if (SLIST->last == X)                                                                            \
                SLIST->last = X->backward;                                                                   \
            else                                                                                             \
                X->forward[0]->backward = X->backward;                                                       \
            SLIST->nobjs--;                                                                                  \
            X->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[0], X->forward);                           \
            X          = H5FL_FREE(H5SL_node_t, X);                                                          \
                                                                                                             \
            HGOTO_DONE(tmp);                                                                                 \
        }                                                                                                    \
    }

/* Macro used to search for node */
#define H5SL_SEARCH(CMP, SLIST, X, TYPE, KEY, HASHVAL) H5SL_LOCATE(SEARCH, CMP, SLIST, X, TYPE, KEY, HASHVAL)

/* Macro used to find a node */
#define H5SL_FIND(CMP, SLIST, X, TYPE, KEY, HASHVAL) H5SL_LOCATE(FIND, CMP, SLIST, X, TYPE, KEY, HASHVAL)

/* Private typedefs & structs */

/* Skip list node data structure */
struct H5SL_node_t {
    const void          *key;        /* Pointer to node's key */
    void                *item;       /* Pointer to node's item */
    size_t               level;      /* The level of this node */
    size_t               log_nalloc; /* log2(Number of slots allocated in forward) */
    uint32_t             hashval;    /* Hash value for key (only for strings, currently) */
    struct H5SL_node_t **forward;    /* Array of forward pointers from this node */
    struct H5SL_node_t  *backward;   /* Backward pointer from this node */
};

/* Main skip list data structure */
struct H5SL_t {
    /* Static values for each list */
    H5SL_type_t type; /* Type of skip list */
    H5SL_cmp_t  cmp;  /* Comparison callback, if type is H5SL_TYPE_GENERIC */

    /* Dynamic values for each list */
    int          curr_level; /* Current top level used in list */
    size_t       nobjs;      /* Number of active objects in skip list */
    H5SL_node_t *header;     /* Header for nodes in skip list */
    H5SL_node_t *last;       /* Pointer to last node in skip list */
};

/* Static functions */
static H5SL_node_t *H5SL__new_node(void *item, const void *key, uint32_t hashval);
static H5SL_node_t *H5SL__insert_common(H5SL_t *slist, void *item, const void *key);
static herr_t       H5SL__release_common(H5SL_t *slist, H5SL_operator_t op, void *op_data);
static herr_t       H5SL__close_common(H5SL_t *slist, H5SL_operator_t op, void *op_data);

/* Package initialization variable */
hbool_t H5_PKG_INIT_VAR = FALSE;

/* Declare a free list to manage the H5SL_t struct */
H5FL_DEFINE_STATIC(H5SL_t);

/* Declare a free list to manage the H5SL_node_t struct */
H5FL_DEFINE_STATIC(H5SL_node_t);

/* Global variables */
static H5FL_fac_head_t **H5SL_fac_g;
static size_t            H5SL_fac_nused_g;
static size_t            H5SL_fac_nalloc_g;

/*--------------------------------------------------------------------------
 NAME
    H5SL__init_package
 PURPOSE
    Initialize interface-specific information
 USAGE
    herr_t H5SL__init_package()
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Initializes any interface-specific data or routines.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5SL__init_package(void)
{
    FUNC_ENTER_PACKAGE_NOERR

    /* Allocate space for array of factories */
    H5SL_fac_g = (H5FL_fac_head_t **)H5MM_malloc(sizeof(H5FL_fac_head_t *));
    HDassert(H5SL_fac_g);
    H5SL_fac_nalloc_g = 1;

    /* Initialize first factory */
    H5SL_fac_g[0] = H5FL_fac_init(sizeof(H5SL_node_t *));
    HDassert(H5SL_fac_g[0]);
    H5SL_fac_nused_g = 1;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5SL__init_package() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_term_package
 PURPOSE
    Terminate all the H5FL factories used in this package, and clear memory
 USAGE
    int H5SL_term_package()
 RETURNS
    Success:	Positive if any action might have caused a change in some
                other interface; zero otherwise.
        Failure:	Negative
 DESCRIPTION
    Release any resources allocated.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
     Can't report errors...
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
int
H5SL_term_package(void)
{
    int n = 0;

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    if (H5_PKG_INIT_VAR) {
        /* Terminate all the factories */
        if (H5SL_fac_nused_g > 0) {
            size_t                       i;
            herr_t H5_ATTR_NDEBUG_UNUSED ret;

            for (i = 0; i < H5SL_fac_nused_g; i++) {
                ret = H5FL_fac_term(H5SL_fac_g[i]);
                HDassert(ret >= 0);
            }
            H5SL_fac_nused_g = 0;

            n++;
        }

        /* Free the list of factories */
        if (H5SL_fac_g) {
            H5SL_fac_g        = (H5FL_fac_head_t **)H5MM_xfree((void *)H5SL_fac_g);
            H5SL_fac_nalloc_g = 0;

            n++;
        }

        /* Mark the interface as uninitialized */
        if (0 == n)
            H5_PKG_INIT_VAR = FALSE;
    }

    FUNC_LEAVE_NOAPI(n)
} /* H5SL_term_package() */

/*--------------------------------------------------------------------------
 NAME
    H5SL__new_node
 PURPOSE
    Create a new skip list node of level 0
 USAGE
    H5SL_node_t *H5SL__new_node(item,key,hasval)
        void *item;             IN: Pointer to item info for node
        void *key;              IN: Pointer to key info for node
        uint32_t hashval;       IN: Hash value for node

 RETURNS
    Returns a pointer to a skip list node on success, NULL on failure.
 DESCRIPTION
    Create a new skip list node of the height 0, setting the item
    and key values internally.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    This routine does _not_ initialize the 'forward' pointers
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static H5SL_node_t *
H5SL__new_node(void *item, const void *key, uint32_t hashval)
{
    H5SL_node_t *ret_value = NULL; /* New skip list node */

    FUNC_ENTER_STATIC

    /* Allocate the node */
    if (NULL == (ret_value = (H5SL_node_t *)H5FL_MALLOC(H5SL_node_t)))
        HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed")

    /* Initialize node */
    ret_value->key     = key;
    ret_value->item    = item;
    ret_value->level   = 0;
    ret_value->hashval = hashval;
    if (NULL == (ret_value->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0]))) {
        ret_value = H5FL_FREE(H5SL_node_t, ret_value);
        HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed")
    }
    ret_value->log_nalloc = 0;

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__new_node() */

/*--------------------------------------------------------------------------
 NAME
    H5SL__insert_common
 PURPOSE
    Common code for inserting an object into a skip list
 USAGE
    H5SL_node_t *H5SL__insert_common(slist,item,key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *item;             IN: Item to insert
        void *key;              IN: Key for item to insert

 RETURNS
    Returns pointer to new node on success, NULL on failure.
 DESCRIPTION
    Common code for inserting an element into a skip list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    Inserting an item with the same key as an existing object fails.
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static H5SL_node_t *
H5SL__insert_common(H5SL_t *slist, void *item, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    H5SL_node_t *prev;             /* Node before the new node */
    uint32_t     hashval   = 0;    /* Hash value for key */
    H5SL_node_t *ret_value = NULL; /* Return value */

    FUNC_ENTER_STATIC

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to insert
     */
    prev = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_INSERT(SCALAR, slist, prev, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_INSERT(SCALAR, slist, prev, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_INSERT(STRING, slist, prev, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_INSERT(SCALAR, slist, prev, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_INSERT(SCALAR, slist, prev, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_INSERT(SCALAR, slist, prev, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_INSERT(OBJ, slist, prev, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_INSERT(SCALAR, slist, prev, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_INSERT(GENERIC, slist, prev, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

    /* 'key' must not have been found in existing list, if we get here */

    if (slist->curr_level < 0)
        slist->curr_level = 0;

    /* Create new node of level 0 */
    if (NULL == (x = H5SL__new_node(item, key, hashval)))
        HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "can't create new skip list node")

    /* Update the links */
    x->backward      = prev;
    x->forward[0]    = prev->forward[0];
    prev->forward[0] = x;
    if (x->forward[0])
        x->forward[0]->backward = x;
    else {
        HDassert(slist->last == prev);
        slist->last = x;
    }

    /* Increment the number of nodes in the skip list */
    slist->nobjs++;

    /* Set return value */
    ret_value = x;

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__insert_common() */

/*--------------------------------------------------------------------------
 NAME
    H5SL__release_common
 PURPOSE
    Release all nodes from a skip list, optionally calling a 'free' operator
 USAGE
    herr_t H5SL__release_common(slist,op,opdata)
        H5SL_t *slist;            IN/OUT: Pointer to skip list to release nodes
        H5SL_operator_t op;     IN: Callback function to free item & key
        void *op_data;          IN/OUT: Pointer to application data for callback

 RETURNS
    Returns non-negative on success, negative on failure.
 DESCRIPTION
    Release all the nodes in a skip list.  The 'op' routine is called for
    each node in the list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    The return value from the 'op' routine is ignored.

    The skip list itself is still valid, it just has all its nodes removed.
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5SL__release_common(H5SL_t *slist, H5SL_operator_t op, void *op_data)
{
    H5SL_node_t *node, *next_node; /* Pointers to skip list nodes */
    herr_t       ret_value = SUCCEED;

    FUNC_ENTER_STATIC

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Free skip list nodes */
    node = slist->header->forward[0];
    while (node) {
        next_node = node->forward[0];

        /* Call callback, if one is given.
         *
         * Ignoring const here is fine as we only need the value to be const
         * with respect to the list code, which should never modify the
         * elements. The library code that is making use of the skip list
         * container can do what it likes with the elements.
         */
        H5_GCC_DIAG_OFF("cast-qual")
        if (op)
            (void)(op)(node->item, (void *)node->key, op_data);
        H5_GCC_DIAG_ON("cast-qual")

        node->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[node->log_nalloc], node->forward);
        node          = H5FL_FREE(H5SL_node_t, node);
        node          = next_node;
    }

    /* Reset the header pointers */
    slist->header->forward =
        (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[slist->header->log_nalloc], slist->header->forward);
    if (NULL == (slist->header->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0])))
        HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, FAIL, "memory allocation failed")
    slist->header->forward[0] = NULL;
    slist->header->log_nalloc = 0;
    slist->header->level      = 0;

    /* Reset the last pointer */
    slist->last = slist->header;

    /* Reset the dynamic internal fields */
    slist->curr_level = -1;
    slist->nobjs      = 0;

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__release_common() */

/*--------------------------------------------------------------------------
 NAME
    H5SL__close_common
 PURPOSE
    Close a skip list, deallocating it and potentially freeing all its nodes.
 USAGE
    herr_t H5SL__close_common(slist,op,opdata)
        H5SL_t *slist;          IN/OUT: Pointer to skip list to close
        H5SL_operator_t op;     IN: Callback function to free item & key
        void *op_data;          IN/OUT: Pointer to application data for callback

 RETURNS
    Returns non-negative on success, negative on failure.
 DESCRIPTION
    Close a skip list, freeing all internal information.  Any objects left in
    the skip list have the 'op' routine called for each.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    If the 'op' routine returns non-zero, only the nodes up to that
    point in the list are released and the list is still valid.
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5SL__close_common(H5SL_t *slist, H5SL_operator_t op, void *op_data)
{
    herr_t ret_value = SUCCEED;

    FUNC_ENTER_STATIC

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Free skip list nodes */
    if (H5SL__release_common(slist, op, op_data) < 0)
        HGOTO_ERROR(H5E_SLIST, H5E_CANTFREE, FAIL, "can't release skip list nodes")

    /* Release header node */
    slist->header->forward =
        (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[slist->header->log_nalloc], slist->header->forward);
    slist->header = H5FL_FREE(H5SL_node_t, slist->header);

    /* Free skip list object */
    slist = H5FL_FREE(H5SL_t, slist);

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__close_common() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_create
 PURPOSE
    Create a skip list
 USAGE
    H5SL_t *H5SL_create(H5SL_type_t type, H5SL_cmp_t cmp)

 RETURNS
    Returns a pointer to a skip list on success, NULL on failure.
 DESCRIPTION
    Create a skip list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_t *
H5SL_create(H5SL_type_t type, H5SL_cmp_t cmp)
{
    H5SL_t      *new_slist = NULL; /* Pointer to new skip list object created */
    H5SL_node_t *header;           /* Pointer to skip list header node */
    H5SL_t      *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI(NULL)

    /* Check args */
    HDassert(type >= H5SL_TYPE_INT && type <= H5SL_TYPE_GENERIC);

    /* Allocate skip list structure */
    if (NULL == (new_slist = H5FL_MALLOC(H5SL_t)))
        HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed")

    /* Set the static internal fields */
    new_slist->type = type;
    HDassert((type == H5SL_TYPE_GENERIC) == !!cmp);
    new_slist->cmp = cmp;

    /* Set the dynamic internal fields */
    new_slist->curr_level = -1;
    new_slist->nobjs      = 0;

    /* Allocate the header node */
    if (NULL == (header = H5SL__new_node(NULL, NULL, (uint32_t)ULONG_MAX)))
        HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "can't create new skip list node")

    /* Initialize header node's forward pointer */
    header->forward[0] = NULL;

    /* Initialize header node's backward pointer */
    header->backward = NULL;

    /* Attach the header */
    new_slist->header = header;
    new_slist->last   = header;

    /* Set the return value */
    ret_value = new_slist;

done:
    /* Error cleanup */
    if (ret_value == NULL) {
        if (new_slist != NULL)
            new_slist = H5FL_FREE(H5SL_t, new_slist);
    }

    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_create() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_count
 PURPOSE
    Count the number of objects in a skip list
 USAGE
    size_t H5SL_count(slist)
        H5SL_t *slist;            IN: Pointer to skip list to count

 RETURNS
    Returns number of objects on success, can't fail
 DESCRIPTION
    Count elements in a skip list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
size_t
H5SL_count(H5SL_t *slist)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    FUNC_LEAVE_NOAPI(slist->nobjs)
} /* end H5SL_count() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_insert
 PURPOSE
    Insert an object into a skip list
 USAGE
    herr_t H5SL_insert(slist,item,key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *item;             IN: Item to insert
        void *key;              IN: Key for item to insert

 RETURNS
    Returns non-negative on success, negative on failure.
 DESCRIPTION
    Insert element into a skip list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    Inserting an item with the same key as an existing object fails.
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5SL_insert(H5SL_t *slist, void *item, const void *key)
{
    herr_t ret_value = SUCCEED; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */
    if (NULL == H5SL__insert_common(slist, item, key))
        HGOTO_ERROR(H5E_SLIST, H5E_CANTINSERT, FAIL, "can't create new skip list node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_insert() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_add
 PURPOSE
    Insert an object into a skip list
 USAGE
    H5SL_node_t *H5SL_add(slist,item,key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *item;             IN: Item to insert
        void *key;              IN: Key for item to insert

 RETURNS
    Returns pointer to new skip list node on success, NULL on failure.
 DESCRIPTION
    Insert element into a skip list and return the skip list node for the
    new element in the list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    Inserting an item with the same key as an existing object fails.

    This routine is a useful starting point for next/prev calls
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_add(H5SL_t *slist, void *item, const void *key)
{
    H5SL_node_t *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */
    if (NULL == (ret_value = H5SL__insert_common(slist, item, key)))
        HGOTO_ERROR(H5E_SLIST, H5E_CANTINSERT, NULL, "can't create new skip list node")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_add() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_remove
 PURPOSE
    Removes an object from a skip list
 USAGE
    void *H5SL_remove(slist,key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *key;              IN: Key for item to remove

 RETURNS
    Returns pointer to item removed on success, NULL on failure.
 DESCRIPTION
    Remove element from a skip list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
void *
H5SL_remove(H5SL_t *slist, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    uint32_t     hashval   = 0;    /* Hash value for key */
    void        *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Remove item from skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to remove
     */
    x = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_REMOVE(SCALAR, slist, x, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_REMOVE(SCALAR, slist, x, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_REMOVE(STRING, slist, x, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_REMOVE(SCALAR, slist, x, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_REMOVE(SCALAR, slist, x, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_REMOVE(SCALAR, slist, x, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_REMOVE(OBJ, slist, x, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_REMOVE(SCALAR, slist, x, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_REMOVE(GENERIC, slist, x, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_remove() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_remove_first
 PURPOSE
    Removes the first object from a skip list
 USAGE
    void *H5SL_remove_first(slist)
        H5SL_t *slist;          IN/OUT: Pointer to skip list

 RETURNS
    Returns pointer to item removed on success, NULL on failure.
 DESCRIPTION
    Remove first element from a skip list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
void *
H5SL_remove_first(H5SL_t *slist)
{
    void        *ret_value = NULL;                      /* Return value             */
    H5SL_node_t *head      = slist->header;             /* Skip list header         */
    H5SL_node_t *tmp       = slist->header->forward[0]; /* Temporary node pointer   */
    H5SL_node_t *next;                                  /* Next node to search for  */
    size_t       level;                                 /* Skip list level          */
    size_t       i;                                     /* Index                    */

    FUNC_ENTER_NOAPI_NOINIT

    /* Check args */
    HDassert(slist);

    /* Assign level */
    H5_CHECK_OVERFLOW(slist->curr_level, int, size_t);
    level = (size_t)slist->curr_level;

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Remove item from skip list */

    /* Check for empty list */
    if (slist->last != slist->header) {

        /* Assign return value */
        ret_value = tmp->item;
        HDassert(level == head->level);
        HDassert(0 == tmp->level);

        /* Remove the first node */
        head->forward[0] = tmp->forward[0];
        if (slist->last == tmp)
            slist->last = head;
        else
            tmp->forward[0]->backward = head;
        slist->nobjs--;
        /* Free memory */
        tmp->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[0], tmp->forward);
        tmp          = H5FL_FREE(H5SL_node_t, tmp);

        /* Reshape the skip list as necessary to maintain 1-2-3 condition */
        for (i = 0; i < level; i++) {
            next = head->forward[i + 1];
            HDassert(next);

            /* Check if  head->forward[i] == head->forward[i+1] (illegal) */
            if (head->forward[i] == next) {
                tmp  = next;
                next = next->forward[i + 1];

                HDassert(tmp->level == i + 1);

                /* Demote head->forward[i] */
                H5SL_DEMOTE(tmp, head)

                /* Check if we need to promote the following node to maintain
                 * 1-2-3 condition */
                if (tmp->forward[i]->forward[i] != next) {
                    HDassert(tmp->forward[i]->forward[i]->forward[i] == next ||
                             tmp->forward[i]->forward[i]->forward[i]->forward[i] == next);
                    tmp = tmp->forward[i];
                    H5SL_PROMOTE(slist, tmp, head, NULL);
                    /* In this case, since there is a node of height = i+1 here
                     * now (tmp), we know the skip list must be valid and can
                     * break */
                    break;
                }
                else if (!head->forward[i + 1]) {
                    /* We just shrunk the largest node, shrink the header */
                    HDassert(i == level - 1);

                    H5SL_SHRINK(head, level)
                    slist->curr_level--;
                }
            }
            else
                break;
        }
    }

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_remove_first() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_search
 PURPOSE
    Search for object in a skip list
 USAGE
    void *H5SL_search(slist,key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *key;              IN: Key for item to search for

 RETURNS
    Returns pointer to item on success, NULL on failure
 DESCRIPTION
    Search for an object in a skip list, according to it's key
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
void *
H5SL_search(H5SL_t *slist, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    uint32_t     hashval   = 0;    /* Hash value for key */
    void        *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to insert
     */
    x = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_SEARCH(SCALAR, slist, x, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_SEARCH(SCALAR, slist, x, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_SEARCH(STRING, slist, x, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_SEARCH(SCALAR, slist, x, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_SEARCH(SCALAR, slist, x, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_SEARCH(SCALAR, slist, x, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_SEARCH(OBJ, slist, x, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_SEARCH(SCALAR, slist, x, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_SEARCH(GENERIC, slist, x, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

    /* 'key' must not have been found in list, if we get here */
    ret_value = NULL;

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_search() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_less
 PURPOSE
    Search for object in a skip list that is less than or equal to 'key'
 USAGE
    void *H5SL_less(slist,key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *key;              IN: Key for item to search for

 RETURNS
    Returns pointer to item who key is less than or equal to 'key' on success,
        NULL on failure
 DESCRIPTION
    Search for an object in a skip list, according to it's key, returning the
    object itself (for an exact match), or the object with the next highest
    key that is less than 'key'
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
void *
H5SL_less(H5SL_t *slist, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    uint32_t     hashval   = 0;    /* Hash value for key */
    void        *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to insert
     */
    x = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_SEARCH(SCALAR, slist, x, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_SEARCH(SCALAR, slist, x, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_SEARCH(STRING, slist, x, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_SEARCH(SCALAR, slist, x, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_SEARCH(SCALAR, slist, x, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_SEARCH(SCALAR, slist, x, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_SEARCH(OBJ, slist, x, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_SEARCH(SCALAR, slist, x, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_SEARCH(GENERIC, slist, x, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

    /* An exact match for 'key' must not have been found in list, if we get here */
    /* Check for a node with a key that is less than the given 'key' */
    if (x == NULL) {
        /* Check for walking off the list */
        if (slist->last != slist->header)
            ret_value = slist->last->item;
        else
            ret_value = NULL;
    }
    else {
        if (x->backward != slist->header)
            ret_value = x->backward->item;
        else
            ret_value = NULL;
    }

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_less() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_greater
 PURPOSE
    Search for object in a skip list that is greater than or equal to 'key'
 USAGE
    void *H5SL_greater(slist, key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *key;              IN: Key for item to search for

 RETURNS
    Returns pointer to item who key is greater than or equal to 'key' on success,
        NULL on failure
 DESCRIPTION
    Search for an object in a skip list, according to it's key, returning the
    object itself (for an exact match), or the object with the next lowest
    key that is greater than 'key'
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
void *
H5SL_greater(H5SL_t *slist, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    uint32_t     hashval   = 0;    /* Hash value for key */
    void        *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to insert
     */
    x = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_SEARCH(SCALAR, slist, x, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_SEARCH(SCALAR, slist, x, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_SEARCH(STRING, slist, x, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_SEARCH(SCALAR, slist, x, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_SEARCH(SCALAR, slist, x, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_SEARCH(SCALAR, slist, x, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_SEARCH(OBJ, slist, x, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_SEARCH(SCALAR, slist, x, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_SEARCH(GENERIC, slist, x, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

    /* An exact match for 'key' must not have been found in list, if we get here */
    /* ('x' must be the next node with a key greater than the 'key', or NULL) */
    if (x)
        ret_value = x->item;
    else
        ret_value = NULL;

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_greater() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_find
 PURPOSE
    Search for _node_ in a skip list
 USAGE
    H5SL_node_t *H5SL_node(slist,key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *key;              IN: Key for item to search for

 RETURNS
    Returns pointer to _node_ matching key on success, NULL on failure
 DESCRIPTION
    Search for an object in a skip list, according to it's key and returns
    the node that the object is attached to
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    This routine is a useful starting point for next/prev calls
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_find(H5SL_t *slist, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    uint32_t     hashval   = 0;    /* Hash value for key */
    H5SL_node_t *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to insert
     */
    x = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_FIND(SCALAR, slist, x, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_FIND(SCALAR, slist, x, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_FIND(STRING, slist, x, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_FIND(SCALAR, slist, x, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_FIND(SCALAR, slist, x, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_FIND(SCALAR, slist, x, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_FIND(OBJ, slist, x, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_FIND(SCALAR, slist, x, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_FIND(GENERIC, slist, x, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

    /* 'key' must not have been found in list, if we get here */
    ret_value = NULL;

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_find() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_below
 PURPOSE
    Search for _node_ in a skip list whose object is less than or equal to 'key'
 USAGE
    H5SL_node_t *H5SL_below(slist, key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *key;              IN: Key for item to search for

 RETURNS
    Returns pointer to _node_ who key is less than or equal to 'key' on success,
        NULL on failure
 DESCRIPTION
    Search for a node with an object in a skip list, according to it's key,
    returning the node itself (for an exact match), or the node with the next
    highest key that is less than 'key'
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_below(H5SL_t *slist, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    uint32_t     hashval   = 0;    /* Hash value for key */
    H5SL_node_t *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to insert
     */
    x = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_FIND(SCALAR, slist, x, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_FIND(SCALAR, slist, x, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_FIND(STRING, slist, x, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_FIND(SCALAR, slist, x, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_FIND(SCALAR, slist, x, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_FIND(SCALAR, slist, x, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_FIND(OBJ, slist, x, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_FIND(SCALAR, slist, x, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_FIND(GENERIC, slist, x, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

    /* An exact match for 'key' must not have been found in list, if we get here */
    /* Check for a node with a key that is less than the given 'key' */
    if (NULL == x) {
        /* Check for walking off the list */
        if (slist->last != slist->header)
            ret_value = slist->last;
        else
            ret_value = NULL;
    }
    else {
        if (x->backward != slist->header)
            ret_value = x->backward;
        else
            ret_value = NULL;
    }

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_below() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_above
 PURPOSE
    Search for _node_ in a skip list whose object is greater than or equal to 'key'
 USAGE
    H5SL_node_t *H5SL_above(slist, key)
        H5SL_t *slist;          IN/OUT: Pointer to skip list
        void *key;              IN: Key for item to search for

 RETURNS
    Returns pointer to _node_ with object that has a key is greater than or
        equal to 'key' on success, NULL on failure
 DESCRIPTION
    Search for a node with an object in a skip list, according to it's key,
    returning the node itself (for an exact match), or the node with the next
    lowest key that is greater than 'key'
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_above(H5SL_t *slist, const void *key)
{
    H5SL_node_t *x;                /* Current node to examine */
    uint32_t     hashval   = 0;    /* Hash value for key */
    H5SL_node_t *ret_value = NULL; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);
    HDassert(key);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Insert item into skip list */

    /* Work through the forward pointers for a node, finding the node at each
     * level that is before the location to insert
     */
    x = slist->header;
    switch (slist->type) {
        case H5SL_TYPE_INT:
            H5SL_FIND(SCALAR, slist, x, const int, key, -)
            break;

        case H5SL_TYPE_HADDR:
            H5SL_FIND(SCALAR, slist, x, const haddr_t, key, -)
            break;

        case H5SL_TYPE_STR:
            H5SL_FIND(STRING, slist, x, char *, key, hashval)
            break;

        case H5SL_TYPE_HSIZE:
            H5SL_FIND(SCALAR, slist, x, const hsize_t, key, -)
            break;

        case H5SL_TYPE_UNSIGNED:
            H5SL_FIND(SCALAR, slist, x, const unsigned, key, -)
            break;

        case H5SL_TYPE_SIZE:
            H5SL_FIND(SCALAR, slist, x, const size_t, key, -)
            break;

        case H5SL_TYPE_OBJ:
            H5SL_FIND(OBJ, slist, x, const H5_obj_t, key, -)
            break;

        case H5SL_TYPE_HID:
            H5SL_FIND(SCALAR, slist, x, const hid_t, key, -)
            break;

        case H5SL_TYPE_GENERIC:
            H5SL_FIND(GENERIC, slist, x, const void, key, -)
            break;

        default:
            HDassert(0 && "Unknown skiplist type!");
    }

    /* An exact match for 'key' must not have been found in list, if we get here */
    /* ('x' must be the next node with a key greater than the 'key', or NULL) */
    if (x)
        ret_value = x;
    else
        ret_value = NULL;

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_above() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_first
 PURPOSE
    Gets a pointer to the first node in a skip list
 USAGE
    H5SL_node_t *H5SL_first(slist)
        H5SL_t *slist;          IN: Pointer to skip list

 RETURNS
    Returns pointer to first node in skip list on success, NULL on failure.
 DESCRIPTION
    Retrieves a pointer to the first node in a skip list, for iterating over
    the list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_first(H5SL_t *slist)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    FUNC_LEAVE_NOAPI(slist->header->forward[0])
} /* end H5SL_first() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_next
 PURPOSE
    Gets a pointer to the next node in a skip list
 USAGE
    H5SL_node_t *H5SL_next(slist_node)
        H5SL_node_t *slist_node;          IN: Pointer to skip list node

 RETURNS
    Returns pointer to node after slist_node in skip list on success, NULL on failure.
 DESCRIPTION
    Retrieves a pointer to the next node in a skip list, for iterating over
    the list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_next(H5SL_node_t *slist_node)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist_node);

    /* Check internal consistency */
    /* (Pre-condition) */

    FUNC_LEAVE_NOAPI(slist_node->forward[0])
} /* end H5SL_next() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_prev
 PURPOSE
    Gets a pointer to the previous node in a skip list
 USAGE
    H5SL_node_t *H5SL_prev(slist_node)
        H5SL_node_t *slist_node;          IN: Pointer to skip list node

 RETURNS
    Returns pointer to node before slist_node in skip list on success, NULL on failure.
 DESCRIPTION
    Retrieves a pointer to the previous node in a skip list, for iterating over
    the list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_prev(H5SL_node_t *slist_node)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist_node);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Walk backward, detecting the header node (which has it's key set to NULL) */
    FUNC_LEAVE_NOAPI(slist_node->backward->key == NULL ? NULL : slist_node->backward)
} /* end H5SL_prev() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_last
 PURPOSE
    Gets a pointer to the last node in a skip list
 USAGE
    H5SL_node_t *H5SL_last(slist)
        H5SL_t *slist;          IN: Pointer to skip list

 RETURNS
    Returns pointer to last node in skip list on success, NULL on failure.
 DESCRIPTION
    Retrieves a pointer to the last node in a skip list, for iterating over
    the list.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
H5SL_node_t *
H5SL_last(H5SL_t *slist)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Find last node, avoiding the header node */
    FUNC_LEAVE_NOAPI(slist->last == slist->header ? NULL : slist->last)
} /* end H5SL_last() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_item
 PURPOSE
    Gets pointer to the 'item' for a skip list node
 USAGE
    void *H5SL_item(slist_node)
        H5SL_node_t *slist_node;          IN: Pointer to skip list node

 RETURNS
    Returns pointer to node 'item' on success, NULL on failure.
 DESCRIPTION
    Retrieves a node's 'item'
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
void *
H5SL_item(H5SL_node_t *slist_node)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist_node);

    /* Check internal consistency */
    /* (Pre-condition) */

    FUNC_LEAVE_NOAPI(slist_node->item)
} /* end H5SL_item() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_iterate
 PURPOSE
    Iterate over all nodes in a skip list
 USAGE
    herr_t H5SL_iterate(slist, op, op_data)
        H5SL_t *slist;          IN/OUT: Pointer to skip list to iterate over
        H5SL_operator_t op;     IN: Callback function for iteration
        void *op_data;          IN/OUT: Pointer to application data for callback

 RETURNS
    Returns a negative value if something is wrong, the return
        value of the last operator if it was non-zero, or zero if all
        nodes were processed.
 DESCRIPTION
    Iterate over all the nodes in a skip list, calling an application callback
    with the item, key and any operator data.

    The operator callback receives a pointer to the item and key for the list
    being iterated over ('mesg'), and the pointer to the operator data passed
    in to H5SL_iterate ('op_data').  The return values from an operator are:
        A. Zero causes the iterator to continue, returning zero when all
            nodes of that type have been processed.
        B. Positive causes the iterator to immediately return that positive
            value, indicating short-circuit success.
        C. Negative causes the iterator to immediately return that value,
            indicating failure.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5SL_iterate(H5SL_t *slist, H5SL_operator_t op, void *op_data)
{
    H5SL_node_t *node;          /* Pointer to current skip list node */
    H5SL_node_t *next;          /* Pointer to next skip list node */
    herr_t       ret_value = 0; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Free skip list nodes */
    node = slist->header->forward[0];
    while (node != NULL) {
        /* Protect against the node being deleted by the callback */
        next = node->forward[0];

        /* Call the iterator callback
         *
         * Ignoring const here is fine as we only need the value to be const
         * with respect to the list code, which should never modify the
         * elements. The library code that is making use of the skip list
         * container can do what it likes with the elements.
         */
        H5_GCC_DIAG_OFF("cast-qual")
        if ((ret_value = (op)(node->item, (void *)node->key, op_data)) != 0)
            break;
        H5_GCC_DIAG_ON("cast-qual")

        /* Advance to next node */
        node = next;
    }

    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_iterate() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_release
 PURPOSE
    Release all nodes from a skip list
 USAGE
    herr_t H5SL_release(slist)
        H5SL_t *slist;            IN/OUT: Pointer to skip list to release nodes

 RETURNS
    Returns non-negative on success, negative on failure.
 DESCRIPTION
    Release all the nodes in a skip list.  Any objects left in the skip list
    nodes are not deallocated.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    The skip list itself is still valid, it just has all its nodes removed.
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5SL_release(H5SL_t *slist)
{
    herr_t ret_value = SUCCEED;

    FUNC_ENTER_NOAPI(FAIL)

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Free skip list nodes */
    if (H5SL__release_common(slist, NULL, NULL) < 0)
        HGOTO_ERROR(H5E_SLIST, H5E_CANTFREE, FAIL, "can't release skip list nodes")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_release() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_free
 PURPOSE
    Release all nodes from a skip list, freeing all nodes
 USAGE
    herr_t H5SL_free(slist,op,op_data)
        H5SL_t *slist;          IN/OUT: Pointer to skip list to release nodes
        H5SL_operator_t op;     IN: Callback function to free item & key
        void *op_data;          IN/OUT: Pointer to application data for callback

 RETURNS
    Returns non-negative on success, negative on failure.
 DESCRIPTION
    Release all the nodes in a skip list.  Any objects left in
    the skip list have the 'op' routine called for each.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    The skip list itself is still valid, it just has all its nodes removed.

    The return value from the 'op' routine is ignored.

    This routine is essentially a combination of iterating over all the nodes
    (where the iterator callback is supposed to free the items and/or keys)
    followed by a call to H5SL_release().
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5SL_free(H5SL_t *slist, H5SL_operator_t op, void *op_data)
{
    herr_t ret_value = SUCCEED;

    FUNC_ENTER_NOAPI(FAIL)

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Free skip list nodes */
    if (H5SL__release_common(slist, op, op_data) < 0)
        HGOTO_ERROR(H5E_SLIST, H5E_CANTFREE, FAIL, "can't release skip list nodes")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_free() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_destroy
 PURPOSE
    Close a skip list, deallocating it and freeing all its nodes.
 USAGE
    herr_t H5SL_destroy(slist,op,opdata)
        H5SL_t *slist;          IN/OUT: Pointer to skip list to close
        H5SL_operator_t op;     IN: Callback function to free item & key
        void *op_data;          IN/OUT: Pointer to application data for callback

 RETURNS
    Returns non-negative on success, negative on failure.
 DESCRIPTION
    Close a skip list, freeing all internal information.  Any objects left in
    the skip list have the 'op' routine called for each.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    The return value from the 'op' routine is ignored.

    This routine is essentially a combination of iterating over all the nodes
    (where the iterator callback is supposed to free the items and/or keys)
    followed by a call to H5SL_close().
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5SL_destroy(H5SL_t *slist, H5SL_operator_t op, void *op_data)
{
    herr_t ret_value = SUCCEED; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Close skip list */
    if (H5SL__close_common(slist, op, op_data) < 0)
        HGOTO_ERROR(H5E_SLIST, H5E_CANTCLOSEOBJ, FAIL, "can't close skip list")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_destroy() */

/*--------------------------------------------------------------------------
 NAME
    H5SL_close
 PURPOSE
    Close a skip list, deallocating it.
 USAGE
    herr_t H5SL_close(slist)
        H5SL_t *slist;            IN/OUT: Pointer to skip list to close

 RETURNS
    Returns non-negative on success, negative on failure.
 DESCRIPTION
    Close a skip list, freeing all internal information.  Any objects left in
    the skip list are not deallocated.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5SL_close(H5SL_t *slist)
{
    herr_t ret_value = SUCCEED; /* Return value */

    FUNC_ENTER_NOAPI_NOINIT

    /* Check args */
    HDassert(slist);

    /* Check internal consistency */
    /* (Pre-condition) */

    /* Close skip list */
    if (H5SL__close_common(slist, NULL, NULL) < 0)
        HGOTO_ERROR(H5E_SLIST, H5E_CANTCLOSEOBJ, FAIL, "can't close skip list")

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_close() */