summaryrefslogtreecommitdiffstats
path: root/src/H5B2.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-03-11 02:27:59 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-03-11 02:27:59 (GMT)
commit46dcfc7a497e25cad02c7cddf1b36df7614ea27e (patch)
treedc0f85d34bb1f61c2d143363560298f567a13f18 /src/H5B2.c
parent5b7ebc2ff95e1dea0bd9517e360b7af98dbd0a4d (diff)
downloadhdf5-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)
Diffstat (limited to 'src/H5B2.c')
-rw-r--r--src/H5B2.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/H5B2.c b/src/H5B2.c
index a04a870..828aebd 100644
--- a/src/H5B2.c
+++ b/src/H5B2.c
@@ -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)