summaryrefslogtreecommitdiffstats
path: root/src/H5B.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2002-04-23 16:01:43 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2002-04-23 16:01:43 (GMT)
commitf99a4120573eb8bcededc20a91be8fa520d4ebfa (patch)
tree87fd804f59a537819fb669fecda5598d6e964fd6 /src/H5B.c
parentac917c1f07c0af2e8de40a841223f72a85eaa7ee (diff)
downloadhdf5-f99a4120573eb8bcededc20a91be8fa520d4ebfa.zip
hdf5-f99a4120573eb8bcededc20a91be8fa520d4ebfa.tar.gz
hdf5-f99a4120573eb8bcededc20a91be8fa520d4ebfa.tar.bz2
[svn-r5230] Purpose:
Code cleanup Description: Clean up the H5B_iterate code to not have a single hard-wired iterator for each interface which uses a B-tree, instead accept a function pointer which determines the callback function. This allows additional iterator callbacks to be defined without requiring additional H5B functions to be created. In that spirit, remove the H5B_prune_by_extent call and convert the H5F_istore callback routine for it into a callback routine for H5B_iterate. Platforms tested: FreeBSD 4.5 (sleipnir)
Diffstat (limited to 'src/H5B.c')
-rw-r--r--src/H5B.c124
1 files changed, 7 insertions, 117 deletions
diff --git a/src/H5B.c b/src/H5B.c
index b1edd37..4db91b0 100644
--- a/src/H5B.c
+++ b/src/H5B.c
@@ -1568,10 +1568,13 @@ H5B_insert_helper(H5F_t *f, haddr_t addr, const H5B_class_t *type,
*
* Robb Matzke, 1999-07-28
* The ADDR argument is passed by value.
+ *
+ * Quincey Koziol, 2002-04-22
+ * Changed callback to function pointer from static function
*-------------------------------------------------------------------------
*/
herr_t
-H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata)
+H5B_iterate (H5F_t *f, const H5B_class_t *type, H5B_operator_t op, haddr_t addr, void *udata)
{
H5B_t *bt = NULL;
haddr_t next_addr;
@@ -1588,7 +1591,7 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata)
*/
assert(f);
assert(type);
- assert(type->list);
+ assert(op);
assert(H5F_addr_defined(addr));
assert(udata);
@@ -1598,7 +1601,7 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata)
}
if (bt->level > 0) {
/* Keep following the left-most child until we reach a leaf node. */
- if ((ret_value=H5B_iterate(f, type, bt->child[0], udata))<0) {
+ if ((ret_value=H5B_iterate(f, type, op, bt->child[0], udata))<0) {
HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL,
"unable to list B-tree node");
}
@@ -1641,7 +1644,7 @@ H5B_iterate (H5F_t *f, const H5B_class_t *type, haddr_t addr, void *udata)
* application callback.
*/
for (i=0, ret_value=0; i<nchildren && !ret_value; i++) {
- ret_value = (type->list)(f, key+i*type->sizeof_nkey,
+ ret_value = (*op)(f, key+i*type->sizeof_nkey,
child[i], key+(i+1)*type->sizeof_nkey,
udata);
if (ret_value<0) {
@@ -2153,119 +2156,6 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5B_prune_by_extent
- *
- * Purpose: Search for chunks that are no longer necessary in the B-tree.
- * The function iterates through the B-tree and calls an operator
- * function prune_extent
- *
- * Return: Success: 0, Failure: -1
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: March 26, 2002
- *
- * Comments: Private function
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5B_prune_by_extent(H5F_t *f, const H5B_class_t *type, haddr_t addr,
- void *udata, hsize_t *size)
-{
- H5B_t *bt = NULL;
- haddr_t next_addr;
- haddr_t cur_addr = HADDR_UNDEF;
- uint8_t *key = NULL;
- int i, nchildren;
- herr_t ret_value = FAIL;
-
- FUNC_ENTER(H5B_prune_by_extent, FAIL);
-
-/*
- * Check arguments.
- */
- assert(f);
- assert(type);
- assert(type->prune_extent);
- assert(H5F_addr_defined(addr));
- assert(udata);
-
- if(NULL == (bt = H5AC_find(f, H5AC_BT, addr, type, udata))) {
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL,
- "unable to load B-tree node");
- }
-
- if(bt->level > 0) {
- /* Keep following the left-most child until we reach a leaf node. */
- if((ret_value =
- H5B_prune_by_extent(f, type, bt->child[0], udata,
- size)) < 0) {
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL,
- "unable to list B-tree node");
- }
- }
- else {
-
-/*
- * We've reached the left-most leaf. Now follow the right-sibling
- * pointer from leaf to leaf until we've processed all leaves.
- */
-
- if(NULL == (key =
- H5MM_malloc((2 * H5B_Kvalue(f,
- type) + 1) * type->sizeof_nkey))) {
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
-
- for(cur_addr = addr, ret_value = 0;
- H5F_addr_defined(cur_addr) && !ret_value;
- cur_addr = next_addr) {
-
- /*
- * Save all the native keys since we can't leave the B-tree node protected during an application callback.
- */
-
- if(NULL == (bt = H5AC_find(f, H5AC_BT, cur_addr, type, udata))) {
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "B-tree node");
- }
-
- for(i = 0; i < bt->nchildren + 1; i++) {
- if(!bt->key[i].nkey)
- H5B_decode_key(f, bt, i);
- HDmemcpy(key + i * type->sizeof_nkey, bt->key[i].nkey,
- type->sizeof_nkey);
- }
-
- next_addr = bt->right;
- nchildren = bt->nchildren;
- bt = NULL;
-
- /* Figure out what chunks are no longer in use for the specified extent and release them */
-
- for(i = 0, ret_value = 0; i < nchildren && !ret_value; i++) {
- ret_value =
- (type->prune_extent) (f, key + i * type->sizeof_nkey,
- addr, udata, size);
- if(ret_value < 0) {
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL,
- "iterator function failed");
- }
- } /*i */
- } /*addr */
- } /*level */
-
-done:
- if(key != NULL)
- H5MM_xfree(key);
- FUNC_LEAVE(ret_value);
-}
-
-
-/*-------------------------------------------------------------------------
* Function: H5B_debug
*
* Purpose: Prints debugging info about a B-tree.