diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2004-11-18 18:53:35 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2004-11-18 18:53:35 (GMT) |
commit | 49db749a01f37c04ab9366b7832126c01e923dd8 (patch) | |
tree | 2806c3b36055d413392966722e2834a4bd8842b9 | |
parent | 7016b6e5ed1870eba265ac1a06b1683106a18420 (diff) | |
download | hdf5-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
-rw-r--r-- | src/H5TB.c | 22 | ||||
-rw-r--r-- | src/H5TBprivate.h | 2 |
2 files changed, 17 insertions, 7 deletions
@@ -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]); diff --git a/src/H5TBprivate.h b/src/H5TBprivate.h index 0e374e3..a58fc39 100644 --- a/src/H5TBprivate.h +++ b/src/H5TBprivate.h @@ -127,7 +127,7 @@ H5_DLL H5TB_NODE *H5TB_less (H5TB_NODE * root, void * key, H5TB_cmp_t cmp, int arg, H5TB_NODE ** pp); H5_DLL H5TB_NODE *H5TB_index (H5TB_NODE * root, unsigned indx); H5_DLL H5TB_NODE *H5TB_dins (H5TB_TREE * tree, void * item, void * key); -H5_DLL H5TB_NODE *H5TB_ins (H5TB_NODE ** root, void * item, void * key, H5TB_cmp_t cmp, int arg); +H5_DLL H5TB_NODE *H5TB_ins (H5TB_NODE ** root, void * item, void * key, unsigned fast_compare, H5TB_cmp_t cmp, int arg); H5_DLL void *H5TB_rem(H5TB_NODE ** root, H5TB_NODE * node, void * *kp); H5_DLL H5TB_TREE *H5TB_dfree (H5TB_TREE * tree, void(*fd) (void *), void(*fk) (void *)); H5_DLL void *H5TB_free (H5TB_NODE ** root, void(*fd) (void *), void(*fk) (void *)); |