diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-03-11 02:27:59 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-03-11 02:27:59 (GMT) |
commit | 46dcfc7a497e25cad02c7cddf1b36df7614ea27e (patch) | |
tree | dc0f85d34bb1f61c2d143363560298f567a13f18 | |
parent | 5b7ebc2ff95e1dea0bd9517e360b7af98dbd0a4d (diff) | |
download | hdf5-46dcfc7a497e25cad02c7cddf1b36df7614ea27e.zip hdf5-46dcfc7a497e25cad02c7cddf1b36df7614ea27e.tar.gz hdf5-46dcfc7a497e25cad02c7cddf1b36df7614ea27e.tar.bz2 |
[svn-r10185] Purpose:
New feature & bug fix
Description:
Allow NULL 'op' for find operations to easily query the existance of a
record for a key during H5B2_find() operations.
Fix H5B2_neighbor() to work properly with empty B-tree
Platforms tested:
FreeBSD 4.11 (sleipnir)
Solaris 2.9 (shanti)
-rw-r--r-- | src/H5B2.c | 12 | ||||
-rw-r--r-- | test/btree2.c | 10 |
2 files changed, 19 insertions, 3 deletions
@@ -2941,6 +2941,9 @@ done: * OP_DATA pointer, to allow caller to return information about * the record. * + * If 'OP' is NULL, then this routine just returns "SUCCEED" when + * a record is found. + * * Return: Non-negative on success, negative on failure. * * Programmer: Quincey Koziol @@ -2969,7 +2972,6 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr, HDassert(f); HDassert(type); HDassert(H5F_addr_defined(addr)); - HDassert(op); /* Look up the B-tree header */ if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_READ))) @@ -3027,7 +3029,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr, } /* end if */ else { /* Make callback for current record */ - if ((op)(H5B2_INT_NREC(internal,shared,idx), op_data) <0) { + if ( op && (op)(H5B2_INT_NREC(internal,shared,idx), op_data) <0) { /* Unlock current node */ if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node") @@ -3073,7 +3075,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr, } /* end if */ else { /* Make callback for current record */ - if ((op)(H5B2_LEAF_NREC(leaf,shared,idx), op_data) <0) { + if ( op && (op)(H5B2_LEAF_NREC(leaf,shared,idx), op_data) <0) { /* Unlock current node */ if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node") @@ -3902,6 +3904,10 @@ H5B2_neighbor(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr, if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_READ))) HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree header") + /* Check for empty tree */ + if(!H5F_addr_defined(bt2->root.addr)) + HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "B-tree has no records") + /* Attempt to find neighbor record in B-tree */ if(bt2->depth>0) { if(H5B2_neighbor_internal(f, dxpl_id, bt2->shared, bt2->depth, &bt2->root, NULL, range, udata, op, op_data)<0) diff --git a/test/btree2.c b/test/btree2.c index 80a5714..81d563d 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -223,10 +223,20 @@ test_insert_basic(hid_t fapl) /* Should fail */ if(ret != FAIL) TEST_ERROR; + /* Try again with NULL 'op' */ + H5E_BEGIN_TRY { + ret = H5B2_find(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &idx, NULL, NULL); + } H5E_END_TRY; + /* Should fail */ + if(ret != FAIL) TEST_ERROR; + /* Attempt to find existant record in B-tree with 1 record */ idx = 42; if(H5B2_find(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &idx, find_cb, &idx)<0) TEST_ERROR; + /* Try again with NULL 'op' */ + if(H5B2_find(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &idx, NULL, NULL)<0) TEST_ERROR; + /* Attempt to index non-existant record in B-tree with 1 record */ idx = 0; H5E_BEGIN_TRY { |