summaryrefslogtreecommitdiffstats
path: root/src/H5SL.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
commitb2d661b508a7fc7a2592c13bc6bdc175551f075d (patch)
tree13baeb0d83a7c2a4c6299993c182b1227c2f6114 /src/H5SL.c
parent29ab58b58dce556639ea3154e262895773a8a8df (diff)
downloadhdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2
Clang-format of source files
Diffstat (limited to 'src/H5SL.c')
-rw-r--r--src/H5SL.c1232
1 files changed, 601 insertions, 631 deletions
diff --git a/src/H5SL.c b/src/H5SL.c
index 4716dc4..443eaff 100644
--- a/src/H5SL.c
+++ b/src/H5SL.c
@@ -57,521 +57,516 @@
*
*/
-#include "H5SLmodule.h" /* This source code file is part of the H5SL module */
-
+#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 */
+#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) \
-{ \
- HDassert(!X->removed); \
- HGOTO_DONE(X->item); \
-} /* end block */
+#define H5SL_LOCATE_SEARCH_FOUND(SLIST, X, I) \
+ { \
+ HDassert(!X->removed); \
+ HGOTO_DONE(X->item); \
+ } /* end block */
/* Define the code template for deferred removals for the "OP" in the
* H5SL_LOCATE macro */
-#define H5SL_LOCATE_SEARCH_DEFER_REMOVE_FOUND(SLIST, X, I) \
-{ \
- HDassert(!X->removed); \
- X->removed = TRUE; \
- HGOTO_DONE(X->item); \
-} /* end block */
+#define H5SL_LOCATE_SEARCH_DEFER_REMOVE_FOUND(SLIST, X, I) \
+ { \
+ HDassert(!X->removed); \
+ X->removed = TRUE; \
+ HGOTO_DONE(X->item); \
+ } /* end block */
/* Define the code template for finds for the "OP" in the H5SL_LOCATE macro */
-#define H5SL_LOCATE_FIND_FOUND(SLIST, X, I) \
-{ \
- HDassert(!X->removed); \
- HGOTO_DONE(X); \
-} /* end block */
-
+#define H5SL_LOCATE_FIND_FOUND(SLIST, X, I) \
+ { \
+ HDassert(!X->removed); \
+ HGOTO_DONE(X); \
+ } /* end block */
/* 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 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 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 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 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 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 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 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 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 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 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 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 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++; \
- } /* end while */ \
- } /* end for */ \
- 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) \
- } /* end if */ \
-}
+#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++; \
+ } /* end while */ \
+ } /* end for */ \
+ 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) \
+ } /* end if */ \
+ }
/* Macro used to find node for operation, if there may be "removed" nodes in the
* list (whose keys cannot be read) */
-#define H5SL_LOCATE_SAFE(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
-{ \
- int _i; /* Local index variable */ \
- H5SL_node_t *_low = X; \
- H5SL_node_t *_high = NULL; \
- \
- H5_GLUE3(H5SL_LOCATE_,CMP,_HASHINIT)(KEY, HASHVAL) \
- for(_i = (int)SLIST->curr_level; _i >= 0; _i--) { \
- X = _low->forward[_i]; \
- while(X != _high) { \
- if(!X->removed) { \
- if(H5_GLUE3(H5SL_LOCATE_,CMP,_CMP)(SLIST, TYPE, X, KEY, HASHVAL)) \
- _low = X; \
- else \
- break; \
- } /* end if */ \
- X = X->forward[_i]; \
- } /* end while */ \
- _high = X; \
- 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) \
- break; \
- } /* end if */ \
- } /* end for */ \
-}
+#define H5SL_LOCATE_SAFE(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
+ { \
+ int _i; /* Local index variable */ \
+ H5SL_node_t *_low = X; \
+ H5SL_node_t *_high = NULL; \
+ \
+ H5_GLUE3(H5SL_LOCATE_, CMP, _HASHINIT) \
+ (KEY, HASHVAL) for (_i = (int)SLIST->curr_level; _i >= 0; _i--) \
+ { \
+ X = _low->forward[_i]; \
+ while (X != _high) { \
+ if (!X->removed) { \
+ if (H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, X, KEY, HASHVAL)) \
+ _low = X; \
+ else \
+ break; \
+ } /* end if */ \
+ X = X->forward[_i]; \
+ } /* end while */ \
+ _high = X; \
+ 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) break; \
+ } /* end if */ \
+ } /* end for */ \
+ }
/* Macro used to find node for operation */
-#define H5SL_LOCATE(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
-{ \
- if((SLIST)->safe_iterating) \
- H5SL_LOCATE_SAFE(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
- else \
- H5SL_LOCATE_OPT(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
-}
-
+#define H5SL_LOCATE(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
+ { \
+ if ((SLIST)->safe_iterating) \
+ H5SL_LOCATE_SAFE(OP, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
+ else \
+ 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") \
- } /* end if */ \
- \
- /* 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++; \
- } /* end if */ \
- \
- /* 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; \
- } /* end if */ \
- \
- X->level++; \
-}
-
+#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") \
+ } /* end if */ \
+ \
+ /* 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++; \
+ } /* end if */ \
+ \
+ /* 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; \
+ } /* end if */ \
+ \
+ 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; \
- } /* end if */ \
- \
- 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; \
+ } /* end if */ \
+ \
+ 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]; \
- } /* end else */ \
- PREV->forward[_lvl+1] = X; \
-}
-
+#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]; \
+ } /* end else */ \
+ 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 currrent 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); \
-}
-
+#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 currect 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; \
- } /* end if */ \
- \
- /* 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]; \
- } /* end for */ \
- 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]; \
- } /* end for */ \
- \
- 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") \
-}
-
+#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 currect 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; \
+ } /* end if */ \
+ \
+ /* 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]; \
+ } /* end for */ \
+ 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]; \
+ } /* end for */ \
+ \
+ 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) \
-{ \
- /* Check for deferred removal */ \
- if(SLIST->safe_iterating) \
- H5SL_LOCATE(SEARCH_DEFER_REMOVE, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
- else { \
- 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 currect 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; \
- } /* end if */ \
- \
- /* 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; \
- } /* end if */ \
- } /* end if */ \
- else \
- _ldrop = X; \
- } /* end else */ \
- \
- /* 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; \
- } /* end if */ \
- X = X->forward[_i]; \
- } /* end for */ \
- 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--; \
- } /* end else */ \
- } 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--; \
- } /* end else */ \
- } /* end else */ \
- } /* end if */ \
- \
- /* Prepare to drop down */ \
- _llast = _ldrop; \
- _last = _drop; \
- _next = _drop->forward[_i]; \
- } /* end for */ \
- \
- /* 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; \
- } /* end if */ \
- 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); \
- } /* end if */ \
- } /* end else */ \
-}
-
+#define H5SL_REMOVE(CMP, SLIST, X, TYPE, KEY, HASHVAL) \
+ { \
+ /* Check for deferred removal */ \
+ if (SLIST->safe_iterating) \
+ H5SL_LOCATE(SEARCH_DEFER_REMOVE, CMP, SLIST, X, TYPE, KEY, HASHVAL) \
+ else { \
+ 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 currect 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; \
+ } /* end if */ \
+ \
+ /* 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; \
+ } /* end if */ \
+ } /* end if */ \
+ else \
+ _ldrop = X; \
+ } /* end else */ \
+ \
+ /* 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; \
+ } /* end if */ \
+ X = X->forward[_i]; \
+ } /* end for */ \
+ 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--; \
+ } /* end else */ \
+ } \
+ 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--; \
+ } /* end else */ \
+ } /* end else */ \
+ } /* end if */ \
+ \
+ /* Prepare to drop down */ \
+ _llast = _ldrop; \
+ _last = _drop; \
+ _next = _drop->forward[_i]; \
+ } /* end for */ \
+ \
+ /* 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; \
+ } /* end if */ \
+ 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); \
+ } /* end if */ \
+ } /* end else */ \
+ }
/* Macro used to search for node */
-#define H5SL_SEARCH(CMP, SLIST, X, TYPE, KEY, HASHVAL) \
- H5SL_LOCATE(SEARCH, CMP, SLIST, X, TYPE, KEY, HASHVAL)
+#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)
-
+#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) */
- hbool_t removed; /* Whether the node is "removed" (actual removal deferred) */
- struct H5SL_node_t **forward; /* Array of forward pointers from this node */
- struct H5SL_node_t *backward; /* Backward pointer from this node */
+ 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) */
+ hbool_t removed; /* Whether the node is "removed" (actual removal deferred) */
+ 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 */
+ 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 */
- hbool_t safe_iterating; /* Whether a routine is "safely" iterating over the list and removals should be deferred */
+ 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 */
+ hbool_t safe_iterating; /* Whether a routine is "safely" iterating over the list and removals should be
+ deferred */
};
/* 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);
+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;
@@ -584,10 +579,9 @@ 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;
+static size_t H5SL_fac_nused_g;
+static size_t H5SL_fac_nalloc_g;
-
/*--------------------------------------------------------------------------
NAME
H5SL__init_package
@@ -622,7 +616,6 @@ H5SL__init_package(void)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5SL__init_package() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_term_package
@@ -633,7 +626,7 @@ H5SL__init_package(void)
RETURNS
Success: Positive if any action might have caused a change in some
other interface; zero otherwise.
- Failure: Negative
+ Failure: Negative
DESCRIPTION
Release any resources allocated.
GLOBAL VARIABLES
@@ -645,17 +638,17 @@ H5SL__init_package(void)
int
H5SL_term_package(void)
{
- int n = 0;
+ int n = 0;
FUNC_ENTER_NOAPI_NOINIT_NOERR
- if(H5_PKG_INIT_VAR) {
+ 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;
+ 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++) {
+ for (i = 0; i < H5SL_fac_nused_g; i++) {
ret = H5FL_fac_term(H5SL_fac_g[i]);
HDassert(ret >= 0);
} /* end if */
@@ -665,22 +658,21 @@ H5SL_term_package(void)
} /* end if */
/* Free the list of factories */
- if(H5SL_fac_g) {
- H5SL_fac_g = (H5FL_fac_head_t **)H5MM_xfree((void *)H5SL_fac_g);
+ if (H5SL_fac_g) {
+ H5SL_fac_g = (H5FL_fac_head_t **)H5MM_xfree((void *)H5SL_fac_g);
H5SL_fac_nalloc_g = 0;
n++;
} /* end if */
/* Mark the interface as uninitialized */
- if(0 == n)
+ if (0 == n)
H5_PKG_INIT_VAR = FALSE;
} /* end if */
FUNC_LEAVE_NOAPI(n)
} /* H5SL_term_package() */
-
/*--------------------------------------------------------------------------
NAME
H5SL__new_node
@@ -706,21 +698,21 @@ H5SL_term_package(void)
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 */
+ 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)))
+ 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->key = key;
+ ret_value->item = item;
+ ret_value->level = 0;
ret_value->hashval = hashval;
ret_value->removed = FALSE;
- if(NULL == (ret_value->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0]))) {
+ 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")
} /* end if */
@@ -730,7 +722,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__new_node() */
-
/*--------------------------------------------------------------------------
NAME
H5SL__insert_common
@@ -755,10 +746,10 @@ done:
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; /* Return value */
+ 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; /* Return value */
FUNC_ENTER_STATIC
@@ -774,8 +765,8 @@ H5SL__insert_common(H5SL_t *slist, void *item, const void *key)
/* 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) {
+ prev = slist->header;
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_INSERT(SCALAR, slist, prev, const int, key, -)
break;
@@ -816,21 +807,20 @@ H5SL__insert_common(H5SL_t *slist, void *item, const void *key)
HDassert(0 && "Unknown skiplist type!");
} /* end switch */
-
/* 'key' must not have been found in existing list, if we get here */
- if(slist->curr_level < 0)
+ 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")
+ 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];
+ x->backward = prev;
+ x->forward[0] = prev->forward[0];
prev->forward[0] = x;
- if(x->forward[0])
+ if (x->forward[0])
x->forward[0]->backward = x;
else {
HDassert(slist->last == prev);
@@ -841,13 +831,12 @@ H5SL__insert_common(H5SL_t *slist, void *item, const void *key)
slist->nobjs++;
/* Set return value */
- ret_value=x;
+ ret_value = x;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__insert_common() */
-
/*--------------------------------------------------------------------------
NAME
H5SL__release_common
@@ -875,8 +864,8 @@ done:
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;
+ H5SL_node_t *node, *next_node; /* Pointers to skip list nodes */
+ herr_t ret_value = SUCCEED;
FUNC_ENTER_STATIC
@@ -888,39 +877,39 @@ H5SL__release_common(H5SL_t *slist, H5SL_operator_t op, void *op_data)
/* Free skip list nodes */
node = slist->header->forward[0];
- while(node) {
+ while (node) {
next_node = node->forward[0];
/* Call callback, if one is given */
- if(op)
+ if (op)
/* Casting away const OK -QAK */
(void)(op)(node->item, (void *)node->key, op_data);
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;
+ node = H5FL_FREE(H5SL_node_t, node);
+ node = next_node;
} /* end while */
/* 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])))
+ 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;
+ slist->header->level = 0;
/* Reset the last pointer */
slist->last = slist->header;
/* Reset the dynamic internal fields */
slist->curr_level = -1;
- slist->nobjs = 0;
+ slist->nobjs = 0;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__release_common() */
-
/*--------------------------------------------------------------------------
NAME
H5SL__close_common
@@ -958,11 +947,12 @@ H5SL__close_common(H5SL_t *slist, H5SL_operator_t op, void *op_data)
/* (Pre-condition) */
/* Free skip list nodes */
- if(H5SL__release_common(slist, op, op_data) < 0)
+ 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->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 */
@@ -972,7 +962,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL__close_common() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_create
@@ -993,9 +982,9 @@ done:
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 */
+ 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)
@@ -1003,7 +992,7 @@ H5SL_create(H5SL_type_t type, H5SL_cmp_t cmp)
HDassert(type >= H5SL_TYPE_INT && type <= H5SL_TYPE_GENERIC);
/* Allocate skip list structure */
- if(NULL == (new_slist = H5FL_MALLOC(H5SL_t)))
+ if (NULL == (new_slist = H5FL_MALLOC(H5SL_t)))
HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed")
/* Set the static internal fields */
@@ -1012,13 +1001,13 @@ H5SL_create(H5SL_type_t type, H5SL_cmp_t cmp)
new_slist->cmp = cmp;
/* Set the dynamic internal fields */
- new_slist->curr_level = -1;
- new_slist->nobjs = 0;
+ new_slist->curr_level = -1;
+ new_slist->nobjs = 0;
new_slist->safe_iterating = FALSE;
/* 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")
+ 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;
@@ -1028,22 +1017,21 @@ H5SL_create(H5SL_type_t type, H5SL_cmp_t cmp)
/* Attach the header */
new_slist->header = header;
- new_slist->last = header;
+ new_slist->last = header;
/* Set the return value */
ret_value = new_slist;
done:
/* Error cleanup */
- if(ret_value == NULL) {
- if(new_slist != NULL)
+ if (ret_value == NULL) {
+ if (new_slist != NULL)
new_slist = H5FL_FREE(H5SL_t, new_slist);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_create() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_count
@@ -1079,7 +1067,6 @@ H5SL_count(H5SL_t *slist)
FUNC_LEAVE_NOAPI(slist->nobjs)
} /* end H5SL_count() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_insert
@@ -1104,7 +1091,7 @@ H5SL_count(H5SL_t *slist)
herr_t
H5SL_insert(H5SL_t *slist, void *item, const void *key)
{
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -1119,14 +1106,13 @@ H5SL_insert(H5SL_t *slist, void *item, const void *key)
/* (Pre-condition) */
/* Insert item into skip list */
- if(NULL == H5SL__insert_common(slist, item, key))
+ 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
@@ -1154,7 +1140,7 @@ done:
H5SL_node_t *
H5SL_add(H5SL_t *slist, void *item, const void *key)
{
- H5SL_node_t *ret_value = NULL; /* Return value */
+ H5SL_node_t *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -1169,14 +1155,13 @@ H5SL_add(H5SL_t *slist, void *item, const void *key)
/* (Pre-condition) */
/* Insert item into skip list */
- if(NULL == (ret_value = H5SL__insert_common(slist, item, key)))
+ 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
@@ -1199,9 +1184,9 @@ done:
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 */
+ 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
@@ -1218,7 +1203,7 @@ H5SL_remove(H5SL_t *slist, const void *key)
* level that is before the location to remove
*/
x = slist->header;
- switch(slist->type) {
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_REMOVE(SCALAR, slist, x, const int, key, -)
break;
@@ -1263,7 +1248,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_remove() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_remove_first
@@ -1285,12 +1269,12 @@ done:
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 */
+ 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
@@ -1310,7 +1294,7 @@ H5SL_remove_first(H5SL_t *slist)
/* Remove item from skip list */
/* Check for empty list */
- if(slist->last != slist->header) {
+ if (slist->last != slist->header) {
/* Assign return value */
ret_value = tmp->item;
@@ -1319,58 +1303,59 @@ H5SL_remove_first(H5SL_t *slist)
/* Remove the first node */
head->forward[0] = tmp->forward[0];
- if(slist->last == tmp)
+ 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);
+ 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];
+ 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];
+ if (head->forward[i] == next) {
+ tmp = next;
+ next = next->forward[i + 1];
- HDassert(tmp->level == 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) {
+ 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->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]) {
+ }
+ 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--;
} /* end else */
- } else
+ }
+ else
break;
} /* end for */
- } /* end if */
+ } /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_remove_first() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_search
@@ -1393,9 +1378,9 @@ done:
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; /* Return value */
+ H5SL_node_t *x; /* Current node to examine */
+ uint32_t hashval = 0; /* Hash value for key */
+ void * ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT_NOERR
@@ -1411,8 +1396,8 @@ H5SL_search(H5SL_t *slist, const void *key)
/* 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) {
+ x = slist->header;
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_SEARCH(SCALAR, slist, x, const int, key, -)
break;
@@ -1454,13 +1439,12 @@ H5SL_search(H5SL_t *slist, const void *key)
} /* end switch */
/* 'key' must not have been found in list, if we get here */
- ret_value=NULL;
+ ret_value = NULL;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_search() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_less
@@ -1486,9 +1470,9 @@ done:
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 */
+ 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
@@ -1507,8 +1491,8 @@ H5SL_less(H5SL_t *slist, const void *key)
/* 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) {
+ x = slist->header;
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_SEARCH(SCALAR, slist, x, const int, key, -)
break;
@@ -1551,25 +1535,24 @@ H5SL_less(H5SL_t *slist, const void *key)
/* 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) {
+ if (x == NULL) {
/* Check for walking off the list */
- if(slist->last!=slist->header)
- ret_value=slist->last->item;
+ if (slist->last != slist->header)
+ ret_value = slist->last->item;
else
- ret_value=NULL;
+ ret_value = NULL;
} /* end if */
else {
- if(x->backward!=slist->header)
- ret_value=x->backward->item;
+ if (x->backward != slist->header)
+ ret_value = x->backward->item;
else
- ret_value=NULL;
+ ret_value = NULL;
} /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_less() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_greater
@@ -1595,9 +1578,9 @@ done:
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 */
+ 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
@@ -1617,7 +1600,7 @@ H5SL_greater(H5SL_t *slist, const void *key)
* level that is before the location to insert
*/
x = slist->header;
- switch(slist->type) {
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_SEARCH(SCALAR, slist, x, const int, key, -)
break;
@@ -1660,7 +1643,7 @@ H5SL_greater(H5SL_t *slist, const void *key)
/* 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)
+ if (x)
ret_value = x->item;
else
ret_value = NULL;
@@ -1669,7 +1652,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_greater() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_find
@@ -1694,9 +1676,9 @@ done:
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; /* Return value */
+ H5SL_node_t *x; /* Current node to examine */
+ uint32_t hashval = 0; /* Hash value for key */
+ H5SL_node_t *ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT_NOERR
@@ -1712,8 +1694,8 @@ H5SL_find(H5SL_t *slist, const void *key)
/* 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) {
+ x = slist->header;
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_FIND(SCALAR, slist, x, const int, key, -)
break;
@@ -1755,13 +1737,12 @@ H5SL_find(H5SL_t *slist, const void *key)
} /* end switch */
/* 'key' must not have been found in list, if we get here */
- ret_value=NULL;
+ ret_value = NULL;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_find() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_below
@@ -1787,9 +1768,9 @@ done:
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 */
+ 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
@@ -1806,7 +1787,7 @@ H5SL_below(H5SL_t *slist, const void *key)
* level that is before the location to insert
*/
x = slist->header;
- switch(slist->type) {
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_FIND(SCALAR, slist, x, const int, key, -)
break;
@@ -1849,15 +1830,15 @@ H5SL_below(H5SL_t *slist, const void *key)
/* 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) {
+ if (NULL == x) {
/* Check for walking off the list */
- if(slist->last != slist->header)
+ if (slist->last != slist->header)
ret_value = slist->last;
else
ret_value = NULL;
} /* end if */
else {
- if(x->backward != slist->header)
+ if (x->backward != slist->header)
ret_value = x->backward;
else
ret_value = NULL;
@@ -1867,7 +1848,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_below() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_above
@@ -1893,9 +1873,9 @@ done:
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 */
+ 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
@@ -1912,7 +1892,7 @@ H5SL_above(H5SL_t *slist, const void *key)
* level that is before the location to insert
*/
x = slist->header;
- switch(slist->type) {
+ switch (slist->type) {
case H5SL_TYPE_INT:
H5SL_FIND(SCALAR, slist, x, const int, key, -)
break;
@@ -1955,7 +1935,7 @@ H5SL_above(H5SL_t *slist, const void *key)
/* 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)
+ if (x)
ret_value = x;
else
ret_value = NULL;
@@ -1964,7 +1944,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_above() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_first
@@ -2001,7 +1980,6 @@ H5SL_first(H5SL_t *slist)
FUNC_LEAVE_NOAPI(slist->header->forward[0])
} /* end H5SL_first() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_next
@@ -2038,7 +2016,6 @@ H5SL_next(H5SL_node_t *slist_node)
FUNC_LEAVE_NOAPI(slist_node->forward[0])
} /* end H5SL_next() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_prev
@@ -2073,10 +2050,9 @@ H5SL_prev(H5SL_node_t *slist_node)
/* (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)
+ FUNC_LEAVE_NOAPI(slist_node->backward->key == NULL ? NULL : slist_node->backward)
} /* end H5SL_prev() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_last
@@ -2111,10 +2087,9 @@ H5SL_last(H5SL_t *slist)
/* (Pre-condition) */
/* Find last node, avoiding the header node */
- FUNC_LEAVE_NOAPI(slist->last==slist->header ? NULL : slist->last)
+ FUNC_LEAVE_NOAPI(slist->last == slist->header ? NULL : slist->last)
} /* end H5SL_last() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_item
@@ -2150,7 +2125,6 @@ H5SL_item(H5SL_node_t *slist_node)
FUNC_LEAVE_NOAPI(slist_node->item)
} /* end H5SL_item() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_iterate
@@ -2187,9 +2161,9 @@ H5SL_item(H5SL_node_t *slist_node)
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 */
+ 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
@@ -2201,14 +2175,14 @@ H5SL_iterate(H5SL_t *slist, H5SL_operator_t op, void *op_data)
/* Free skip list nodes */
node = slist->header->forward[0];
- while(node != NULL) {
+ while (node != NULL) {
/* Protect against the node being deleted by the callback */
next = node->forward[0];
/* Call the iterator callback */
/* Casting away const OK -QAK */
- if(!node->removed)
- if((ret_value = (op)(node->item, (void *)node->key, op_data)) != 0)
+ if (!node->removed)
+ if ((ret_value = (op)(node->item, (void *)node->key, op_data)) != 0)
break;
/* Advance to next node */
@@ -2218,7 +2192,6 @@ H5SL_iterate(H5SL_t *slist, H5SL_operator_t op, void *op_data)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_iterate() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_release
@@ -2256,14 +2229,13 @@ H5SL_release(H5SL_t *slist)
/* (Pre-condition) */
/* Free skip list nodes */
- if(H5SL__release_common(slist, NULL, NULL) < 0)
+ 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(SUCCEED)
} /* end H5SL_release() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_free
@@ -2309,14 +2281,13 @@ H5SL_free(H5SL_t *slist, H5SL_operator_t op, void *op_data)
/* (Pre-condition) */
/* Free skip list nodes */
- if(H5SL__release_common(slist, op, op_data) < 0)
+ 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_try_free_safe
@@ -2348,8 +2319,8 @@ herr_t
H5SL_try_free_safe(H5SL_t *slist, H5SL_try_free_op_t op, void *op_data)
{
H5SL_node_t *node, *next_node, *last_node; /* Pointers to skip list nodes */
- htri_t op_ret;
- herr_t ret_value = SUCCEED;
+ htri_t op_ret;
+ herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI_NOINIT
@@ -2370,16 +2341,16 @@ H5SL_try_free_safe(H5SL_t *slist, H5SL_try_free_op_t op, void *op_data)
/* Iterate over skip list nodes, making the callback for each and marking
* them as removed if requested by the callback */
node = slist->header->forward[0];
- while(node) {
+ while (node) {
/* Check if the node was already removed */
- if(!node->removed) {
+ if (!node->removed) {
/* Call callback */
/* Casting away const OK -NAF */
- if((op_ret = (op)(node->item , (void *)node->key, op_data)) < 0)
+ if ((op_ret = (op)(node->item, (void *)node->key, op_data)) < 0)
HGOTO_ERROR(H5E_SLIST, H5E_CALLBACK, FAIL, "callback operation failed")
/* Check if op indicated that the node should be removed */
- if(op_ret)
+ if (op_ret)
/* Mark the node as removed */
node->removed = TRUE;
} /* end if */
@@ -2392,17 +2363,17 @@ H5SL_try_free_safe(H5SL_t *slist, H5SL_try_free_op_t op, void *op_data)
slist->safe_iterating = FALSE;
/* Iterate over nodes, freeing ones marked as removed */
- node = slist->header->forward[0];
+ node = slist->header->forward[0];
last_node = slist->header;
- while(node) {
+ while (node) {
/* Save next node */
next_node = node->forward[0];
/* Check if the node was marked as removed */
- if(node->removed) {
+ if (node->removed) {
/* Remove the node */
node->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[node->log_nalloc], node->forward);
- node = H5FL_FREE(H5SL_node_t, node);
+ node = H5FL_FREE(H5SL_node_t, node);
slist->nobjs--;
} /* end if */
else {
@@ -2412,18 +2383,19 @@ H5SL_try_free_safe(H5SL_t *slist, H5SL_try_free_op_t op, void *op_data)
/* Set level to 0. Note there is no need to preserve
* node->forward[0] since it was cached above and will always be
* updated later. */
- if(node->level > 0) {
- node->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[node->log_nalloc], (void *)node->forward);
- if(NULL == (node->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0])))
+ if (node->level > 0) {
+ node->forward =
+ (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[node->log_nalloc], (void *)node->forward);
+ if (NULL == (node->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0])))
HGOTO_ERROR(H5E_SLIST, H5E_CANTALLOC, FAIL, "memory allocation failed")
node->log_nalloc = 0;
- node->level = 0;
+ node->level = 0;
} /* end if */
/* Update pointers */
last_node->forward[0] = node;
- node->backward = last_node;
- last_node = node;
+ node->backward = last_node;
+ last_node = node;
} /* end else */
/* Advance node */
@@ -2432,23 +2404,24 @@ H5SL_try_free_safe(H5SL_t *slist, H5SL_try_free_op_t op, void *op_data)
/* Final pointer update */
last_node->forward[0] = NULL;
- slist->last = last_node;
+ slist->last = last_node;
/* Demote skip list to level 0 */
- if(slist->curr_level > 0) {
+ if (slist->curr_level > 0) {
HDassert(slist->header->level == (size_t)slist->curr_level);
- node = slist->header->forward[0];
- slist->header->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[slist->header->log_nalloc], (void *)slist->header->forward);
- if(NULL == (slist->header->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0])))
+ node = slist->header->forward[0];
+ slist->header->forward = (H5SL_node_t **)H5FL_FAC_FREE(H5SL_fac_g[slist->header->log_nalloc],
+ (void *)slist->header->forward);
+ if (NULL == (slist->header->forward = (H5SL_node_t **)H5FL_FAC_MALLOC(H5SL_fac_g[0])))
HGOTO_ERROR(H5E_SLIST, H5E_CANTALLOC, FAIL, "memory allocation failed")
slist->header->forward[0] = node;
slist->header->log_nalloc = 0;
- slist->header->level = 0;
+ slist->header->level = 0;
} /* end if */
/* Check if there are any nodes left */
- if(slist->nobjs > 0) {
+ if (slist->nobjs > 0) {
int i;
HDassert(slist->header->forward[0]);
@@ -2457,31 +2430,31 @@ H5SL_try_free_safe(H5SL_t *slist, H5SL_try_free_op_t op, void *op_data)
slist->curr_level = 0;
/* Rebuild the forward arrays */
- for(i = 0; slist->curr_level >= i; i++) {
+ for (i = 0; slist->curr_level >= i; i++) {
HDassert(slist->curr_level == i);
/* Promote every third node this level until we run out of nodes */
node = last_node = slist->header;
- while(1) {
+ while (1) {
/* Check second node in gap, if not present, no need to promote
* further this level. */
HDassert(node->forward[i]);
node = node->forward[i]->forward[i];
- if(!node)
+ if (!node)
break;
/* Check third and fourth node in gap, if either is not present,
* no need to promote further this level. */
node = node->forward[i];
- if(!node || !node->forward[i])
+ if (!node || !node->forward[i])
break;
/* Promote the third node in the gap */
H5SL_PROMOTE(slist, node, last_node, FAIL)
last_node = node;
} /* end while */
- } /* end for */
- } /* end if */
+ } /* end for */
+ } /* end if */
else {
HDassert(!slist->header->forward[0]);
HDassert(slist->last == slist->header);
@@ -2495,7 +2468,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_try_free_safe() */
-
/*--------------------------------------------------------------------------
NAME
H5SL_destroy
@@ -2525,7 +2497,7 @@ done:
herr_t
H5SL_destroy(H5SL_t *slist, H5SL_operator_t op, void *op_data)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -2536,14 +2508,13 @@ H5SL_destroy(H5SL_t *slist, H5SL_operator_t op, void *op_data)
/* (Pre-condition) */
/* Close skip list */
- if(H5SL__close_common(slist, op, op_data) < 0)
+ 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
@@ -2566,7 +2537,7 @@ done:
herr_t
H5SL_close(H5SL_t *slist)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -2577,10 +2548,9 @@ H5SL_close(H5SL_t *slist)
/* (Pre-condition) */
/* Close skip list */
- if(H5SL__close_common(slist, NULL, NULL) < 0)
+ 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() */
-