summaryrefslogtreecommitdiffstats
path: root/src/H5B2test.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-11-07 13:12:06 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-11-07 13:12:06 (GMT)
commite8f31a24797a129fd8ed2c7ec5e2a080d0b5fb88 (patch)
tree41ef126f79131fbafb8c5826a6628ba8b3be1c65 /src/H5B2test.c
parent401f0c995f4c28d3bf4c15c859f0195bba70bdd3 (diff)
downloadhdf5-e8f31a24797a129fd8ed2c7ec5e2a080d0b5fb88.zip
hdf5-e8f31a24797a129fd8ed2c7ec5e2a080d0b5fb88.tar.gz
hdf5-e8f31a24797a129fd8ed2c7ec5e2a080d0b5fb88.tar.bz2
[svn-r17848] Description:
Further refactoring v2 B-trees so that they can get context to the encode/decode client callbacks: - Switch tests to using refactored routines Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.1 (amazon) in debug mode Mac OS X/32 10.6.1 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode
Diffstat (limited to 'src/H5B2test.c')
-rw-r--r--src/H5B2test.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/src/H5B2test.c b/src/H5B2test.c
index 6722c28..28f6dc2 100644
--- a/src/H5B2test.c
+++ b/src/H5B2test.c
@@ -222,6 +222,35 @@ H5B2_test_debug(FILE *stream, const H5F_t UNUSED *f, hid_t UNUSED dxpl_id,
/*-------------------------------------------------------------------------
+ * Function: H5B2_get_root_addr_test_2
+ *
+ * Purpose: Retrieve the root node's address
+ *
+ * Return: Success: non-negative
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Saturday, February 26, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5B2_get_root_addr_test_2(H5B2_t *bt2, haddr_t *root_addr)
+{
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_get_root_addr_test_2)
+
+ /* Check arguments. */
+ HDassert(bt2);
+ HDassert(root_addr);
+
+ /* Get B-tree root addr */
+ *root_addr = bt2->hdr->root.addr;
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* H5B2_get_root_addr_test_2() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5B2_get_root_addr_test
*
* Purpose: Retrieve the root node's address
@@ -267,6 +296,122 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5B2_get_node_info_test_2
+ *
+ * Purpose: Determine information about a node holding a record in the B-tree
+ *
+ * Return: Success: non-negative
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Thursday, August 31, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5B2_get_node_info_test_2(H5B2_t *bt2, hid_t dxpl_id, void *udata,
+ H5B2_node_info_test_t *ninfo)
+{
+ H5B2_hdr_t *hdr; /* Pointer to the B-tree header */
+ H5B2_node_ptr_t curr_node_ptr; /* Node pointer info for current node */
+ unsigned depth; /* Current depth of the tree */
+ int cmp; /* Comparison value of records */
+ unsigned idx; /* Location of record which matches key */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5B2_get_node_info_test_2, FAIL)
+
+ /* Check arguments. */
+ HDassert(bt2);
+
+ /* Set the shared v2 B-tree header's file context for this operation */
+ bt2->hdr->f = bt2->f;
+
+ /* Get the v2 B-tree header */
+ hdr = bt2->hdr;
+
+ /* Make copy of the root node pointer to start search with */
+ curr_node_ptr = hdr->root;
+
+ /* Current depth of the tree */
+ depth = hdr->depth;
+
+ /* Check for empty tree */
+ if(0 == curr_node_ptr.node_nrec)
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "B-tree has no records")
+
+ /* Walk down B-tree to find record or leaf node where record is located */
+ cmp = -1;
+ while(depth > 0 && cmp != 0) {
+ H5B2_internal_t *internal; /* Pointer to internal node in B-tree */
+ H5B2_node_ptr_t next_node_ptr; /* Node pointer info for next node */
+
+ /* Lock B-tree current node */
+ if(NULL == (internal = H5B2_protect_internal(hdr, dxpl_id, curr_node_ptr.addr, curr_node_ptr.node_nrec, depth, H5AC_READ)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree internal node")
+
+ /* Locate node pointer for child */
+ cmp = H5B2_locate_record(hdr->cls, internal->nrec, hdr->nat_off, internal->int_native, udata, &idx);
+ if(cmp > 0)
+ idx++;
+
+ if(cmp != 0) {
+ /* Get node pointer for next node to search */
+ next_node_ptr = internal->node_ptrs[idx];
+
+ /* Unlock current node */
+ if(H5AC_unprotect(hdr->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")
+
+ /* Set pointer to next node to load */
+ curr_node_ptr = next_node_ptr;
+ } /* end if */
+ else {
+ /* Unlock current node */
+ if(H5AC_unprotect(hdr->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")
+
+ /* Fill in information about the node */
+ ninfo->depth = depth;
+ ninfo->nrec = curr_node_ptr.node_nrec;
+
+ /* Indicate success */
+ HGOTO_DONE(SUCCEED)
+ } /* end else */
+
+ /* Decrement depth we're at in B-tree */
+ depth--;
+ } /* end while */
+
+ {
+ H5B2_leaf_t *leaf; /* Pointer to leaf node in B-tree */
+
+ /* Lock B-tree leaf node */
+ if(NULL == (leaf = (H5B2_leaf_t *)H5AC_protect(hdr->f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, &(curr_node_ptr.node_nrec), hdr, H5AC_READ)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree internal node")
+
+ /* Locate record */
+ cmp = H5B2_locate_record(hdr->cls, leaf->nrec, hdr->nat_off, leaf->leaf_native, udata, &idx);
+
+ /* Unlock current node */
+ if(H5AC_unprotect(hdr->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")
+
+ /* Indicate the depth that the record was found */
+ if(cmp != 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "record not in B-tree")
+ } /* end block */
+
+ /* Fill in information about the leaf node */
+ ninfo->depth = depth;
+ ninfo->nrec = curr_node_ptr.node_nrec;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* H5B2_get_node_info_test_2() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5B2_get_node_info_test
*
* Purpose: Determine information about a node holding a record in the B-tree
@@ -390,6 +535,45 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5B2_get_node_depth_test_2
+ *
+ * Purpose: Determine the depth of a node holding a record in the B-tree
+ *
+ * Note: Just a simple wrapper around the H5B2_get_node_info_test() routine
+ *
+ * Return: Success: non-negative depth of the node where the record
+ * was found
+ * Failure: negative
+ *
+ * Programmer: Quincey Koziol
+ * Saturday, August 26, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+H5B2_get_node_depth_test_2(H5B2_t *bt2, hid_t dxpl_id, void *udata)
+{
+ H5B2_node_info_test_t ninfo; /* Node information */
+ int ret_value; /* Return information */
+
+ FUNC_ENTER_NOAPI(H5B2_get_node_depth_test_2, FAIL)
+
+ /* Check arguments. */
+ HDassert(bt2);
+
+ /* Get information abou the node */
+ if(H5B2_get_node_info_test_2(bt2, dxpl_id, udata, &ninfo) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "error looking up node info")
+
+ /* Set return value */
+ ret_value = (int)ninfo.depth;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* H5B2_get_node_depth_test_2() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5B2_get_node_depth_test
*
* Purpose: Determine the depth of a node holding a record in the B-tree