mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-01-24 15:25:00 +08:00
[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)
This commit is contained in:
parent
5b7ebc2ff9
commit
46dcfc7a49
12
src/H5B2.c
12
src/H5B2.c
@ -2941,6 +2941,9 @@ done:
|
|||||||
* OP_DATA pointer, to allow caller to return information about
|
* OP_DATA pointer, to allow caller to return information about
|
||||||
* the record.
|
* 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.
|
* Return: Non-negative on success, negative on failure.
|
||||||
*
|
*
|
||||||
* Programmer: Quincey Koziol
|
* 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(f);
|
||||||
HDassert(type);
|
HDassert(type);
|
||||||
HDassert(H5F_addr_defined(addr));
|
HDassert(H5F_addr_defined(addr));
|
||||||
HDassert(op);
|
|
||||||
|
|
||||||
/* Look up the B-tree header */
|
/* Look up the B-tree header */
|
||||||
if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_READ)))
|
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 */
|
} /* end if */
|
||||||
else {
|
else {
|
||||||
/* Make callback for current record */
|
/* 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 */
|
/* Unlock current node */
|
||||||
if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0)
|
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")
|
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 */
|
} /* end if */
|
||||||
else {
|
else {
|
||||||
/* Make callback for current record */
|
/* 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 */
|
/* Unlock current node */
|
||||||
if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
|
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")
|
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)))
|
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")
|
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 */
|
/* Attempt to find neighbor record in B-tree */
|
||||||
if(bt2->depth>0) {
|
if(bt2->depth>0) {
|
||||||
if(H5B2_neighbor_internal(f, dxpl_id, bt2->shared, bt2->depth, &bt2->root, NULL, range, udata, op, op_data)<0)
|
if(H5B2_neighbor_internal(f, dxpl_id, bt2->shared, bt2->depth, &bt2->root, NULL, range, udata, op, op_data)<0)
|
||||||
|
@ -223,10 +223,20 @@ test_insert_basic(hid_t fapl)
|
|||||||
/* Should fail */
|
/* Should fail */
|
||||||
if(ret != FAIL) TEST_ERROR;
|
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 */
|
/* Attempt to find existant record in B-tree with 1 record */
|
||||||
idx = 42;
|
idx = 42;
|
||||||
if(H5B2_find(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &idx, find_cb, &idx)<0) TEST_ERROR;
|
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 */
|
/* Attempt to index non-existant record in B-tree with 1 record */
|
||||||
idx = 0;
|
idx = 0;
|
||||||
H5E_BEGIN_TRY {
|
H5E_BEGIN_TRY {
|
||||||
|
Loading…
Reference in New Issue
Block a user