summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2022-04-07 13:52:31 (GMT)
committerGitHub <noreply@github.com>2022-04-07 13:52:31 (GMT)
commitb9d77ec8be0aa633869b1d10510f96f756adf6f9 (patch)
treeecd47a1a95fe1467d63136644233fed96672cb74 /src
parent74863549c0a640909c87e72717e262f91140a2a4 (diff)
parent541bc15452f71f3eae7471fdecbe7994a7f138e2 (diff)
downloadhdf5-b9d77ec8be0aa633869b1d10510f96f756adf6f9.zip
hdf5-b9d77ec8be0aa633869b1d10510f96f756adf6f9.tar.gz
hdf5-b9d77ec8be0aa633869b1d10510f96f756adf6f9.tar.bz2
Merge branch 'hdf5_1_12' into spelling-corrections
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt27
-rw-r--r--src/H5HP.c904
-rw-r--r--src/H5HPprivate.h68
-rw-r--r--src/H5MP.c446
-rw-r--r--src/H5MPmodule.h32
-rw-r--r--src/H5MPpkg.h99
-rw-r--r--src/H5MPprivate.h57
-rw-r--r--src/H5MPtest.c213
-rw-r--r--src/H5SL.c672
-rw-r--r--src/H5SLprivate.h4
-rw-r--r--src/Makefile.am3
11 files changed, 204 insertions, 2321 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e08f485..df3eadf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -370,14 +370,6 @@ set (H5HL_HDRS
IDE_GENERATED_PROPERTIES ("H5HL" "${H5HL_HDRS}" "${H5HL_SOURCES}" )
-set (H5HP_SOURCES
- ${HDF5_SRC_DIR}/H5HP.c
-)
-set (H5HP_HDRS
-)
-IDE_GENERATED_PROPERTIES ("H5HP" "${H5HP_HDRS}" "${H5HP_SOURCES}" )
-
-
set (H5I_SOURCES
${HDF5_SRC_DIR}/H5I.c
${HDF5_SRC_DIR}/H5Idbg.c
@@ -431,16 +423,6 @@ set (H5MM_HDRS
IDE_GENERATED_PROPERTIES ("H5MM" "${H5MM_HDRS}" "${H5MM_SOURCES}" )
-set (H5MP_SOURCES
- ${HDF5_SRC_DIR}/H5MP.c
- ${HDF5_SRC_DIR}/H5MPtest.c
-)
-
-set (H5MP_HDRS
-)
-IDE_GENERATED_PROPERTIES ("H5MP" "${H5MP_HDRS}" "${H5MP_SOURCES}" )
-
-
set (H5O_SOURCES
${HDF5_SRC_DIR}/H5O.c
${HDF5_SRC_DIR}/H5Oainfo.c
@@ -733,7 +715,6 @@ set (H5_MODULE_HEADERS
${HDF5_SRC_DIR}/H5Lmodule.h
${HDF5_SRC_DIR}/H5Mmodule.h
${HDF5_SRC_DIR}/H5MFmodule.h
- ${HDF5_SRC_DIR}/H5MPmodule.h
${HDF5_SRC_DIR}/H5Omodule.h
${HDF5_SRC_DIR}/H5Pmodule.h
${HDF5_SRC_DIR}/H5PBmodule.h
@@ -769,13 +750,11 @@ set (common_SRCS
${H5HF_SOURCES}
${H5HG_SOURCES}
${H5HL_SOURCES}
- ${H5HP_SOURCES}
${H5I_SOURCES}
${H5L_SOURCES}
${H5M_SOURCES}
${H5MF_SOURCES}
${H5MM_SOURCES}
- ${H5MP_SOURCES}
${H5O_SOURCES}
${H5P_SOURCES}
${H5PB_SOURCES}
@@ -818,7 +797,6 @@ set (H5_PUBLIC_HEADERS
${H5M_HDRS}
${H5MF_HDRS}
${H5MM_HDRS}
- ${H5MP_HDRS}
${H5O_HDRS}
${H5P_HDRS}
${H5PB_HDRS}
@@ -895,8 +873,6 @@ set (H5_PRIVATE_HEADERS
${HDF5_SRC_DIR}/H5HLpkg.h
${HDF5_SRC_DIR}/H5HLprivate.h
- ${HDF5_SRC_DIR}/H5HPprivate.h
-
${HDF5_SRC_DIR}/H5Ipkg.h
${HDF5_SRC_DIR}/H5Iprivate.h
@@ -911,9 +887,6 @@ set (H5_PRIVATE_HEADERS
${HDF5_SRC_DIR}/H5MMprivate.h
- ${HDF5_SRC_DIR}/H5MPpkg.h
- ${HDF5_SRC_DIR}/H5MPprivate.h
-
${HDF5_SRC_DIR}/H5Opkg.h
${HDF5_SRC_DIR}/H5Oprivate.h
${HDF5_SRC_DIR}/H5Oshared.h
diff --git a/src/H5HP.c b/src/H5HP.c
deleted file mode 100644
index d164223..0000000
--- a/src/H5HP.c
+++ /dev/null
@@ -1,904 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://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 heap abstract data type.
- *
- * (See chapter 11 - "Priority Queues" of _Algorithms_, by
- * Sedgewick for additional information)
- *
- */
-
-/* Private headers needed */
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5HPprivate.h" /* Heap routines */
-#include "H5FLprivate.h" /* Memory management functions */
-
-/* Local Macros */
-#define H5HP_START_SIZE 16 /* Initial number of entries for heaps */
-
-/* Private typedefs & structs */
-
-/* Data structure for entries in the internal heap array */
-typedef struct {
- int val; /* Value to be used for heap condition */
- H5HP_info_t *obj; /* Pointer to object stored in heap */
-} H5HP_ent_t;
-
-/* Main heap data structure */
-struct H5HP_t {
- H5HP_type_t type; /* Type of heap (minimum or maximum value at "top") */
- size_t nobjs; /* Number of active objects in heap array */
- size_t nalloc; /* Number of allocated locations in heap array */
- H5HP_ent_t *heap; /* Pointer to array containing heap entries */
-};
-
-/* Static functions */
-static herr_t H5HP__swim_max(H5HP_t *heap, size_t loc);
-static herr_t H5HP__swim_min(H5HP_t *heap, size_t loc);
-static herr_t H5HP__sink_max(H5HP_t *heap, size_t loc);
-static herr_t H5HP__sink_min(H5HP_t *heap, size_t loc);
-
-/* Declare a free list to manage the H5HP_t struct */
-H5FL_DEFINE_STATIC(H5HP_t);
-
-/* Declare a free list to manage sequences of H5HP_ent_t */
-H5FL_SEQ_DEFINE_STATIC(H5HP_ent_t);
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP__swim_max
- PURPOSE
- Restore heap condition by moving an object upward
- USAGE
- herr_t H5HP__swim_max(heap, loc)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- size_t loc; IN: Location to start from
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Restore the heap condition for the heap's array by "swimming" the object
- at a location upward.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- This routine is for "maximum" value heaps.
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-static herr_t
-H5HP__swim_max(H5HP_t *heap, size_t loc)
-{
- int val; /* Temporary copy value of object to move in heap */
- H5HP_info_t *obj; /* Temporary pointer to object to move in heap */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_STATIC_NOERR
-
- /* Get copies of the information about the object to move in the heap */
- val = heap->heap[loc].val;
- obj = heap->heap[loc].obj;
-
- /* Move object up in heap until it's reached the maximum location possible */
- while (heap->heap[loc / 2].val < val) {
- /* Move object "above" current location in heap down */
- heap->heap[loc].val = heap->heap[loc / 2].val;
- heap->heap[loc].obj = heap->heap[loc / 2].obj;
-
- /* Update heap location for object which moved */
- heap->heap[loc].obj->heap_loc = loc;
-
- /* Move to location "above" current location */
- loc = loc / 2;
- } /* end while */
-
- /* Put object into heap at correct location */
- heap->heap[loc].val = val;
- heap->heap[loc].obj = obj;
-
- /* Update heap location for object */
- heap->heap[loc].obj->heap_loc = loc;
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP__swim_max() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP__swim_min
- PURPOSE
- Restore heap condition by moving an object upward
- USAGE
- herr_t H5HP__swim_min(heap, loc)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- size_t loc; IN: Location to start from
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Restore the heap condition for the heap's array by "swimming" the object
- at a location upward.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- This routine is for "minimum" value heaps.
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-static herr_t
-H5HP__swim_min(H5HP_t *heap, size_t loc)
-{
- int val; /* Temporary copy value of object to move in heap */
- H5HP_info_t *obj; /* Temporary pointer to object to move in heap */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_STATIC_NOERR
-
- /* Get copies of the information about the object to move in the heap */
- val = heap->heap[loc].val;
- obj = heap->heap[loc].obj;
-
- /* Move object up in heap until it's reached the minimum location possible */
- while (heap->heap[loc / 2].val > val) {
- /* Move object "above" current location in heap down */
- heap->heap[loc].val = heap->heap[loc / 2].val;
- heap->heap[loc].obj = heap->heap[loc / 2].obj;
-
- /* Update heap location for object which moved */
- heap->heap[loc].obj->heap_loc = loc;
-
- /* Move to location "above" current location */
- loc = loc / 2;
- } /* end while */
-
- /* Put object into heap at correct location */
- heap->heap[loc].val = val;
- heap->heap[loc].obj = obj;
-
- /* Update heap location for object */
- heap->heap[loc].obj->heap_loc = loc;
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP__swim_min() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP__sink_max
- PURPOSE
- Restore heap condition by moving an object downward
- USAGE
- herr_t H5HP__sink_max(heap, loc)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- size_t loc; IN: Location to start from
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Restore the heap condition for the heap's array by "sinking" the object
- at a location downward.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- This routine is for "maximum" value heaps.
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-static herr_t
-H5HP__sink_max(H5HP_t *heap, size_t loc)
-{
- int val; /* Temporary copy value of object to move in heap */
- void * obj; /* Temporary pointer to object to move in heap */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_STATIC_NOERR
-
- /* Get copies of the information about the object to move in the heap */
- val = heap->heap[loc].val;
- obj = heap->heap[loc].obj;
-
- /* Move object up in heap until it's reached the maximum location possible */
- while ((2 * loc) <= heap->nobjs) {
- size_t new_loc = loc * 2; /* New object's potential location area */
-
- /* Get the greater of the two objects below the location in heap */
- if (new_loc < heap->nobjs && (heap->heap[new_loc].val < heap->heap[new_loc + 1].val))
- new_loc++;
-
- /* Check if the object is smaller than the larger of the objects below it */
- /* If so, its in the correct location now, and we can get out */
- if (val >= heap->heap[new_loc].val)
- break;
-
- /* Move the greater of the two objects below the current location up */
- heap->heap[loc].val = heap->heap[new_loc].val;
- heap->heap[loc].obj = heap->heap[new_loc].obj;
-
- /* Update heap location for object which moved */
- heap->heap[loc].obj->heap_loc = loc;
-
- /* Move to location "below" current location */
- loc = new_loc;
- } /* end while */
-
- /* Put object into heap at correct location */
- heap->heap[loc].val = val;
- heap->heap[loc].obj = (H5HP_info_t *)obj;
-
- /* Update heap location for object */
- heap->heap[loc].obj->heap_loc = loc;
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP__sink_max() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP__sink_min
- PURPOSE
- Restore heap condition by moving an object downward
- USAGE
- herr_t H5HP__sink_min(heap, loc)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- size_t loc; IN: Location to start from
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Restore the heap condition for the heap's array by "sinking" the object
- at a location downward.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- This routine is for "minimum" value heaps.
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-static herr_t
-H5HP__sink_min(H5HP_t *heap, size_t loc)
-{
- int val; /* Temporary copy value of object to move in heap */
- void * obj; /* Temporary pointer to object to move in heap */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_STATIC_NOERR
-
- /* Get copies of the information about the object to move in the heap */
- val = heap->heap[loc].val;
- obj = heap->heap[loc].obj;
-
- /* Move object up in heap until it's reached the maximum location possible */
- while ((2 * loc) <= heap->nobjs) {
- size_t new_loc = loc * 2; /* New object's potential location area */
-
- /* Get the lesser of the two objects below the location in heap */
- if (new_loc < heap->nobjs && (heap->heap[new_loc].val > heap->heap[new_loc + 1].val))
- new_loc++;
-
- /* Check if the object is greater than the larger of the objects below it */
- /* If so, its in the correct location now, and we can get out */
- if (val <= heap->heap[new_loc].val)
- break;
-
- /* Move the greater of the two objects below the current location up */
- heap->heap[loc].val = heap->heap[new_loc].val;
- heap->heap[loc].obj = heap->heap[new_loc].obj;
-
- /* Update heap location for object which moved */
- heap->heap[loc].obj->heap_loc = loc;
-
- /* Move to location "below" current location */
- loc = new_loc;
- } /* end while */
-
- /* Put object into heap at correct location */
- heap->heap[loc].val = val;
- heap->heap[loc].obj = (H5HP_info_t *)obj;
-
- /* Update heap location for object */
- heap->heap[loc].obj->heap_loc = loc;
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP__sink_min() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_create
- PURPOSE
- Create a heap
- USAGE
- H5HP_t *H5HP_create(heap_type)
- H5HP_type_t heap_type; IN: Type of heap to create
-
- RETURNS
- Returns a pointer to a heap on success, NULL on failure.
- DESCRIPTION
- Create a priority queue. The SIZE is used to set the initial number of
- entries allocated.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-H5HP_t *
-H5HP_create(H5HP_type_t heap_type)
-{
- H5HP_t *new_heap = NULL; /* Pointer to new heap object created */
- H5HP_t *ret_value; /* Return value */
-
- FUNC_ENTER_NOAPI(NULL)
-
- /* Check args */
- HDassert(heap_type == H5HP_MIN_HEAP || heap_type == H5HP_MAX_HEAP);
-
- /* Allocate ref-counted string structure */
- if ((new_heap = H5FL_MALLOC(H5HP_t)) == NULL)
- HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "memory allocation failed");
-
- /* Allocate the array to store the heap entries */
- if ((new_heap->heap = H5FL_SEQ_MALLOC(H5HP_ent_t, (size_t)(H5HP_START_SIZE + 1))) == NULL)
- HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "memory allocation failed");
-
- /* Set the internal fields */
- new_heap->type = heap_type;
- new_heap->nobjs = 0;
- new_heap->nalloc = H5HP_START_SIZE + 1;
-
- /* Set the information in the 0'th location based on the type of heap */
- if (heap_type == H5HP_MIN_HEAP) {
- /* Set the value in the '0' location to be the minimum value, to
- * simplify the algorithms
- */
- new_heap->heap[0].val = INT_MIN;
- new_heap->heap[0].obj = NULL;
- } /* end if */
- else {
- /* Set the value in the '0' location to be the maximum value, to
- * simplify the algorithms
- */
- new_heap->heap[0].val = INT_MAX;
- new_heap->heap[0].obj = NULL;
- } /* end else */
-
- /* Set the return value */
- ret_value = new_heap;
-
-done:
- /* Error cleanup */
- if (NULL == ret_value) {
- if (NULL != new_heap) {
- if (NULL != new_heap->heap)
- new_heap->heap = H5FL_SEQ_FREE(H5HP_ent_t, new_heap->heap);
- new_heap = H5FL_FREE(H5HP_t, new_heap);
- } /* end if */
- } /* end if */
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP_create() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_count
- PURPOSE
- Check the number of elements in a heap
- USAGE
- ssize_t H5HP_count(heap)
- const H5HP_t *heap; IN: Pointer to heap to query
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Checks the number of elements in heap
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-ssize_t
-H5HP_count(const H5HP_t *heap)
-{
- ssize_t ret_value; /* Return value */
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check args */
- HDassert(heap);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- /* Return the number of objects in the heap */
- H5_CHECK_OVERFLOW(heap->nobjs, size_t, ssize_t);
- ret_value = (ssize_t)heap->nobjs;
-
- /* No post-condition check necessary, since heap is constant */
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP_count() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_insert
- PURPOSE
- Insert an object into a heap, with an initial value
- USAGE
- herr_t H5HP_insert(heap, val, obj)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- int val; IN: Initial value for object in heap
- void *obj; IN: Pointer to object to insert into heap
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Inserts a OBJ into a HEAP, with an initial VALue.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5HP_insert(H5HP_t *heap, int val, void *obj)
-{
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* Check args */
- HDassert(heap);
- HDassert(obj);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- /* Increment number of objects in heap */
- heap->nobjs++;
-
- /* Check if we need to allocate more room for heap array */
- if (heap->nobjs >= heap->nalloc) {
- size_t n = MAX(H5HP_START_SIZE, 2 * (heap->nalloc - 1)) + 1;
- H5HP_ent_t *new_heap = H5FL_SEQ_REALLOC(H5HP_ent_t, heap->heap, n);
-
- if (!new_heap)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend heap array");
- heap->heap = new_heap;
- heap->nalloc = n;
- } /* end if */
-
- /* Insert new object at end of heap */
- heap->heap[heap->nobjs].val = val;
- heap->heap[heap->nobjs].obj = (H5HP_info_t *)obj;
- heap->heap[heap->nobjs].obj->heap_loc = heap->nobjs;
-
- /* Restore heap condition */
- if (heap->type == H5HP_MAX_HEAP) {
- if (H5HP__swim_max(heap, heap->nobjs) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINSERT, FAIL, "unable to restore heap condition");
- } /* end if */
- else {
- if (H5HP__swim_min(heap, heap->nobjs) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINSERT, FAIL, "unable to restore heap condition");
- } /* end else */
-
-done:
-
- /* Check internal consistency */
- /* (Post-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP_insert() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_top
- PURPOSE
- Check the value of the top object in the heap
- USAGE
- herr_t H5HP_top(heap, val)
- const H5HP_t *heap; IN: Pointer to heap to modify
- int val; IN/OUT: Initial value for object in heap
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Checks the value of the top object in a heap
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5HP_top(const H5HP_t *heap, int *val)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check args */
- HDassert(heap);
- HDassert(val);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- /* Get value of the top object in the heap */
- *val = heap->heap[1].val;
-
- /* No post-condition check necessary, since heap is constant */
- FUNC_LEAVE_NOAPI(SUCCEED);
-} /* end H5HP_top() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_remove
- PURPOSE
- Remove an object into a heap
- USAGE
- herr_t H5HP_remove(heap, val, obj)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- int *val; OUT: Pointer to value of object removed from heap
- void **obj; OUT: Pointer to object removed from heap
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Removes the top object on a heap, returning its value and object pointer
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5HP_remove(H5HP_t *heap, int *val, void **obj)
-{
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* Check args */
- HDassert(heap);
- HDassert(val);
- HDassert(obj);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- /* Check if there are any objects on the heap to remove */
- if (heap->nobjs == 0)
- HGOTO_ERROR(H5E_HEAP, H5E_NOTFOUND, FAIL, "heap is empty");
-
- /* Get the information for the top object on the heap */
- HDassert(heap->heap[1].obj->heap_loc == 1);
- *val = heap->heap[1].val;
- *obj = heap->heap[1].obj;
-
- /* Move the last element in the heap to the top */
- heap->heap[1].val = heap->heap[heap->nobjs].val;
- heap->heap[1].obj = heap->heap[heap->nobjs].obj;
- heap->heap[1].obj->heap_loc = 1;
-
- /* Decrement number of objects in heap */
- heap->nobjs--;
-
- /* Restore heap condition, if there are objects on the heap */
- if (heap->nobjs > 0) {
- if (heap->type == H5HP_MAX_HEAP) {
- if (H5HP__sink_max(heap, (size_t)1) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTDELETE, FAIL, "unable to restore heap condition");
- } /* end if */
- else {
- if (H5HP__sink_min(heap, (size_t)1) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTDELETE, FAIL, "unable to restore heap condition");
- } /* end else */
- } /* end if */
-
-done:
-
- /* Check internal consistency */
- /* (Post-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP_remove() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_change
- PURPOSE
- Change the priority of an object on a heap
- USAGE
- herr_t H5HP_change(heap, val, obj)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- int val; IN: New priority value for object
- void *obj; IN: Pointer to object to modify
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Changes the priority of an object on a heap.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5HP_change(H5HP_t *heap, int val, void *_obj)
-{
- H5HP_info_t *obj = (H5HP_info_t *)_obj; /* Alias for object */
- size_t obj_loc; /* Location of object in heap */
- int old_val; /* Object's old priority value */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* Check args */
- HDassert(heap);
- HDassert(obj);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- /* Get the location of the object in the heap */
- obj_loc = obj->heap_loc;
- HDassert(obj_loc > 0 && obj_loc <= heap->nobjs);
-
- /* Change the heap object's priority */
- old_val = heap->heap[obj_loc].val;
- heap->heap[obj_loc].val = val;
-
- /* Restore heap condition */
- if (val < old_val) {
- if (heap->type == H5HP_MAX_HEAP) {
- if (H5HP__sink_max(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition");
- } /* end if */
- else {
- if (H5HP__swim_min(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition");
- } /* end else */
- } /* end if */
- else {
- if (heap->type == H5HP_MAX_HEAP) {
- if (H5HP__swim_max(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition");
- } /* end if */
- else {
- if (H5HP__sink_min(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition");
- } /* end else */
- } /* end else */
-
-done:
-
- /* Check internal consistency */
- /* (Post-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP_change() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_incr
- PURPOSE
- Increment the priority of an object on a heap
- USAGE
- herr_t H5HP_incr(heap, amt, obj)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- unsigned amt; IN: Amount to increase priority by
- void *obj; IN: Pointer to object to modify
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Increments the priority of an object on a heap by one.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5HP_incr(H5HP_t *heap, unsigned amt, void *_obj)
-{
- H5HP_info_t *obj = (H5HP_info_t *)_obj; /* Alias for object */
- size_t obj_loc; /* Location of object in heap */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* Check args */
- HDassert(heap);
- HDassert(obj);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- /* Get the location of the object in the heap */
- obj_loc = obj->heap_loc;
- HDassert(obj_loc > 0 && obj_loc <= heap->nobjs);
-
- /* Change the heap object's priority */
- heap->heap[obj_loc].val += (int)amt;
-
- /* Restore heap condition */
- if (H5HP_MAX_HEAP == heap->type) {
- if (H5HP__swim_max(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition")
- } /* end if */
- else {
- if (H5HP__sink_min(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition")
- } /* end else */
-
-done:
-
- /* Check internal consistency */
- /* (Post-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP_incr() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_decr
- PURPOSE
- Decrement the priority of an object on a heap
- USAGE
- herr_t H5HP_dec(heap, amt, obj)
- H5HP_t *heap; IN/OUT: Pointer to heap to modify
- unsigned amt; IN: Amount to decrease priority by
- void *obj; IN: Pointer to object to modify
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Decrements the priority of an object on a heap by one.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5HP_decr(H5HP_t *heap, unsigned amt, void *_obj)
-{
- H5HP_info_t *obj = (H5HP_info_t *)_obj; /* Alias for object */
- size_t obj_loc; /* Location of object in heap */
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* Check args */
- HDassert(heap);
- HDassert(obj);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- /* Get the location of the object in the heap */
- obj_loc = obj->heap_loc;
- HDassert(obj_loc > 0 && obj_loc <= heap->nobjs);
-
- /* Change the heap object's priority */
- H5_CHECK_OVERFLOW(amt, unsigned, int);
- heap->heap[obj_loc].val -= (int)amt;
-
- /* Restore heap condition */
- if (heap->type == H5HP_MAX_HEAP) {
- if (H5HP__sink_max(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition");
- } /* end if */
- else {
- if (H5HP__swim_min(heap, obj_loc) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTRESTORE, FAIL, "unable to restore heap condition");
- } /* end else */
-
-done:
-
- /* Check internal consistency */
- /* (Post-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(heap->heap[0].obj == NULL);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5HP_decr() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5HP_close
- PURPOSE
- Close a heap, deallocating it.
- USAGE
- herr_t H5HP_close(heap)
- H5HP_t *heap; IN/OUT: Pointer to heap to close
-
- RETURNS
- Returns non-negative on success, negative on failure.
- DESCRIPTION
- Close a heap, freeing all internal information. Any objects left in
- the heap are not deallocated.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-herr_t
-H5HP_close(H5HP_t *heap)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check args */
- HDassert(heap);
-
- /* Check internal consistency */
- /* (Pre-condition) */
- HDassert(heap->nobjs < heap->nalloc);
- HDassert(heap->heap);
- HDassert((heap->type == H5HP_MAX_HEAP && heap->heap[0].val == INT_MAX) ||
- (heap->type == H5HP_MIN_HEAP && heap->heap[0].val == INT_MIN));
- HDassert(NULL == heap->heap[0].obj);
-
- /* Free internal structures for heap */
- heap->heap = H5FL_SEQ_FREE(H5HP_ent_t, heap->heap);
-
- /* Free actual heap object */
- heap = H5FL_FREE(H5HP_t, heap);
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5HP_close() */
diff --git a/src/H5HPprivate.h b/src/H5HPprivate.h
deleted file mode 100644
index 50020bc..0000000
--- a/src/H5HPprivate.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://www.hdfgroup.org/licenses. *
- * If you do not have access to either file, you may request a copy from *
- * help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*
- * This file contains private information about the H5HP module
- */
-#ifndef H5HPprivate_H
-#define H5HPprivate_H
-
-/**************************************/
-/* Public headers needed by this file */
-/**************************************/
-#ifdef LATER
-#include "H5HPpublic.h"
-#endif /* LATER */
-
-/***************************************/
-/* Private headers needed by this file */
-/***************************************/
-#include "H5private.h"
-
-/************/
-/* Typedefs */
-/************/
-
-/* Typedef for heap struct (defined in H5HP.c) */
-typedef struct H5HP_t H5HP_t;
-
-/* Typedef for objects which can be inserted into heaps */
-/* This _must_ be the first field in objects which can be inserted into heaps */
-typedef struct H5HP_info_t {
- size_t heap_loc; /* Location of object in heap */
-} H5HP_info_t;
-
-/* Typedef for type of heap to create */
-typedef enum {
- H5HP_MIN_HEAP, /* Minimum values in heap are at the "top" */
- H5HP_MAX_HEAP /* Maximum values in heap are at the "top" */
-} H5HP_type_t;
-
-/**********/
-/* Macros */
-/**********/
-
-/********************/
-/* Private routines */
-/********************/
-H5_DLL H5HP_t *H5HP_create(H5HP_type_t heap_type);
-H5_DLL herr_t H5HP_insert(H5HP_t *heap, int val, void *obj);
-H5_DLL ssize_t H5HP_count(const H5HP_t *heap);
-H5_DLL herr_t H5HP_top(const H5HP_t *heap, int *val);
-H5_DLL herr_t H5HP_remove(H5HP_t *heap, int *val, void **ptr);
-H5_DLL herr_t H5HP_change(H5HP_t *heap, int val, void *obj);
-H5_DLL herr_t H5HP_incr(H5HP_t *heap, unsigned amt, void *obj);
-H5_DLL herr_t H5HP_decr(H5HP_t *heap, unsigned amt, void *obj);
-H5_DLL herr_t H5HP_close(H5HP_t *heap);
-
-#endif /* H5HPprivate_H */
diff --git a/src/H5MP.c b/src/H5MP.c
deleted file mode 100644
index 474a995..0000000
--- a/src/H5MP.c
+++ /dev/null
@@ -1,446 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://www.hdfgroup.org/licenses. *
- * If you do not have access to either file, you may request a copy from *
- * help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*-------------------------------------------------------------------------
- *
- * Created: H5MP.c
- * May 2 2005
- * Quincey Koziol
- *
- * Purpose: Implements memory pools. (Similar to Apache's APR
- * memory pools)
- *
- * Please see the documentation in:
- * doc/html/TechNotes/MemoryPools.html for a full description
- * of how they work, etc.
- *
- *-------------------------------------------------------------------------
- */
-
-#include "H5MPmodule.h" /* This source code file is part of the H5MP module */
-
-/* Private headers */
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5MMprivate.h" /* Memory management */
-#include "H5MPpkg.h" /* Memory Pools */
-
-/****************/
-/* Local Macros */
-/****************/
-
-/* Minimum sized block */
-#define H5MP_MIN_BLOCK (H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGNMENT)
-
-/* First block in page */
-#define H5MP_PAGE_FIRST_BLOCK(p) \
- (H5MP_page_blk_t *)((void *)((unsigned char *)(p) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
-
-/******************/
-/* Local Typedefs */
-/******************/
-
-/********************/
-/* Local Prototypes */
-/********************/
-
-/********************************/
-/* Package Variable Definitions */
-/********************************/
-
-/* Package initialization variable */
-hbool_t H5_PKG_INIT_VAR = FALSE;
-
-/********************/
-/* Static Variables */
-/********************/
-
-/* Declare a free list to manage the H5MP_pool_t struct */
-H5FL_DEFINE(H5MP_pool_t);
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_create
- *
- * Purpose: Create a new memory pool
- *
- * Return: Pointer to the memory pool "header" on success/NULL on failure
- *
- * Programmer: Quincey Koziol
- * May 2 2005
- *
- *-------------------------------------------------------------------------
- */
-H5MP_pool_t *
-H5MP_create(size_t page_size, unsigned flags)
-{
- H5MP_pool_t *mp = NULL; /* New memory pool header */
- H5MP_pool_t *ret_value = NULL; /* Return value */
-
- FUNC_ENTER_NOAPI(NULL)
-
- /* Allocate space for the pool header */
- if (NULL == (mp = H5FL_MALLOC(H5MP_pool_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for memory pool header")
-
- /* Assign information */
- mp->page_size = H5MP_BLOCK_ALIGN(page_size);
- mp->flags = flags;
-
- /* Initialize information */
- mp->free_size = 0;
- mp->first = NULL;
- mp->max_size = mp->page_size - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t));
-
- /* Create factory for pool pages */
- if (NULL == (mp->page_fac = H5FL_fac_init(page_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't create page factory")
-
- /* Set return value */
- ret_value = mp;
-
-done:
- if (NULL == ret_value && mp)
- if (H5MP_close(mp) < 0)
- HDONE_ERROR(H5E_RESOURCE, H5E_CANTFREE, NULL, "unable to free memory pool header")
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5MP_create() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP__new_page
- *
- * Purpose: Allocate new page for a memory pool
- *
- * Return: Pointer to the page allocated on success/NULL on failure
- *
- * Programmer: Quincey Koziol
- * May 4 2005
- *
- *-------------------------------------------------------------------------
- */
-static H5MP_page_t *
-H5MP__new_page(H5MP_pool_t *mp, size_t page_size)
-{
- H5MP_page_t * new_page; /* New page created */
- H5MP_page_blk_t *first_blk; /* Pointer to first block in page */
- H5MP_page_t * ret_value = NULL; /* Return value */
-
- FUNC_ENTER_STATIC
-
- /* Sanity check */
- HDassert(mp);
- HDassert(page_size >= mp->page_size);
-
- /* Allocate page */
- if (page_size > mp->page_size) {
- if (NULL == (new_page = (H5MP_page_t *)H5MM_malloc(page_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for page")
- new_page->free_size = page_size - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t));
- new_page->fac_alloc = FALSE;
- } /* end if */
- else {
- if (NULL == (new_page = (H5MP_page_t *)H5FL_FAC_MALLOC(mp->page_fac)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for page")
- new_page->free_size = mp->max_size;
- new_page->fac_alloc = TRUE;
- } /* end else */
-
- /* Initialize page information */
- first_blk = H5MP_PAGE_FIRST_BLOCK(new_page);
- first_blk->size = new_page->free_size;
- first_blk->page = new_page;
- first_blk->is_free = TRUE;
- first_blk->prev = NULL;
- first_blk->next = NULL;
-
- /* Insert into page list */
- new_page->prev = NULL;
- new_page->next = mp->first;
- if (mp->first)
- mp->first->prev = new_page;
- mp->first = new_page;
-
- /* Account for new free space */
- new_page->free_blk = first_blk;
- mp->free_size += new_page->free_size;
-
- /* Assign return value */
- ret_value = new_page;
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5MP__new_page() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_malloc
- *
- * Purpose: Allocate space in a memory pool
- *
- * Return: Pointer to the space allocated on success/NULL on failure
- *
- * Programmer: Quincey Koziol
- * May 2 2005
- *
- *-------------------------------------------------------------------------
- */
-void *
-H5MP_malloc(H5MP_pool_t *mp, size_t request)
-{
- H5MP_page_t * alloc_page = NULL; /* Page to allocate space from */
- H5MP_page_blk_t *alloc_free; /* Pointer to free space in page */
- size_t needed; /* Size requested, plus block header and alignment */
- void * ret_value = NULL; /* Return value */
-
- FUNC_ENTER_NOAPI(NULL)
-
- /* Sanity check */
- HDassert(mp);
- HDassert(request > 0);
-
- /* Compute actual size needed */
- needed = H5MP_BLOCK_ALIGN(request) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t));
-
- /* See if the request can be handled by existing free space */
- if (needed <= mp->free_size) {
- size_t pool_free_avail; /* Amount of free space possibly available in pool */
-
- /* Locate page with enough free space */
- alloc_page = mp->first;
- pool_free_avail = mp->free_size;
- while (alloc_page && pool_free_avail >= needed) {
- /* If we found a page with enough free space, search for large
- * enough free block on that page */
- if (alloc_page->free_size >= needed) {
- size_t page_free_avail; /* Amount of free space possibly available */
-
- /* Locate large enough block */
- alloc_free = alloc_page->free_blk;
- page_free_avail = alloc_page->free_size;
- while (alloc_free && page_free_avail >= needed) {
- if (alloc_free->is_free) {
- /* If we found a large enough block, leave now */
- if (alloc_free->size >= needed)
- goto found; /* Needed to escape double "while" loop */
-
- /* Decrement amount of potential space left */
- page_free_avail -= alloc_free->size;
- } /* end if */
-
- /* Go to next block */
- alloc_free = alloc_free->next;
- } /* end while */
- } /* end if */
-
- /* Decrement amount of potential space left */
- pool_free_avail -= alloc_page->free_size;
-
- /* Go to next page */
- alloc_page = alloc_page->next;
- } /* end while */
- } /* end if */
-
- {
- size_t page_size; /* Size of page needed */
-
- /* Check if the request is too large for a standard page */
- page_size =
- (needed > mp->max_size) ? (needed + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) : mp->page_size;
-
- /* Allocate new page */
- if (NULL == (alloc_page = H5MP__new_page(mp, page_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for page")
-
- /* Set the block to allocate from */
- alloc_free = alloc_page->free_blk;
- } /* end block */
-
- /* Allocate space in page */
-found:
-
- /* Sanity check */
- HDassert(alloc_page);
- HDassert(alloc_free);
-
- /* Check if we can subdivide the free space */
- if (alloc_free->size > (needed + H5MP_MIN_BLOCK)) {
- H5MP_page_blk_t *new_free; /* New free block created */
-
- /* Carve out new free block after block to allocate */
- new_free = (H5MP_page_blk_t *)((void *)(((unsigned char *)alloc_free) + needed));
-
- /* Link into existing lists */
- new_free->next = alloc_free->next;
- if (alloc_free->next)
- alloc_free->next->prev = new_free;
- new_free->prev = alloc_free;
- alloc_free->next = new_free;
-
- /* Set blocks' information */
- new_free->size = alloc_free->size - needed;
- new_free->is_free = TRUE;
- new_free->page = alloc_free->page;
- alloc_free->size = needed;
- alloc_free->is_free = FALSE;
- } /* end if */
- else {
- /* Use whole free space block for new block */
- alloc_free->is_free = FALSE;
- } /* end else */
-
- /* Update page & pool's free size information */
- alloc_page->free_size -= alloc_free->size;
- if (alloc_page->free_blk == alloc_free)
- alloc_page->free_blk = alloc_free->next;
- mp->free_size -= alloc_free->size;
-
- /* Set new space pointer for the return value */
- ret_value = ((unsigned char *)alloc_free) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t));
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5MP_malloc() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_free
- *
- * Purpose: Release space in a memory pool
- *
- * Return: NULL on success/NULL on failure
- *
- * Programmer: Quincey Koziol
- * May 3 2005
- *
- * Note: Should we release pages that have no used blocks?
- *
- *-------------------------------------------------------------------------
- */
-void *
-H5MP_free(H5MP_pool_t *mp, void *spc)
-{
- H5MP_page_blk_t *spc_blk; /* Block for space to free */
- H5MP_page_t * spc_page; /* Page containing block to free */
- void * ret_value = NULL; /* Return value */
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Sanity check */
- HDassert(mp);
- HDassert(spc);
-
- /* Get block header for space to free */
- spc_blk =
- (H5MP_page_blk_t *)((void *)(((unsigned char *)spc) - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))));
-
- /* Mark block as free */
- HDassert(spc_blk->is_free == FALSE);
- spc_blk->is_free = TRUE;
-
- /* Add it's space to the amount of free space in the page & pool */
- spc_page = spc_blk->page;
- spc_page->free_size += spc_blk->size;
- mp->free_size += spc_blk->size;
-
- /* Move page with newly freed space to front of list of pages in pool */
- if (spc_page != mp->first) {
- /* Remove page from list */
- spc_page->prev->next = spc_page->next;
- if (spc_page->next)
- spc_page->next->prev = spc_page->prev;
-
- /* Insert page at beginning of list */
- spc_page->prev = NULL;
- spc_page->next = mp->first;
- mp->first->prev = spc_page;
- mp->first = spc_page;
- } /* end if */
-
- /* Check if block can be merged with free space after it on page */
- if (spc_blk->next != NULL) {
- H5MP_page_blk_t *next_blk; /* Block following space to free */
-
- next_blk = spc_blk->next;
- HDassert(next_blk->prev == spc_blk);
- if (next_blk->is_free) {
- spc_blk->size += next_blk->size;
- spc_blk->next = next_blk->next;
- } /* end if */
- } /* end if */
-
- /* Check if block can be merged with free space before it on page */
- if (spc_blk->prev != NULL) {
- H5MP_page_blk_t *prev_blk; /* Block before space to free */
-
- prev_blk = spc_blk->prev;
- HDassert(prev_blk->next == spc_blk);
- if (prev_blk->is_free) {
- prev_blk->size += spc_blk->size;
- prev_blk->next = spc_blk->next;
- } /* end if */
- } /* end if */
-
- /* Check if the block freed becomes the first free block on the page */
- if (spc_page->free_blk == NULL || spc_blk < spc_page->free_blk)
- spc_page->free_blk = spc_blk;
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5MP_free() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_close
- *
- * Purpose: Release all memory for a pool and destroy pool
- *
- * Return: Non-negative on success/negative on failure
- *
- * Programmer: Quincey Koziol
- * May 3 2005
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5MP_close(H5MP_pool_t *mp)
-{
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* Release memory for pool pages */
- if (mp->first != NULL) {
- H5MP_page_t *page, *next_page; /* Pointer to pages in pool */
-
- /* Iterate through pages, releasing them */
- page = mp->first;
- while (page) {
- next_page = page->next;
-
- /* Free the page appropriately */
- if (page->fac_alloc)
- page = (H5MP_page_t *)H5FL_FAC_FREE(mp->page_fac, page);
- else
- page = (H5MP_page_t *)H5MM_xfree(page);
-
- page = next_page;
- } /* end while */
- } /* end if */
-
- /* Release page factory */
- if (mp->page_fac)
- if (H5FL_fac_term(mp->page_fac) < 0)
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTRELEASE, FAIL, "can't destroy page factory")
-
-done:
- /* Free the memory pool itself */
- mp = H5FL_FREE(H5MP_pool_t, mp);
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5MP_close() */
diff --git a/src/H5MPmodule.h b/src/H5MPmodule.h
deleted file mode 100644
index 8e34598..0000000
--- a/src/H5MPmodule.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * 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. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*
- * Programmer: Quincey Koziol
- * Saturday, September 12, 2015
- *
- * Purpose: This file contains declarations which define macros for the
- * H5MP package. Including this header means that the source file
- * is part of the H5MP package.
- */
-#ifndef H5MPmodule_H
-#define H5MPmodule_H
-
-/* Define the proper control macros for the generic FUNC_ENTER/LEAVE and error
- * reporting macros.
- */
-#define H5MP_MODULE
-#define H5_MY_PKG H5MP
-#define H5_MY_PKG_ERR H5E_RESOURCE
-#define H5_MY_PKG_INIT NO
-
-#endif /* H5MPmodule_H */
diff --git a/src/H5MPpkg.h b/src/H5MPpkg.h
deleted file mode 100644
index 64c5293..0000000
--- a/src/H5MPpkg.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://www.hdfgroup.org/licenses. *
- * If you do not have access to either file, you may request a copy from *
- * help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*
- * Programmer: Quincey Koziol
- * Monday, May 2, 2005
- *
- * Purpose: This file contains declarations which are visible only within
- * the H5MP package. Source files outside the H5MP package should
- * include H5MPprivate.h instead.
- */
-#if !(defined H5MP_FRIEND || defined H5MP_MODULE)
-#error "Do not include this file outside the H5MP package!"
-#endif
-
-#ifndef H5MPpkg_H
-#define H5MPpkg_H
-
-/* Get package's private header */
-#include "H5MPprivate.h" /* Memory Pools */
-
-/* Other private headers needed by this file */
-#include "H5FLprivate.h" /* Free Lists */
-
-/**************************/
-/* Package Private Macros */
-/**************************/
-
-/* Alignment macros */
-/* (Ideas from Apache APR :-) */
-
-/* Default alignment necessary */
-#define H5MP_BLOCK_ALIGNMENT 8
-
-/* General alignment macro */
-/* (this only works for aligning to power of 2 boundary) */
-#define H5MP_ALIGN(x, a) (((x) + ((size_t)(a)) - 1) & ~(((size_t)(a)) - 1))
-
-/* Default alignment */
-#define H5MP_BLOCK_ALIGN(x) H5MP_ALIGN(x, H5MP_BLOCK_ALIGNMENT)
-
-/****************************/
-/* Package Private Typedefs */
-/****************************/
-
-/* Free block in pool */
-typedef struct H5MP_page_blk_t {
- size_t size; /* Size of block (includes this H5MP_page_blk_t info) */
- unsigned is_free : 1; /* Flag to indicate the block is free */
- struct H5MP_page_t * page; /* Pointer to page block is located in */
- struct H5MP_page_blk_t *prev; /* Pointer to previous block in page */
- struct H5MP_page_blk_t *next; /* Pointer to next block in page */
-} H5MP_page_blk_t;
-
-/* Memory pool page */
-typedef struct H5MP_page_t {
- size_t free_size; /* Total amount of free space in page */
- unsigned fac_alloc : 1; /* Flag to indicate the page was allocated by the pool's factory */
- H5MP_page_blk_t * free_blk; /* Pointer to first free block in page */
- struct H5MP_page_t *next; /* Pointer to next page in pool */
- struct H5MP_page_t *prev; /* Pointer to previous page in pool */
-} H5MP_page_t;
-
-/* Memory pool header */
-struct H5MP_pool_t {
- H5FL_fac_head_t *page_fac; /* Free-list factory for pages */
- size_t page_size; /* Page size for pool */
- size_t free_size; /* Total amount of free space in pool */
- size_t max_size; /* Maximum block that will fit in a standard page */
- H5MP_page_t * first; /* Pointer to first page in pool */
- unsigned flags; /* Bit flags for pool settings */
-};
-
-/*****************************************/
-/* Package Private Variable Declarations */
-/*****************************************/
-
-/******************************/
-/* Package Private Prototypes */
-/******************************/
-#ifdef H5MP_TESTING
-H5_DLL herr_t H5MP_get_pool_free_size(const H5MP_pool_t *mp, size_t *free_size);
-H5_DLL htri_t H5MP_pool_is_free_size_correct(const H5MP_pool_t *mp);
-H5_DLL herr_t H5MP_get_pool_first_page(const H5MP_pool_t *mp, H5MP_page_t **page);
-H5_DLL herr_t H5MP_get_page_free_size(const H5MP_page_t *mp, size_t *page);
-H5_DLL herr_t H5MP_get_page_next_page(const H5MP_page_t *page, H5MP_page_t **next_page);
-#endif /* H5MP_TESTING */
-
-#endif /* H5MPpkg_H */
diff --git a/src/H5MPprivate.h b/src/H5MPprivate.h
deleted file mode 100644
index 2b06650..0000000
--- a/src/H5MPprivate.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://www.hdfgroup.org/licenses. *
- * If you do not have access to either file, you may request a copy from *
- * help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/*-------------------------------------------------------------------------
- *
- * Created: H5MPprivate.h
- * May 2 2005
- * Quincey Koziol
- *
- * Purpose: Private header for memory pool routines.
- *
- *-------------------------------------------------------------------------
- */
-
-#ifndef H5MPprivate_H
-#define H5MPprivate_H
-
-/* Include package's public header (not yet) */
-/* #include "H5MPpublic.h" */
-
-/* Private headers needed by this file */
-
-/**************************/
-/* Library Private Macros */
-/**************************/
-
-/* Pool creation flags */
-/* Default settings */
-#define H5MP_FLG_DEFAULT 0
-#define H5MP_PAGE_SIZE_DEFAULT 4096 /* (bytes) */
-
-/****************************/
-/* Library Private Typedefs */
-/****************************/
-
-/* Memory pool header (defined in H5MPpkg.c) */
-typedef struct H5MP_pool_t H5MP_pool_t;
-
-/***************************************/
-/* Library-private Function Prototypes */
-/***************************************/
-H5_DLL H5MP_pool_t *H5MP_create(size_t page_size, unsigned flags);
-H5_DLL void * H5MP_malloc(H5MP_pool_t *mp, size_t request);
-H5_DLL void * H5MP_free(H5MP_pool_t *mp, void *spc);
-H5_DLL herr_t H5MP_close(H5MP_pool_t *mp);
-
-#endif /* H5MPprivate_H */
diff --git a/src/H5MPtest.c b/src/H5MPtest.c
deleted file mode 100644
index 27e7bbe..0000000
--- a/src/H5MPtest.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the COPYING file, which can be found at the root of the source code *
- * distribution tree, or in https://www.hdfgroup.org/licenses. *
- * If you do not have access to either file, you may request a copy from *
- * help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-/* Programmer: Quincey Koziol
- * Tuesday, May 3, 2005
- *
- * Purpose: Memory pool testing functions.
- */
-
-#include "H5MPmodule.h" /* This source code file is part of the H5MP module */
-#define H5MP_TESTING /*include H5MP testing funcs*/
-
-/* Private headers */
-#include "H5private.h" /* Generic Functions */
-#include "H5MPpkg.h" /* Memory Pools */
-#include "H5Eprivate.h" /* Error handling */
-
-/* Static Prototypes */
-
-/* Package variables */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_get_pool_free_size
- *
- * Purpose: Retrieve the total amount of free space in entire pool
- *
- * Return: Success: non-negative
- *
- * Failure: negative
- *
- * Programmer: Quincey Koziol
- * Tuesday, May 3, 2005
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5MP_get_pool_free_size(const H5MP_pool_t *mp, size_t *free_size)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check arguments. */
- HDassert(mp);
- HDassert(free_size);
-
- /* Get memory pool's free space */
- *free_size = mp->free_size;
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* H5MP_get_pool_free_size() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_get_pool_first_page
- *
- * Purpose: Retrieve the first page in a memory pool
- *
- * Return: Success: non-negative
- *
- * Failure: negative
- *
- * Programmer: Quincey Koziol
- * Tuesday, May 3, 2005
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5MP_get_pool_first_page(const H5MP_pool_t *mp, H5MP_page_t **page)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check arguments. */
- HDassert(mp);
- HDassert(page);
-
- /* Get memory pool's first page */
- *page = mp->first;
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* H5MP_get_pool_first_page() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_pool_is_free_size_correct
- *
- * Purpose: Check that the free space reported in each page corresponds
- * to the free size in each page and that the free space in the
- * free blocks for a page corresponds with the free space for
- * the page.
- *
- * Return: Success: non-negative
- *
- * Failure: negative
- *
- * Programmer: Quincey Koziol
- * Wednesday, May 3, 2005
- *
- *-------------------------------------------------------------------------
- */
-htri_t
-H5MP_pool_is_free_size_correct(const H5MP_pool_t *mp)
-{
- H5MP_page_t *page; /* Pointer to current page */
- size_t pool_free; /* Size of pages' free space */
- htri_t ret_value = TRUE; /* Return value */
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check arguments. */
- HDassert(mp);
-
- /* Iterate through pages, checking the free size & accumulating the
- * free space for all the pages */
- page = mp->first;
- pool_free = 0;
- while (page != NULL) {
- H5MP_page_blk_t *blk; /* Pointer to current free block */
- size_t page_free; /* Size of blocks on free list */
-
- /* Iterate through the blocks in page, accumulating free space */
- blk = (H5MP_page_blk_t *)((void *)((unsigned char *)page + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))));
- page_free = 0;
- while (blk != NULL) {
- if (blk->is_free)
- page_free += blk->size;
- blk = blk->next;
- } /* end while */
-
- /* Check that the free space from the blocks on the free list
- * corresponds to space in page */
- if (page_free != page->free_size)
- HGOTO_DONE(FALSE)
-
- /* Increment the amount of free space in pool */
- pool_free += page->free_size;
-
- /* Advance to next page */
- page = page->next;
- } /* end while */
-
- /* Check that the free space from the pages
- * corresponds to free space in pool */
- if (pool_free != mp->free_size)
- HGOTO_DONE(FALSE)
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* H5MP_pool_is_free_size_correct() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_get_page_free_size
- *
- * Purpose: Retrieve the amount of free space in given page
- *
- * Return: Success: non-negative
- *
- * Failure: negative
- *
- * Programmer: Quincey Koziol
- * Tuesday, May 3, 2005
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5MP_get_page_free_size(const H5MP_page_t *page, size_t *free_size)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check arguments. */
- HDassert(page);
- HDassert(free_size);
-
- /* Get memory page's free space */
- *free_size = page->free_size;
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* H5MP_get_page_free_size() */
-
-/*-------------------------------------------------------------------------
- * Function: H5MP_get_page_next_page
- *
- * Purpose: Retrieve the next page in the pool
- *
- * Return: Success: non-negative
- *
- * Failure: negative
- *
- * Programmer: Quincey Koziol
- * Tuesday, May 3, 2005
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5MP_get_page_next_page(const H5MP_page_t *page, H5MP_page_t **next_page)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
- /* Check arguments. */
- HDassert(page);
- HDassert(next_page);
-
- /* Get next memory page */
- *next_page = page->next;
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* H5MP_get_page_next_page() */
diff --git a/src/H5SL.c b/src/H5SL.c
index 1a2ef22..ab07a07 100644
--- a/src/H5SL.c
+++ b/src/H5SL.c
@@ -36,13 +36,6 @@
* skip list. The implementation in that document hurts
* performance, at least for integer keys. -NAF)
*
- * (Also, this implementation has a couple of home-grown
- * optimizations, including setting the "update" vector to the
- * actual 'forward' pointer to update, instead of the node
- * containing the forward pointer -QAK
- * -No longer uses update vector, as insertions/deletions are now
- * always at level 0. -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",
@@ -71,25 +64,14 @@
/* 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 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 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 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)
@@ -155,51 +137,19 @@
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 */ \
+ } \
}
/* 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) \
+ 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
@@ -209,7 +159,7 @@
/* 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); \
+ HDassert(LVL + 1 == 1U << X->log_nalloc); \
/* Double the amount of allocated space */ \
X->log_nalloc++; \
\
@@ -225,13 +175,13 @@
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]))) \
@@ -239,7 +189,7 @@
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++; \
}
@@ -251,7 +201,7 @@
/* 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)); \
+ HDassert(LVL == 1U << (X->log_nalloc - 1)); \
X->log_nalloc--; \
\
/* Allocate space for new forward pointers */ \
@@ -260,7 +210,7 @@
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--; \
}
@@ -284,7 +234,7 @@
else { \
HDassert(_lvl < (size_t)SLIST->curr_level); \
X->forward[_lvl + 1] = PREV->forward[_lvl + 1]; \
- } /* end else */ \
+ } \
PREV->forward[_lvl + 1] = X; \
}
@@ -322,7 +272,7 @@
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)) \
@@ -337,7 +287,7 @@
break; \
} \
X = X->forward[_i]; \
- } /* end for */ \
+ } \
HDassert(!_drop->forward[_i] || \
!H5_GLUE3(H5SL_LOCATE_, CMP, _CMP)(SLIST, TYPE, _drop->forward[_i], KEY, HASHVAL)); \
\
@@ -350,7 +300,7 @@
/* 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") \
@@ -359,172 +309,167 @@
/* 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 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; \
+ 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); \
+ if (_i < 0) \
+ HGOTO_DONE(NULL); \
\
- H5_GLUE3(H5SL_LOCATE_, CMP, _HASHINIT) \
- (KEY, HASHVAL) \
+ 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; \
+ /* 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 */ \
+ /* 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; \
+ /* 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 { /* !_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 */ \
+ 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; \
- } /* 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)); \
+ /* 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]; \
+ /* 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) \
+ /* 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); \
+ /* 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 */ \
+ 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); \
+ } \
+ 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) \
+ /* 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); \
+ /* 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 */ \
+ H5SL_SHRINK(_head, (size_t)(_i + 1)) \
+ SLIST->curr_level--; \
+ } \
+ } \
+ } \
\
- /* Prepare to drop down */ \
- _llast = _ldrop; \
- _last = _drop; \
- _next = _drop->forward[_i]; \
- } /* end for */ \
+ /* 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; \
+ /* 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); \
+ /* 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); \
+ /* 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 */ \
+ HGOTO_DONE(tmp); \
+ } \
}
/* Macro used to search for node */
@@ -542,7 +487,6 @@ struct H5SL_node_t {
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 */
};
@@ -558,8 +502,6 @@ struct H5SL_t {
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 */
@@ -651,11 +593,11 @@ H5SL_term_package(void)
for (i = 0; i < H5SL_fac_nused_g; i++) {
ret = H5FL_fac_term(H5SL_fac_g[i]);
HDassert(ret >= 0);
- } /* end if */
+ }
H5SL_fac_nused_g = 0;
n++;
- } /* end if */
+ }
/* Free the list of factories */
if (H5SL_fac_g) {
@@ -663,12 +605,12 @@ H5SL_term_package(void)
H5SL_fac_nalloc_g = 0;
n++;
- } /* end if */
+ }
/* Mark the interface as uninitialized */
if (0 == n)
H5_PKG_INIT_VAR = FALSE;
- } /* end if */
+ }
FUNC_LEAVE_NOAPI(n)
} /* H5SL_term_package() */
@@ -711,11 +653,10 @@ H5SL__new_node(void *item, const void *key, uint32_t hashval)
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]))) {
ret_value = H5FL_FREE(H5SL_node_t, ret_value);
HGOTO_ERROR(H5E_SLIST, H5E_NOSPACE, NULL, "memory allocation failed")
- } /* end if */
+ }
ret_value->log_nalloc = 0;
done:
@@ -805,7 +746,7 @@ H5SL__insert_common(H5SL_t *slist, void *item, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
/* 'key' must not have been found in existing list, if we get here */
@@ -880,15 +821,22 @@ H5SL__release_common(H5SL_t *slist, H5SL_operator_t op, void *op_data)
while (node) {
next_node = node->forward[0];
- /* Call callback, if one is given */
+ /* 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)
- /* Casting away const OK -QAK */
(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;
- } /* end while */
+ }
/* Reset the header pointers */
slist->header->forward =
@@ -1001,9 +949,8 @@ 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->safe_iterating = FALSE;
+ 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)))
@@ -1027,7 +974,7 @@ done:
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() */
@@ -1058,9 +1005,6 @@ H5SL_count(H5SL_t *slist)
/* Check args */
HDassert(slist);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -1099,9 +1043,6 @@ H5SL_insert(H5SL_t *slist, void *item, const void *key)
HDassert(slist);
HDassert(key);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -1148,9 +1089,6 @@ H5SL_add(H5SL_t *slist, void *item, const void *key)
HDassert(slist);
HDassert(key);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -1242,7 +1180,7 @@ H5SL_remove(H5SL_t *slist, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -1281,9 +1219,6 @@ H5SL_remove_first(H5SL_t *slist)
/* Check args */
HDassert(slist);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Assign level */
H5_CHECK_OVERFLOW(slist->curr_level, int, size_t);
level = (size_t)slist->curr_level;
@@ -1345,12 +1280,12 @@ H5SL_remove_first(H5SL_t *slist)
H5SL_SHRINK(head, level)
slist->curr_level--;
- } /* end else */
+ }
}
else
break;
- } /* end for */
- } /* end if */
+ }
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -1436,7 +1371,7 @@ H5SL_search(H5SL_t *slist, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
/* 'key' must not have been found in list, if we get here */
ret_value = NULL;
@@ -1480,9 +1415,6 @@ H5SL_less(H5SL_t *slist, const void *key)
HDassert(slist);
HDassert(key);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -1531,7 +1463,7 @@ H5SL_less(H5SL_t *slist, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
/* 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' */
@@ -1541,13 +1473,13 @@ H5SL_less(H5SL_t *slist, const void *key)
ret_value = slist->last->item;
else
ret_value = NULL;
- } /* end if */
+ }
else {
if (x->backward != slist->header)
ret_value = x->backward->item;
else
ret_value = NULL;
- } /* end else */
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -1588,9 +1520,6 @@ H5SL_greater(H5SL_t *slist, const void *key)
HDassert(slist);
HDassert(key);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -1639,7 +1568,7 @@ H5SL_greater(H5SL_t *slist, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
/* 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) */
@@ -1734,7 +1663,7 @@ H5SL_find(H5SL_t *slist, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
/* 'key' must not have been found in list, if we get here */
ret_value = NULL;
@@ -1826,7 +1755,7 @@ H5SL_below(H5SL_t *slist, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
/* 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' */
@@ -1836,13 +1765,13 @@ H5SL_below(H5SL_t *slist, const void *key)
ret_value = slist->last;
else
ret_value = NULL;
- } /* end if */
+ }
else {
if (x->backward != slist->header)
ret_value = x->backward;
else
ret_value = NULL;
- } /* end else */
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -1931,7 +1860,7 @@ H5SL_above(H5SL_t *slist, const void *key)
default:
HDassert(0 && "Unknown skiplist type!");
- } /* end switch */
+ }
/* 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) */
@@ -1971,9 +1900,6 @@ H5SL_first(H5SL_t *slist)
/* Check args */
HDassert(slist);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -2007,9 +1933,6 @@ H5SL_next(H5SL_node_t *slist_node)
/* Check args */
HDassert(slist_node);
- /* Not currently supported */
- HDassert(!slist_node->removed);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -2043,9 +1966,6 @@ H5SL_prev(H5SL_node_t *slist_node)
/* Check args */
HDassert(slist_node);
- /* Not currently supported */
- HDassert(!slist_node->removed);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -2080,9 +2000,6 @@ H5SL_last(H5SL_t *slist)
/* Check args */
HDassert(slist);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -2116,9 +2033,6 @@ H5SL_item(H5SL_node_t *slist_node)
/* Check args */
HDassert(slist_node);
- /* Not currently supported */
- HDassert(!slist_node->removed);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -2179,15 +2093,21 @@ H5SL_iterate(H5SL_t *slist, H5SL_operator_t op, void *op_data)
/* 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)
- break;
+ /* 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;
- } /* end while */
+ }
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_iterate() */
@@ -2222,9 +2142,6 @@ H5SL_release(H5SL_t *slist)
/* Check args */
HDassert(slist);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -2233,7 +2150,7 @@ H5SL_release(H5SL_t *slist)
HGOTO_ERROR(H5E_SLIST, H5E_CANTFREE, FAIL, "can't release skip list nodes")
done:
- FUNC_LEAVE_NOAPI(SUCCEED)
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5SL_release() */
/*--------------------------------------------------------------------------
@@ -2274,9 +2191,6 @@ H5SL_free(H5SL_t *slist, H5SL_operator_t op, void *op_data)
/* Check args */
HDassert(slist);
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
/* Check internal consistency */
/* (Pre-condition) */
@@ -2290,186 +2204,6 @@ done:
/*--------------------------------------------------------------------------
NAME
- H5SL_try_free_safe
- PURPOSE
- Makes the supplied callback on all nodes in the skip list, freeing each
- node that the callback returns TRUE for.
- USAGE
- herr_t PURPOSE(slist,op,opdata)
- H5SL_t *slist; IN/OUT: Pointer to skip list to release nodes
- H5SL_try_free_op_t op; IN: Callback function to try 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
- Makes the supplied callback on all nodes in the skip list, freeing each
- node that the callback returns TRUE for. The iteration is performed in
- a safe manner, such that the callback can call H5SL_remove(),
- H5SL_search(), H5SL_find(), and H5SL_iterate() on nodes in this
- skiplist, except H5SL_remove() may not be call on *this* node.
- GLOBAL VARIABLES
- COMMENTS, BUGS, ASSUMPTIONS
- This function is written to be most efficient when most nodes are
- removed from the skiplist, as it rebuilds the nodes afterwards.
- EXAMPLES
- REVISION LOG
---------------------------------------------------------------------------*/
-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;
-
- FUNC_ENTER_NOAPI_NOINIT
-
- /* Check args */
- HDassert(slist);
- HDassert(op);
-
- /* Not currently supported */
- HDassert(!slist->safe_iterating);
-
- /* Check internal consistency */
- /* (Pre-condition) */
-
- /* Mark skip list as safe iterating, so nodes aren't freed out from under
- * us */
- slist->safe_iterating = TRUE;
-
- /* 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) {
- /* Check if the node was already removed */
- if (!node->removed) {
- /* Call callback */
- /* Casting away const OK -NAF */
- 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)
- /* Mark the node as removed */
- node->removed = TRUE;
- } /* end if */
-
- /* Advance node */
- node = node->forward[0];
- } /* end while */
-
- /* Reset safe_iterating */
- slist->safe_iterating = FALSE;
-
- /* Iterate over nodes, freeing ones marked as removed */
- node = slist->header->forward[0];
- last_node = slist->header;
- while (node) {
- /* Save next node */
- next_node = node->forward[0];
-
- /* Check if the node was marked as 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);
- slist->nobjs--;
- } /* end if */
- else {
- /* Update backwards and forwards[0] pointers, and set the level to
- * 0. Since the list is flattened we must rebuild the skiplist
- * afterwards. */
- /* 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])))
- HGOTO_ERROR(H5E_SLIST, H5E_CANTALLOC, FAIL, "memory allocation failed")
- node->log_nalloc = 0;
- node->level = 0;
- } /* end if */
-
- /* Update pointers */
- last_node->forward[0] = node;
- node->backward = last_node;
- last_node = node;
- } /* end else */
-
- /* Advance node */
- node = next_node;
- } /* end while */
-
- /* Final pointer update */
- last_node->forward[0] = NULL;
- slist->last = last_node;
-
- /* Demote skip list to 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])))
- HGOTO_ERROR(H5E_SLIST, H5E_CANTALLOC, FAIL, "memory allocation failed")
- slist->header->forward[0] = node;
- slist->header->log_nalloc = 0;
- slist->header->level = 0;
- } /* end if */
-
- /* Check if there are any nodes left */
- if (slist->nobjs > 0) {
- int i;
-
- HDassert(slist->header->forward[0]);
-
- /* Set skiplist level to 0 */
- slist->curr_level = 0;
-
- /* Rebuild the forward arrays */
- 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) {
- /* 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)
- 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])
- break;
-
- /* Promote the third node in the gap */
- H5SL_PROMOTE(slist, node, last_node, FAIL)
- last_node = node;
- } /* end while */
- } /* end for */
- } /* end if */
- else {
- HDassert(!slist->header->forward[0]);
- HDassert(slist->last == slist->header);
- HDassert(slist->nobjs == 0);
-
- /* Reset the skiplist level */
- slist->curr_level = -1;
- } /* end else */
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5SL_try_free_safe() */
-
-/*--------------------------------------------------------------------------
- NAME
H5SL_destroy
PURPOSE
Close a skip list, deallocating it and freeing all its nodes.
diff --git a/src/H5SLprivate.h b/src/H5SLprivate.h
index c9e1147..be6f7b6 100644
--- a/src/H5SLprivate.h
+++ b/src/H5SLprivate.h
@@ -60,9 +60,6 @@ typedef int (*H5SL_cmp_t)(const void *key1, const void *key2);
/* Typedef for iteration operations */
typedef herr_t (*H5SL_operator_t)(void *item, void *key, void *operator_data /*in,out*/);
-/* Typedef for H5SL_try_free_safe operation callback */
-typedef htri_t (*H5SL_try_free_op_t)(void *item, void *key, void *operator_data /*in,out*/);
-
/********************/
/* Private routines */
/********************/
@@ -86,7 +83,6 @@ H5_DLL void * H5SL_item(H5SL_node_t *slist_node);
H5_DLL herr_t H5SL_iterate(H5SL_t *slist, H5SL_operator_t op, void *op_data);
H5_DLL herr_t H5SL_release(H5SL_t *slist);
H5_DLL herr_t H5SL_free(H5SL_t *slist, H5SL_operator_t op, void *op_data);
-H5_DLL herr_t H5SL_try_free_safe(H5SL_t *slist, H5SL_try_free_op_t op, void *op_data);
H5_DLL herr_t H5SL_close(H5SL_t *slist);
H5_DLL herr_t H5SL_destroy(H5SL_t *slist, H5SL_operator_t op, void *op_data);
H5_DLL int H5SL_term_interface(void);
diff --git a/src/Makefile.am b/src/Makefile.am
index ab9e13a..b2c0e05 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -73,12 +73,11 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5lib_settings.c H5system.c \
H5HFspace.c H5HFstat.c H5HFtest.c H5HFtiny.c \
H5HG.c H5HGcache.c H5HGdbg.c H5HGquery.c \
H5HL.c H5HLcache.c H5HLdbg.c H5HLint.c H5HLprfx.c H5HLdblk.c \
- H5HP.c \
H5I.c H5Idbg.c H5Iint.c H5Itest.c \
H5L.c H5Ldeprec.c H5Lexternal.c \
H5M.c \
H5MF.c H5MFaggr.c H5MFdbg.c H5MFsection.c \
- H5MM.c H5MP.c H5MPtest.c \
+ H5MM.c \
H5O.c H5Odeprec.c H5Oainfo.c H5Oalloc.c H5Oattr.c H5Oattribute.c \
H5Obogus.c H5Obtreek.c H5Ocache.c H5Ocache_image.c H5Ochunk.c \
H5Ocont.c H5Ocopy.c H5Ocopy_ref.c H5Odbg.c H5Odrvinfo.c H5Odtype.c \