summaryrefslogtreecommitdiffstats
path: root/src/H5TB.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-11-18 18:53:35 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-11-18 18:53:35 (GMT)
commit49db749a01f37c04ab9366b7832126c01e923dd8 (patch)
tree2806c3b36055d413392966722e2834a4bd8842b9 /src/H5TB.c
parent7016b6e5ed1870eba265ac1a06b1683106a18420 (diff)
downloadhdf5-49db749a01f37c04ab9366b7832126c01e923dd8.zip
hdf5-49db749a01f37c04ab9366b7832126c01e923dd8.tar.gz
hdf5-49db749a01f37c04ab9366b7832126c01e923dd8.tar.bz2
[svn-r9540] Purpose:
Code optimization Description: Change threaded, balanced binary tree insertion routine to use more efficient "fast" search routine when trees with "fast compare" routines have objects inserted into them. Platforms tested: FreeBSD 4.10 (sleipnir) w/parallel Solaris 2.7 (arabica) Too minor to require h5committest
Diffstat (limited to 'src/H5TB.c')
-rw-r--r--src/H5TB.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/H5TB.c b/src/H5TB.c
index 37b32eb..db140c7 100644
--- a/src/H5TB.c
+++ b/src/H5TB.c
@@ -713,7 +713,7 @@ H5TB_dins(H5TB_TREE * tree, void * item, void * key)
assert(tree);
/* Try to insert the node */
- ret_value = H5TB_ins(&(tree->root), item, key, tree->compar, tree->cmparg);
+ ret_value = H5TB_ins(&(tree->root), item, key, tree->fast_compare, tree->compar, tree->cmparg);
/* If we successfully inserted the node, increment the node count in the tree */
if (ret_value != NULL)
@@ -741,11 +741,13 @@ H5TB_dins(H5TB_TREE * tree, void * item, void * key)
* Modifications:
*
* Notes:
+ * Assumes that the comparison routine is _NOT_ used for trees with
+ * "fast compare" set.
*
*-------------------------------------------------------------------------
*/
H5TB_NODE *
-H5TB_ins(H5TB_NODE ** root, void * item, void * key, H5TB_cmp_t compar, int arg)
+H5TB_ins(H5TB_NODE ** root, void * item, void * key, unsigned fast_compare, H5TB_cmp_t compar, int arg)
{
int cmp;
H5TB_NODE *ptr, *parent;
@@ -756,8 +758,16 @@ H5TB_ins(H5TB_NODE ** root, void * item, void * key, H5TB_cmp_t compar, int arg)
assert(root);
assert(item);
- if (NULL != H5TB_find(*root, (key ? key : item), compar, arg, &parent))
- HGOTO_ERROR (H5E_TBBT, H5E_EXISTS, NULL, "node already in tree");
+ /* Find node in tree, or parent of where node will go */
+ if(fast_compare!=0) {
+ if(NULL != H5TB_ffind(*root, (key ? key : item), fast_compare, &parent))
+ HGOTO_ERROR (H5E_TBBT, H5E_EXISTS, NULL, "node already in tree");
+ } /* end if */
+ else {
+ if(NULL != H5TB_find(*root, (key ? key : item), compar, arg, &parent))
+ HGOTO_ERROR (H5E_TBBT, H5E_EXISTS, NULL, "node already in tree");
+ } /* end else */
+
if (NULL == (ptr = H5FL_MALLOC(H5TB_NODE)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
ptr->data = item;
@@ -1283,7 +1293,7 @@ done:
H5TB_NODE *
H5TB_end(H5TB_NODE * root, int side)
{
- FUNC_ENTER_NOAPI_NOFUNC(H5TB_end);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5TB_end);
assert(side==LEFT || side==RIGHT);
@@ -1300,7 +1310,7 @@ H5TB_nbr(H5TB_NODE * ptr, int side)
{
H5TB_NODE *ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOFUNC(H5TB_nbr);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5TB_nbr);
if (!HasChild(ptr, side))
HGOTO_DONE (ptr->link[side]);