From bd085c3bc51dc37c0412a5012c1f38dc3cbff161 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 14 Feb 2024 00:00:19 -0800 Subject: [PATCH] Remove TBBT_INTERNALS scheme The TBBT code used a weird scheme where the main data structures were defined differently in the header and source files in an attempt to hide private details. This has been switched to use a PIMPL scheme with properly hidden data instead. --- hdf/src/hdatainfo.c | 2 +- hdf/src/mfan.c | 16 +-- hdf/src/mfgr.c | 14 +- hdf/src/tbbt.c | 332 +++++++++++++++++++++++++++----------------- hdf/src/tbbt.h | 106 +++++--------- hdf/src/vgp.c | 6 +- hdf/src/vio.c | 2 +- 7 files changed, 256 insertions(+), 222 deletions(-) diff --git a/hdf/src/hdatainfo.c b/hdf/src/hdatainfo.c index 22a54aaee8..00f49bca7a 100644 --- a/hdf/src/hdatainfo.c +++ b/hdf/src/hdatainfo.c @@ -726,7 +726,7 @@ GRgetattdatainfo(int32 id, int32 attrindex, int32 *offset, int32 *length) HGOTO_ERROR(DFE_ARGS, FAIL); /* Search for an attribute with the same index */ - aentry = (void **)tbbtfirst((TBBT_NODE *)*search_tree); + aentry = (void **)tbbtfirst(search_tree->root); found = FALSE; while (!found && (aentry != NULL)) { at_ptr = (at_info_t *)*aentry; diff --git a/hdf/src/mfan.c b/hdf/src/mfan.c index bb45bb7596..a506742812 100644 --- a/hdf/src/mfan.c +++ b/hdf/src/mfan.c @@ -683,7 +683,7 @@ ANInumann(int32 an_id, /* IN: annotation interface id */ } /* Traverse the list looking for a match */ - for (entry = tbbtfirst((TBBT_NODE *)*(file_rec->an_tree[type])); entry != NULL; entry = tbbtnext(entry)) { + for (entry = tbbtfirst(file_rec->an_tree[type]->root); entry != NULL; entry = tbbtnext(entry)) { ann_entry = (ANentry *)entry->data; /* get annotation entry from node */ if ((ann_entry->elmref == elem_ref) && (ann_entry->elmtag == elem_tag)) { nanns++; /* increment ref counter if match */ @@ -744,7 +744,7 @@ ANIannlist(int32 an_id, /* IN: annotation interface id */ } /* Traverse the list looking for a match */ - for (entry = tbbtfirst((TBBT_NODE *)*(file_rec->an_tree[type])); entry != NULL; entry = tbbtnext(entry)) { + for (entry = tbbtfirst(file_rec->an_tree[type]->root); entry != NULL; entry = tbbtnext(entry)) { ann_entry = (ANentry *)entry->data; /* get annotation entry from node */ if ((ann_entry->elmref == elem_ref) && (ann_entry->elmtag == elem_tag)) { /* save ref of ann match in list */ @@ -1329,7 +1329,7 @@ ANend(int32 an_id /* IN: Annotation ID of file to close */) /* free file label annotation rb tree */ if (file_rec->an_tree[AN_FILE_LABEL] != NULL) { /* Traverse tree puling ann_id's to delete from annotation atom group */ - for (aentry = tbbtfirst((TBBT_NODE *)*(file_rec->an_tree[AN_FILE_LABEL])); aentry != NULL; + for (aentry = tbbtfirst(file_rec->an_tree[AN_FILE_LABEL]->root); aentry != NULL; aentry = tbbtnext(aentry)) { /* get annotation entry from node */ ann_entry = (ANentry *)aentry->data; @@ -1346,7 +1346,7 @@ ANend(int32 an_id /* IN: Annotation ID of file to close */) /* free file desc annotation rb tree */ if (file_rec->an_tree[AN_FILE_DESC] != NULL) { /* Traverse tree puling ann_id's to delete from annotation atom group */ - for (aentry = tbbtfirst((TBBT_NODE *)*(file_rec->an_tree[AN_FILE_DESC])); aentry != NULL; + for (aentry = tbbtfirst(file_rec->an_tree[AN_FILE_DESC]->root); aentry != NULL; aentry = tbbtnext(aentry)) { /* get annotation entry from node */ ann_entry = (ANentry *)aentry->data; @@ -1364,7 +1364,7 @@ ANend(int32 an_id /* IN: Annotation ID of file to close */) /* free label annotation rb tree */ if (file_rec->an_tree[AN_DATA_LABEL] != NULL) { /* Traverse tree puling ann_id's to delete from annotation atom group */ - for (aentry = tbbtfirst((TBBT_NODE *)*(file_rec->an_tree[AN_DATA_LABEL])); aentry != NULL; + for (aentry = tbbtfirst(file_rec->an_tree[AN_DATA_LABEL]->root); aentry != NULL; aentry = tbbtnext(aentry)) { /* get annotation entry from node */ ann_entry = (ANentry *)aentry->data; @@ -1381,7 +1381,7 @@ ANend(int32 an_id /* IN: Annotation ID of file to close */) /* free desc annotation rb tree */ if (file_rec->an_tree[AN_DATA_DESC] != NULL) { /* Traverse tree pulling ann_id's to delete from annotation atom group */ - for (aentry = tbbtfirst((TBBT_NODE *)*(file_rec->an_tree[AN_DATA_DESC])); aentry != NULL; + for (aentry = tbbtfirst(file_rec->an_tree[AN_DATA_DESC]->root); aentry != NULL; aentry = tbbtnext(aentry)) { /* get annotation entry from node */ ann_entry = (ANentry *)aentry->data; @@ -1534,7 +1534,7 @@ ANselect(int32 an_id, /* IN: annotation interface ID */ HE_REPORT_GOTO("bad index", FAIL); /* find 'index' entry */ - if ((entry = tbbtindx((TBBT_NODE *)*(file_rec->an_tree[type]), index)) == NULL) + if ((entry = tbbtindx(file_rec->an_tree[type]->root, index)) == NULL) HE_REPORT_GOTO("failed to find 'index' entry", FAIL); ann_entry = (ANentry *)entry->data; @@ -1774,7 +1774,7 @@ ANget_tagref(int32 an_id, /* IN: annotation interface ID */ HE_REPORT_GOTO("bad index", FAIL); /* find 'index' entry */ - if ((entry = tbbtindx((TBBT_NODE *)*(file_rec->an_tree[type]), index)) == NULL) + if ((entry = tbbtindx(file_rec->an_tree[type]->root, index)) == NULL) HE_REPORT_GOTO("failed to find 'index' entry", FAIL); ann_entry = (ANentry *)entry->data; diff --git a/hdf/src/mfgr.c b/hdf/src/mfgr.c index 5007e646d9..303a659038 100644 --- a/hdf/src/mfgr.c +++ b/hdf/src/mfgr.c @@ -1995,7 +1995,7 @@ GRend(int32 grid) void **t2; ri_info_t *img_ptr; /* ptr to the image */ - if (NULL == (t2 = (void **)tbbtfirst((TBBT_NODE *)*(gr_ptr->grtree)))) { + if (NULL == (t2 = (void **)tbbtfirst(gr_ptr->grtree->root))) { HGOTO_ERROR(DFE_NOTINTABLE, FAIL); } /* end if */ else @@ -2029,7 +2029,7 @@ GRend(int32 grid) void **t3; at_info_t *attr_ptr; /* ptr to the attribute */ - if (NULL == (t3 = (void **)tbbtfirst((TBBT_NODE *)*(img_ptr->lattree)))) { + if (NULL == (t3 = (void **)tbbtfirst(img_ptr->lattree->root))) { HGOTO_ERROR(DFE_NOTINTABLE, FAIL); } /* end if */ else @@ -2082,7 +2082,7 @@ GRend(int32 grid) void **t2; at_info_t *attr_ptr; /* ptr to the attribute */ - if (NULL == (t2 = (void **)tbbtfirst((TBBT_NODE *)*(gr_ptr->gattree)))) { + if (NULL == (t2 = (void **)tbbtfirst(gr_ptr->gattree->root))) { HGOTO_ERROR(DFE_NOTINTABLE, FAIL); } /* end if */ else @@ -2358,7 +2358,7 @@ GRnametoindex(int32 grid, const char *name) if (NULL == (gr_ptr = (gr_info_t *)HAatom_object(grid))) HGOTO_ERROR(DFE_GRNOTFOUND, FAIL); - if ((t = (void **)tbbtfirst((TBBT_NODE *)*(gr_ptr->grtree))) == NULL) + if ((t = (void **)tbbtfirst(gr_ptr->grtree->root)) == NULL) HGOTO_ERROR(DFE_RINOTFOUND, FAIL); do { ri_ptr = (ri_info_t *)*t; @@ -3352,7 +3352,7 @@ GRreftoindex(int32 grid, uint16 ref) if (NULL == (gr_ptr = (gr_info_t *)HAatom_object(grid))) HGOTO_ERROR(DFE_GRNOTFOUND, FAIL); - if ((t = (void **)tbbtfirst((TBBT_NODE *)*(gr_ptr->grtree))) == NULL) + if ((t = (void **)tbbtfirst(gr_ptr->grtree->root)) == NULL) HGOTO_ERROR(DFE_RINOTFOUND, FAIL); do { ri_ptr = (ri_info_t *)*t; @@ -4392,7 +4392,7 @@ GRsetattr(int32 id, const char *name, int32 attr_nt, int32 count, const void *da HGOTO_ERROR(DFE_ARGS, FAIL); /* Search for an attribute with the same name */ - if ((t = (void **)tbbtfirst((TBBT_NODE *)*search_tree)) != NULL) { + if ((t = (void **)tbbtfirst(search_tree->root)) != NULL) { do { at_ptr = (at_info_t *)*t; if (at_ptr != NULL && strcmp(at_ptr->name, name) == 0) /* ie. the name matches */ @@ -4755,7 +4755,7 @@ GRfindattr(int32 id, const char *name) else /* shouldn't get here, but what the heck... */ HGOTO_ERROR(DFE_ARGS, FAIL); - if ((t = (void **)tbbtfirst((TBBT_NODE *)*search_tree)) == NULL) + if ((t = (void **)tbbtfirst(search_tree->root)) == NULL) HGOTO_ERROR(DFE_RINOTFOUND, FAIL); do { at_ptr = (at_info_t *)*t; diff --git a/hdf/src/tbbt.c b/hdf/src/tbbt.c index 092a98a2ff..1eceb5ac2d 100644 --- a/hdf/src/tbbt.c +++ b/hdf/src/tbbt.c @@ -16,31 +16,106 @@ /* Basic tree structure by Adel'son-Vel'skii and Landis */ #include "hdfi.h" - -#define TBBT_INTERNALS #include "tbbt.h" +#define PARENT 0 +#define LEFT 1 +#define RIGHT 2 + +/* Quick hack to implement PIMPL pattern for TBBT nodes + * + * Simple copy-n-paste, so not as robust as a function-like macro (but + * simpler to read and looks more like the original code) + */ +#define Flags priv->flags +#define Link priv->link +#define Rcnt priv->rcnt +#define Lcnt priv->lcnt +#define Parent Link[PARENT] +#define Lchild Link[LEFT] +#define Rchild Link[RIGHT] + +/* Quick hack to implement PIMPL pattern for TBBT trees + * + * Simple copy-n-paste, so not as robust as a function-like macro (but + * simpler to read and looks more like the original code) + */ +#define Count priv->count +#define Fast_compare priv->fast_compare +#define Compar priv->compar +#define Cmparg priv->cmparg + +#define TBBT_FLAG unsigned long +#define TBBT_LEAF unsigned long + +/* TBBT flag values */ +#define TBBT_HEAVY(s) s /* If the `s' sub-tree is deeper than the other */ +#define TBBT_DOUBLE 4 /* If "heavy" sub-tree is two levels deeper */ +#define TBBT_INTERN 8 /* If node is internal (has two children) */ +#define TBBT_UNBAL (TBBT_HEAVY(LEFT) | TBBT_HEAVY(RIGHT)) +#define TBBT_FLAGS (TBBT_UNBAL | TBBT_INTERN | TBBT_DOUBLE) +#define TBBT_CHILD(s) (TBBT_INTERN | TBBT_HEAVY(s)) + +#define LeftCnt(node) ((node)->Lcnt) /* Left descendants */ +#define RightCnt(node) ((node)->Rcnt) /* Left descendants */ +#define Cnt(node, s) (LEFT == (s) ? LeftCnt(node) : RightCnt(node)) +#define HasChild(n, s) (Cnt(n, s) > 0) +#define Heavy(n, s) ((s) & (LeftCnt(n) > RightCnt(n) ? LEFT : LeftCnt(n) == RightCnt(n) ? 0 : RIGHT)) +#define Intern(n) (LeftCnt(n) && RightCnt(n)) +#define UnBal(n) (LeftCnt(n) > RightCnt(n) ? LEFT : LeftCnt(n) == RightCnt(n) ? 0 : RIGHT) +#define Double(n) (TBBT_DOUBLE & (n)->Flags) +#define Other(side) (LEFT + RIGHT - (side)) +#define Delta(n, s) ((Heavy(n, s) ? 1 : -1) * (Double(n) ? 2 : UnBal(n) ? 1 : 0)) + +#define SetFlags(n, s, b, i) \ + ((-2 < (b) && (b) < 2 ? 0 : TBBT_DOUBLE) | \ + (0 > (b) ? TBBT_HEAVY(s) \ + : (b) > 0 ? TBBT_HEAVY(Other(s)) \ + : 0) | \ + ((i) ? TBBT_INTERN : 0)) + +/* Return maximum of two scalar values */ +#define Max(a, b) ((a) > (b) ? (a) : (b)) + +/* Private TBBT information */ +typedef struct tbbt_node_private { + TBBT_NODE *link[3]; /* Pointers to parent, left child, and right child */ + TBBT_FLAG flags; /* TBBT flags: (see above) */ + TBBT_LEAF lcnt; /* Count of left children */ + TBBT_LEAF rcnt; /* Count of right children */ +} TBBT_NODE_PRIV; + +typedef struct tbbt_tree_private { + unsigned long count; /* The number of nodes in the tree currently */ + unsigned fast_compare; /* Use a faster in-line compare (with casts) instead of function call */ + int (*compar)(void *k1, void *k2, int cmparg); + int cmparg; +} TBBT_TREE_PRIV; + +/* Pointer to the tbbt node free list */ +static TBBT_NODE *tbbt_free_list = NULL; + #define KEYcmp(k1, k2, a) \ - ((NULL != compar) ? (*compar)(k1, k2, a) : memcmp(k1, k2, 0 < (a) ? (a) : (intn)strlen(k1))) + ((NULL != compar) ? (*compar)(k1, k2, a) : memcmp(k1, k2, 0 < (a) ? (a) : (int)strlen(k1))) -void tbbt1dump(TBBT_NODE *node, intn method); +void tbbt1dump(TBBT_NODE *node, int method); /* Function Prototypes */ extern void tbbt_printNode(TBBT_NODE *node, void (*key_dump)(void *, void *)); -extern void tbbt_dumpNode(TBBT_NODE *node, void (*key_dump)(void *, void *), intn method); -extern void tbbt_dump(TBBT_TREE *ptree, void (*key_dump)(void *, void *), intn method); +extern void tbbt_dumpNode(TBBT_NODE *node, void (*key_dump)(void *, void *), int method); +extern void tbbt_dump(TBBT_TREE *ptree, void (*key_dump)(void *, void *), int method); static TBBT_NODE *tbbt_get_node(void); static void tbbt_release_node(TBBT_NODE *nod); /* Returns pointer to end-most (to LEFT or RIGHT) node of tree: */ static TBBT_NODE * -tbbt_end(TBBT_NODE *root, intn side) +tbbt_end(TBBT_NODE *root, int side) { if (root == NULL) return NULL; while (HasChild(root, side)) { - root = root->link[side]; + root = root->Link[side]; } return root; } @@ -57,33 +132,20 @@ tbbtlast(TBBT_NODE *root) return tbbt_end(root, RIGHT); } -/* Return address of parent's pointer to neighboring node (to LEFT or RIGHT) ** - static TBBT_NODE **tbbt_anbr(TBBT_NODE *ptr, intn side ) - { - TBBT_NODE **aptr; - - if( ! HasChild( ptr, side ) ) - return( & ptr->link[side] ); - aptr= & ptr->link[side]; - while( HasChild( *aptr, Other(side) ) ) - aptr= & (*aptr)->link[Other(side)]; - return( aptr ); - } */ - /* Returns pointer to neighboring node (to LEFT or RIGHT): */ static TBBT_NODE * -tbbt_nbr(TBBT_NODE *ptr, intn side) +tbbt_nbr(TBBT_NODE *ptr, int side) { /* return( *tbbt_anbr(ptr,side) ); */ if (!HasChild(ptr, side)) - return ptr->link[side]; + return ptr->Link[side]; /* return NULL; */ - ptr = ptr->link[side]; + ptr = ptr->Link[side]; if (ptr == NULL) return NULL; while (HasChild(ptr, Other(side))) - ptr = ptr->link[Other(side)]; + ptr = ptr->Link[Other(side)]; return ptr; } @@ -105,21 +167,21 @@ tbbtprev(TBBT_NODE *node) /* tbbtffind is based on this routine - fix bugs in both places! */ /* Returns a pointer to the found node (or NULL) */ TBBT_NODE * -tbbtfind(TBBT_NODE *root, void *key, intn (*compar)(void *, void *, intn), intn arg, TBBT_NODE **pp) +tbbtfind(TBBT_NODE *root, void *key, int (*compar)(void *, void *, int), int arg, TBBT_NODE **pp) { TBBT_NODE *ptr = root; TBBT_NODE *parent = NULL; - intn cmp = 1; + int cmp = 1; if (ptr) { - intn side; + int side; while (0 != (cmp = KEYcmp(key, ptr->key, arg))) { parent = ptr; side = (cmp < 0) ? LEFT : RIGHT; if (!HasChild(ptr, side)) break; - ptr = ptr->link[side]; + ptr = ptr->Link[side]; } } if (NULL != pp) @@ -131,23 +193,23 @@ tbbtfind(TBBT_NODE *root, void *key, intn (*compar)(void *, void *, intn), intn /* This routine is based on tbbtfind (fix bugs in both places!) */ /* Returns a pointer to the found node (or NULL) */ static TBBT_NODE * -tbbtffind(TBBT_NODE *root, void *key, uintn fast_compare, TBBT_NODE **pp) +tbbtffind(TBBT_NODE *root, void *key, unsigned fast_compare, TBBT_NODE **pp) { TBBT_NODE *ptr = root; TBBT_NODE *parent = NULL; - intn cmp = 1; + int cmp = 1; switch (fast_compare) { case TBBT_FAST_UINT16_COMPARE: if (ptr) { - intn side; + int side; while (0 != (cmp = (*(uint16 *)key - *(uint16 *)ptr->key))) { parent = ptr; side = (cmp < 0) ? LEFT : RIGHT; if (!HasChild(ptr, side)) break; - ptr = ptr->link[side]; + ptr = ptr->Link[side]; } } if (NULL != pp) @@ -156,14 +218,14 @@ tbbtffind(TBBT_NODE *root, void *key, uintn fast_compare, TBBT_NODE **pp) case TBBT_FAST_INT32_COMPARE: if (ptr) { - intn side; + int side; while (0 != (cmp = (*(int32 *)key - *(int32 *)ptr->key))) { parent = ptr; side = (cmp < 0) ? LEFT : RIGHT; if (!HasChild(ptr, side)) break; - ptr = ptr->link[side]; + ptr = ptr->Link[side]; } } if (NULL != pp) @@ -182,31 +244,31 @@ tbbtdfind(TBBT_TREE *tree, void *key, TBBT_NODE **pp) { if (tree == NULL) return NULL; - if (tree->fast_compare != 0) - return tbbtffind(tree->root, key, tree->fast_compare, pp); + if (tree->Fast_compare != 0) + return tbbtffind(tree->root, key, tree->Fast_compare, pp); else - return tbbtfind(tree->root, key, tree->compar, tree->cmparg, pp); + return tbbtfind(tree->root, key, tree->Compar, tree->Cmparg, pp); } /* tbbtless -- Find a node in a tree which is less than a key, */ /* based on a key value */ /* Returns a pointer to the found node (or NULL) */ TBBT_NODE * -tbbtless(TBBT_NODE *root, void *key, intn (*compar)(void *, void *, intn), intn arg, TBBT_NODE **pp) +tbbtless(TBBT_NODE *root, void *key, int (*compar)(void *, void *, int), int arg, TBBT_NODE **pp) { TBBT_NODE *ptr = root; TBBT_NODE *parent = NULL; - intn cmp = 1; + int cmp = 1; if (ptr) { - intn side; + int side; while (0 != (cmp = KEYcmp(key, ptr->key, arg))) { parent = ptr; side = (cmp < 0) ? LEFT : RIGHT; if (!HasChild(ptr, side)) break; - ptr = ptr->link[side]; + ptr = ptr->Link[side]; } } if (cmp != 0) @@ -235,16 +297,11 @@ tbbtdless(TBBT_TREE *tree, void *key, TBBT_NODE **pp) { if (tree == NULL) return NULL; - return tbbtless(tree->root, key, tree->compar, tree->cmparg, pp); + return tbbtless(tree->root, key, tree->Compar, tree->Cmparg, pp); } /* tbbtindx -- Look up the Nth node (in key order) */ /* Returns a pointer to the `indx'th node (or NULL) */ -/* Bugs(fixed): - Added NULL check for 'ptr' in while loop to - prevent endless loop condition. - Fixed bug where we subtracted children count from the wrong side of the - tree. */ TBBT_NODE * tbbtindx(TBBT_NODE *root, int32 indx) { @@ -291,12 +348,12 @@ tbbtindx(TBBT_NODE *root, int32 indx) * pointers to children. */ static TBBT_NODE * -swapkid(TBBT_NODE **root, TBBT_NODE *ptr, intn side) +swapkid(TBBT_NODE **root, TBBT_NODE *ptr, int side) { - TBBT_NODE *kid = ptr->link[side]; /* Sibling to be swapped with parent */ - intn deep[3]; /* Relative depths of three sub-trees involved. */ - /* 0:ptr->link[Other(side)], 1:kid->link[Other(side)], 2:kid->link[side] */ - TBBT_FLAG ptrflg; /* New value for ptr->flags (ptr->flags used after set) */ + TBBT_NODE *kid = ptr->Link[side]; /* Sibling to be swapped with parent */ + int deep[3]; /* Relative depths of three sub-trees involved. */ + /* 0:ptr->Link[Other(side)], 1:kid->Link[Other(side)], 2:kid->Link[side] */ + TBBT_FLAG ptrflg; /* New value for ptr->Flags (ptr->Flags used after set) */ TBBT_LEAF plcnt, prcnt, /* current values of the ptr's and kid's leaf count */ klcnt, krcnt; @@ -310,11 +367,11 @@ swapkid(TBBT_NODE **root, TBBT_NODE *ptr, intn side) klcnt = LeftCnt(kid); krcnt = RightCnt(kid); if (HasChild(kid, Other(side))) { - ptr->link[side] = kid->link[Other(side)]; /* Real child */ - ptr->link[side]->Parent = ptr; + ptr->Link[side] = kid->Link[Other(side)]; /* Real child */ + ptr->Link[side]->Parent = ptr; } else { - ptr->link[side] = kid; /* Thread */ + ptr->Link[side] = kid; /* Thread */ } /* Update grand parent's pointer: */ if (NULL == ptr->Parent) { @@ -327,19 +384,19 @@ swapkid(TBBT_NODE **root, TBBT_NODE *ptr, intn side) ptr->Parent->Rchild = kid; } ptr->Parent = kid; - kid->link[Other(side)] = ptr; - kid->flags = (TBBT_FLAG)SetFlags(kid, Other(side), deep[2] - 1 - Max(deep[0], 0), HasChild(kid, side)); + kid->Link[Other(side)] = ptr; + kid->Flags = (TBBT_FLAG)SetFlags(kid, Other(side), deep[2] - 1 - Max(deep[0], 0), HasChild(kid, side)); /* update leaf counts */ if (side == LEFT) { /* kid's left count doesn't change, nor ptr's r-count */ - kid->rcnt = prcnt + krcnt + 1; /* kid's leafs+former parent's leafs+parent */ - ptr->lcnt = krcnt; + kid->Rcnt = prcnt + krcnt + 1; /* kid's leafs+former parent's leafs+parent */ + ptr->Lcnt = krcnt; } /* end if */ else { /* kid's right count doesn't change, nor ptr's l-count */ - kid->lcnt = plcnt + klcnt + 1; /* kid's leafs+former parent's leafs+parent */ - ptr->rcnt = klcnt; + kid->Lcnt = plcnt + klcnt + 1; /* kid's leafs+former parent's leafs+parent */ + ptr->Rcnt = klcnt; } /* end if */ - ptr->flags = ptrflg; + ptr->Flags = ptrflg; return kid; } @@ -348,36 +405,36 @@ swapkid(TBBT_NODE **root, TBBT_NODE *ptr, intn side) * balance through "rotation"s when needed. */ static void -balance(TBBT_NODE **root, TBBT_NODE *ptr, intn side, intn added) +balance(TBBT_NODE **root, TBBT_NODE *ptr, int side, int added) { - intn deeper = added; /* 1 if sub-tree got longer; -1 if got shorter */ - intn odelta; - intn obal; + int deeper = added; /* 1 if sub-tree got longer; -1 if got shorter */ + int odelta; + int obal; while (NULL != ptr) { odelta = Delta(ptr, side); /* delta before the node was added */ obal = UnBal(ptr); if (LEFT == side) /* One more/fewer left child: */ if (0 < added) - ptr->lcnt++; /* LeftCnt(ptr)++ */ + ptr->Lcnt++; /* LeftCnt(ptr)++ */ else - ptr->lcnt--; /* LeftCnt(ptr)-- */ + ptr->Lcnt--; /* LeftCnt(ptr)-- */ else if (0 < added) - ptr->rcnt++; /* RightCnt(ptr)++ */ + ptr->Rcnt++; /* RightCnt(ptr)++ */ else - ptr->rcnt--; /* RightCnt(ptr)-- */ + ptr->Rcnt--; /* RightCnt(ptr)-- */ if (0 != deeper) { /* One leg got longer or shorter: */ if ((deeper < 0 && odelta < 0) || (deeper > 0 && odelta > 0)) { /* Became too unbalanced: */ TBBT_NODE *kid; - ptr->flags |= TBBT_DOUBLE; /* Mark node too unbalanced */ + ptr->Flags |= TBBT_DOUBLE; /* Mark node too unbalanced */ if (deeper < 0) /* Just removed a node: */ side = Other(side); /* Swap with child from other side. */ else /* Just inserted a node: */ if (ptr->Parent && UnBal(ptr->Parent)) { deeper = 0; /* Fix will re-shorten sub-tree. */ } - kid = ptr->link[side]; + kid = ptr->Link[side]; if (Heavy(kid, Other(side))) { /* Double rotate needed: */ kid = swapkid(root, kid, Other(side)); ptr = swapkid(root, ptr, side); @@ -391,15 +448,15 @@ balance(TBBT_NODE **root, TBBT_NODE *ptr, intn side, intn added) } } else if (obal) { /* Just became balanced: */ - ptr->flags &= ~TBBT_UNBAL; + ptr->Flags &= ~TBBT_UNBAL; if (0 < deeper) { /* Shorter of legs lengthened */ - ptr->flags |= TBBT_INTERN; /* Mark as internal node now */ + ptr->Flags |= TBBT_INTERN; /* Mark as internal node now */ deeper = 0; /* so max length unchanged */ } /* end if */ } else if (deeper < 0) { /* Just became unbalanced: */ - if (ptr->link[Other(side)] != NULL && ptr->link[Other(side)]->Parent == ptr) { - ptr->flags |= (TBBT_FLAG)TBBT_HEAVY(Other(side)); /* Other side longer */ + if (ptr->Link[Other(side)] != NULL && ptr->Link[Other(side)]->Parent == ptr) { + ptr->Flags |= (TBBT_FLAG)TBBT_HEAVY(Other(side)); /* Other side longer */ if (ptr->Parent) if (ptr->Parent->Rchild == ptr) { /* we're the right child */ if (Heavy(ptr->Parent, RIGHT) && LeftCnt(ptr->Parent) == 1) @@ -412,7 +469,7 @@ balance(TBBT_NODE **root, TBBT_NODE *ptr, intn side, intn added) } } else { /* Just became unbalanced: */ - ptr->flags |= (TBBT_FLAG)TBBT_HEAVY(side); /* 0Flags |= (TBBT_FLAG)TBBT_HEAVY(side); /* 0Parent) { @@ -473,9 +530,9 @@ balance(TBBT_NODE **root, TBBT_NODE *ptr, intn side, intn added) /* Returns pointer to inserted node (or NULL) */ TBBT_NODE * tbbtins(TBBT_NODE **root, void *item, void *key, - intn (*compar)(void * /* k1 */, void * /* k2 */, intn /* arg */), intn arg) + int (*compar)(void * /* k1 */, void * /* k2 */, int /* arg */), int arg) { - intn cmp; + int cmp; TBBT_NODE *ptr, *parent; if (NULL != tbbtfind(*root, (key ? key : item), compar, arg, &parent) || NULL == (ptr = tbbt_get_node())) @@ -483,9 +540,9 @@ tbbtins(TBBT_NODE **root, void *item, void *key, ptr->data = item; ptr->key = key ? key : item; ptr->Parent = parent; - ptr->flags = 0L; /* No children on either side */ - ptr->lcnt = 0; - ptr->rcnt = 0; + ptr->Flags = 0L; /* No children on either side */ + ptr->Lcnt = 0; + ptr->Rcnt = 0; if (NULL == parent) { /* Adding first node to tree: */ *root = ptr; ptr->Lchild = ptr->Rchild = NULL; @@ -515,9 +572,9 @@ tbbtdins(TBBT_TREE *tree, void *item, void *key) if (tree == NULL) return NULL; - ret_node = tbbtins(&(tree->root), item, key, tree->compar, tree->cmparg); + ret_node = tbbtins(&(tree->root), item, key, tree->Compar, tree->Cmparg); if (ret_node != NULL) - tree->count++; + tree->Count++; return ret_node; } @@ -538,7 +595,7 @@ tbbtrem(TBBT_NODE **root, TBBT_NODE *node, void **kp) TBBT_NODE *leaf; /* Node with one or zero children */ TBBT_NODE *par; /* Parent of `leaf' */ TBBT_NODE *next; /* Next/prev node near `leaf' (`leaf's `side' thread) */ - intn side; /* `leaf' is `side' child of `par' */ + int side; /* `leaf' is `side' child of `par' */ void *data; /* Saved pointer to data item of deleted node */ if (NULL == root || NULL == node) @@ -565,7 +622,7 @@ tbbtrem(TBBT_NODE **root, TBBT_NODE *node, void **kp) par = leaf->Parent; if (par == next) { /* Case 2x: `node' had exactly 2 descendants */ side = Other(side); /* Transform this to Case 2 */ - next = leaf->link[side]; + next = leaf->Link[side]; } node->data = leaf->data; node->key = leaf->key; @@ -573,12 +630,12 @@ tbbtrem(TBBT_NODE **root, TBBT_NODE *node, void **kp) else { /* Node has one or zero children: */ leaf = node; /* Simply remove THIS node */ par = leaf->Parent; - if (NULL == par) { /* Case 3: Remove root (of 1- or 2-node tree) */ - side = (intn)UnBal(node); /* Which side root has a child on */ - if (side) { /* Case 3a: Remove root of 2-node tree: */ - *root = leaf = node->link[side]; - leaf->Parent = leaf->link[Other(side)] = NULL; - leaf->flags = 0; /* No left children, balanced, not internal */ + if (NULL == par) { /* Case 3: Remove root (of 1- or 2-node tree) */ + side = (int)UnBal(node); /* Which side root has a child on */ + if (side) { /* Case 3a: Remove root of 2-node tree: */ + *root = leaf = node->Link[side]; + leaf->Parent = leaf->Link[Other(side)] = NULL; + leaf->Flags = 0; /* No left children, balanced, not internal */ } else { /* Case 3b: Remove last node of tree: */ *root = NULL; @@ -587,7 +644,7 @@ tbbtrem(TBBT_NODE **root, TBBT_NODE *node, void **kp) return data; } side = (par->Rchild == leaf) ? RIGHT : LEFT; - next = leaf->link[side]; + next = leaf->Link[side]; } /* Now the deletion has been reduced to the following cases (and Case 3 has * been handled completely above and Case 2x has been transformed into @@ -611,53 +668,61 @@ tbbtrem(TBBT_NODE **root, TBBT_NODE *node, void **kp) * the root falls into Case 3a while removing the only leaf falls into * Case 2 (with `next' NULL and `par' the root node). */ if (!UnBal(leaf)) { /* Case 2: `leaf' has no children: */ - par->link[side] = leaf->link[side]; - par->flags &= (TBBT_FLAG)(~(TBBT_INTERN | TBBT_HEAVY(side))); + par->Link[side] = leaf->Link[side]; + par->Flags &= (TBBT_FLAG)(~(TBBT_INTERN | TBBT_HEAVY(side))); } else { /* Case 1: `leaf' has one child: */ TBBT_NODE *n; if (HasChild(leaf, side)) { /* two-in-a-row cases */ - n = leaf->link[side]; - par->link[side] = n; + n = leaf->Link[side]; + par->Link[side] = n; n->Parent = par; if (HasChild(n, Other(side))) while (HasChild(n, Other(side))) - n = n->link[Other(side)]; - n->link[Other(side)] = par; + n = n->Link[Other(side)]; + n->Link[Other(side)] = par; } /* end if */ else { /* zig-zag cases */ - n = leaf->link[Other(side)]; - par->link[side] = n; + n = leaf->Link[Other(side)]; + par->Link[side] = n; n->Parent = par; if (HasChild(n, side)) while (HasChild(n, side)) - n = n->link[side]; - n->link[side] = next; + n = n->Link[side]; + n->Link[side] = next; } /* end else */ } tbbt_release_node(leaf); balance(root, par, side, -1); - ((TBBT_TREE *)root)->count--; + ((TBBT_TREE *)root)->Count--; return data; } /* tbbtdmake - Allocate a new tree description record for an empty tree */ /* Returns a pointer to the description record */ TBBT_TREE * -tbbtdmake(intn (*cmp)(void * /* k1 */, void * /* k2 */, intn /* arg */), intn arg, uintn fast_compare) +tbbtdmake(int (*cmp)(void * /* k1 */, void * /* k2 */, int /* arg */), int arg, unsigned fast_compare) { - TBBT_TREE *tree = malloc(sizeof(TBBT_TREE)); - if (NULL == tree) - return NULL; + TBBT_TREE *tree = NULL; + + if (NULL == (tree = (TBBT_TREE *)calloc(1, sizeof(TBBT_TREE)))) + goto error; + if (NULL == (tree->priv = (TBBT_TREE_PRIV *)calloc(1, sizeof(TBBT_TREE_PRIV)))) + goto error; tree->root = NULL; - tree->count = 0; - tree->fast_compare = fast_compare; - tree->compar = cmp; - tree->cmparg = arg; + tree->Count = 0; + tree->Fast_compare = fast_compare; + tree->Compar = cmp; + tree->Cmparg = arg; return tree; +error: + if (tree) + free(tree->priv); + free(tree); + return NULL; } /* tbbtfree() - Free an entire tree not allocated with tbbtdmake(). */ @@ -705,15 +770,15 @@ tbbtprint(TBBT_NODE *node) if (node == NULL) return; printf("node=%p, key=%p, data=%p, flags=%x\n", (void *)node, node->key, node->data, - (unsigned)node->flags); - printf("Lcnt=%d, Rcnt=%d\n", (int)node->lcnt, (int)node->rcnt); + (unsigned)node->Flags); + printf("Lcnt=%d, Rcnt=%d\n", (int)node->Lcnt, (int)node->Rcnt); printf("*key=%d\n", (int)*(int32 *)(node->key)); printf("Lchild=%p, Rchild=%p, Parent=%p\n", (void *)node->Lchild, (void *)node->Rchild, (void *)node->Parent); } /* end tbbtprint() */ void -tbbt1dump(TBBT_NODE *node, intn method) +tbbt1dump(TBBT_NODE *node, int method) { if (node == NULL) return; @@ -747,10 +812,10 @@ tbbt1dump(TBBT_NODE *node, intn method) } /* end tbbt1dump() */ void -tbbtdump(TBBT_TREE *tree, intn method) +tbbtdump(TBBT_TREE *tree, int method) { if (tree != NULL && *(TBBT_NODE **)tree != NULL) { - printf("Number of nodes in the tree: %ld\n", tree->count); + printf("Number of nodes in the tree: %ld\n", tree->Count); tbbt1dump(tree->root, method); } /* end if */ else @@ -765,8 +830,8 @@ tbbt_printNode(TBBT_NODE *node, void (*key_dump)(void *, void *)) printf("ERROR: null node pointer\n"); return; } - printf("node=%p, flags=%x, Lcnt=%ld, Rcnt=%ld\n", (void *)node, (unsigned)node->flags, (long)node->lcnt, - (long)node->rcnt); + printf("node=%p, flags=%x, Lcnt=%ld, Rcnt=%ld\n", (void *)node, (unsigned)node->Flags, (long)node->Lcnt, + (long)node->Rcnt); printf("Lchild=%p, Rchild=%p, Parent=%p\n", (void *)node->Lchild, (void *)node->Rchild, (void *)node->Parent); if (key_dump != NULL) { @@ -776,7 +841,7 @@ tbbt_printNode(TBBT_NODE *node, void (*key_dump)(void *, void *)) } /* end tbbt_printNode() */ void -tbbt_dumpNode(TBBT_NODE *node, void (*key_dump)(void *, void *), intn method) +tbbt_dumpNode(TBBT_NODE *node, void (*key_dump)(void *, void *), int method) { if (node == NULL) return; @@ -810,13 +875,13 @@ tbbt_dumpNode(TBBT_NODE *node, void (*key_dump)(void *, void *), intn method) } /* end tbbt_dumpNode() */ void -tbbt_dump(TBBT_TREE *ptree, void (*key_dump)(void *, void *), intn method) +tbbt_dump(TBBT_TREE *ptree, void (*key_dump)(void *, void *), int method) { TBBT_TREE *tree; tree = (TBBT_TREE *)ptree; printf("TBBT-tree dump %p:\n\n", (void *)ptree); - printf("capacity = %ld\n", (long)tree->count); + printf("capacity = %ld\n", (long)tree->Count); printf("\n"); tbbt_dumpNode(tree->root, key_dump, method); } @@ -829,6 +894,7 @@ tbbtdfree(TBBT_TREE *tree, void (*fd)(void * /* item */), void (*fk)(void * /* k return NULL; tbbtfree(&tree->root, fd, fk); + free(tree->priv); free(tree); return NULL; } @@ -840,7 +906,7 @@ tbbtcount(TBBT_TREE *tree) if (tree == NULL) return -1; else - return (long)tree->count; + return (long)tree->Count; } /****************************************************************************** @@ -864,10 +930,19 @@ tbbt_get_node(void) ret_value = tbbt_free_list; tbbt_free_list = tbbt_free_list->Lchild; } - else - ret_value = malloc(sizeof(TBBT_NODE)); + else { + if (NULL == (ret_value = (TBBT_NODE *)calloc(1, sizeof(TBBT_NODE)))) + goto error; + if (NULL == (ret_value->priv = (TBBT_NODE_PRIV *)calloc(1, sizeof(TBBT_NODE_PRIV)))) + goto error; + } return ret_value; +error: + if (ret_value) + free(ret_value->priv); + free(ret_value); + return NULL; } /* end tbbt_get_node() */ /****************************************************************************** @@ -895,7 +970,7 @@ tbbt_release_node(TBBT_NODE *nod) PURPOSE Terminate various static buffers. USAGE - intn tbbt_shutdown() + int tbbt_shutdown() RETURNS Returns SUCCEED/FAIL DESCRIPTION @@ -906,7 +981,7 @@ tbbt_release_node(TBBT_NODE *nod) EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -intn +int tbbt_shutdown(void) { TBBT_NODE *curr; @@ -916,6 +991,7 @@ tbbt_shutdown(void) while (tbbt_free_list != NULL) { curr = tbbt_free_list; tbbt_free_list = tbbt_free_list->Lchild; + free(curr->priv); free(curr); } } diff --git a/hdf/src/tbbt.h b/hdf/src/tbbt.h index 481af1e6c1..b9edc0355a 100644 --- a/hdf/src/tbbt.h +++ b/hdf/src/tbbt.h @@ -19,87 +19,45 @@ #include "hdfi.h" -typedef struct tbbt_node TBBT_NODE; +/* Define the "fast compare" values */ +#define TBBT_FAST_UINT16_COMPARE 1 +#define TBBT_FAST_INT32_COMPARE 2 + +/* Private TBBT information (defined in tbbt.c) */ +struct tbbt_node_private; + +/* Private TBBT node information (defined in tbbt.c) */ +struct tbbt_tree_private; /* Threaded node structure */ -struct tbbt_node { +typedef struct tbbt_node { void *data; /* Pointer to user data to be associated with node */ void *key; /* Field to sort nodes on */ -#ifdef TBBT_INTERNALS -#define PARENT 0 -#define LEFT 1 -#define RIGHT 2 - TBBT_NODE *link[3]; /* Pointers to parent, left child, and right child */ -#define Parent link[PARENT] -#define Lchild link[LEFT] -#define Rchild link[RIGHT] -#define TBBT_FLAG unsigned long -#define TBBT_LEAF unsigned long - TBBT_FLAG flags; /* Combination of the following bit fields: */ -#define TBBT_HEAVY(s) s /* If the `s' sub-tree is deeper than the other */ -#define TBBT_DOUBLE 4 /* If "heavy" sub-tree is two levels deeper */ -#define TBBT_INTERN 8 /* If node is internal (has two children) */ -#define TBBT_UNBAL (TBBT_HEAVY(LEFT) | TBBT_HEAVY(RIGHT)) -#define TBBT_FLAGS (TBBT_UNBAL | TBBT_INTERN | TBBT_DOUBLE) -#define TBBT_CHILD(s) (TBBT_INTERN | TBBT_HEAVY(s)) - TBBT_LEAF lcnt; /* count of left children */ - TBBT_LEAF rcnt; /* count of right children */ -#define LeftCnt(node) ((node)->lcnt) /* Left descendants */ -#define RightCnt(node) ((node)->rcnt) /* Left descendants */ -#define Cnt(node, s) (LEFT == (s) ? LeftCnt(node) : RightCnt(node)) -#define HasChild(n, s) (Cnt(n, s) > 0) -#define Heavy(n, s) ((s) & (LeftCnt(n) > RightCnt(n) ? LEFT : LeftCnt(n) == RightCnt(n) ? 0 : RIGHT)) -#define Intern(n) (LeftCnt(n) && RightCnt(n)) -#define UnBal(n) (LeftCnt(n) > RightCnt(n) ? LEFT : LeftCnt(n) == RightCnt(n) ? 0 : RIGHT) -#define Double(n) (TBBT_DOUBLE & (n)->flags) -#define Other(side) (LEFT + RIGHT - (side)) -#define Delta(n, s) ((Heavy(n, s) ? 1 : -1) * (Double(n) ? 2 : UnBal(n) ? 1 : 0)) -#define SetFlags(n, s, b, i) \ - ((-2 < (b) && (b) < 2 ? 0 : TBBT_DOUBLE) | \ - (0 > (b) ? TBBT_HEAVY(s) \ - : (b) > 0 ? TBBT_HEAVY(Other(s)) \ - : 0) | \ - ((i) ? TBBT_INTERN : 0)) -}; - -/* Pointer to the tbbt node free list */ -static TBBT_NODE *tbbt_free_list = NULL; + struct tbbt_node_private *priv; /* Private information about the TBBT node */ +} TBBT_NODE; -typedef struct tbbt_tree TBBT_TREE; /* Threaded tree structure */ -struct tbbt_tree { - TBBT_NODE *root; - unsigned long count; /* The number of nodes in the tree currently */ - uintn fast_compare; /* use a faster in-line compare (with casts) instead of function call */ - intn (*compar)(void *k1, void *k2, intn cmparg); - intn cmparg; -#endif /* TBBT_INTERNALS */ -}; +typedef struct tbbt_tree { + TBBT_NODE *root; -/* Define the "fast compare" values */ -#define TBBT_FAST_UINT16_COMPARE 1 -#define TBBT_FAST_INT32_COMPARE 2 - -#ifndef TBBT_INTERNALS -typedef TBBT_NODE **TBBT_TREE; -#endif /* TBBT_INTERNALS */ - -/* Return maximum of two scalar values (use arguments w/o side effects): */ -#define Max(a, b) ((a) > (b) ? (a) : (b)) + struct tbbt_tree_private *priv; /* Private information about the TBBT */ +} TBBT_TREE; /* These routines are designed to allow use of a general-purpose balanced tree * implementation. These trees are appropriate for maintaining in memory one * or more lists of items, each list sorted according to key values (key values * must form a "completely ordered set") where no two items in a single list * can have the same key value. The following operations are supported: - * Create an empty list - * Add an item to a list - * Look up an item in a list by key value - * Look up the Nth item in a list - * Delete an item from a list - * Find the first/last/next/previous item in a list - * Destroy a list + * + * - Create an empty list + * - Add an item to a list + * - Look up an item in a list by key value + * - Look up the Nth item in a list + * - Delete an item from a list + * - Find the first/last/next/previous item in a list + * - Destroy a list + * * Each of the above operations requires Order(log(N)) time where N is the * number of items in the list (except for list creation which requires * constant time and list destruction which requires Order(N) time if the user- @@ -139,7 +97,7 @@ typedef TBBT_NODE **TBBT_TREE; extern "C" { #endif -HDFLIBAPI TBBT_TREE *tbbtdmake(intn (*compar)(void *, void *, intn), intn arg, uintn fast_compare); +HDFLIBAPI TBBT_TREE *tbbtdmake(int (*compar)(void *, void *, int), int arg, unsigned fast_compare); /* Allocates and initializes an empty threaded, balanced, binary tree and * returns a pointer to the control structure for it. You can also create * empty trees without this function as long as you never use tbbtd* routines @@ -201,10 +159,10 @@ HDFLIBAPI TBBT_TREE *tbbtdmake(intn (*compar)(void *, void *, intn), intn arg, u */ HDFLIBAPI TBBT_NODE *tbbtdfind(TBBT_TREE *tree, void *key, TBBT_NODE **pp); -HDFLIBAPI TBBT_NODE *tbbtfind(TBBT_NODE *root, void *key, intn (*cmp)(void *, void *, intn), intn arg, +HDFLIBAPI TBBT_NODE *tbbtfind(TBBT_NODE *root, void *key, int (*cmp)(void *, void *, int), int arg, TBBT_NODE **pp); HDFLIBAPI TBBT_NODE *tbbtdless(TBBT_TREE *tree, void *key, TBBT_NODE **pp); -HDFLIBAPI TBBT_NODE *tbbtless(TBBT_NODE *root, void *key, intn (*cmp)(void *, void *, intn), intn arg, +HDFLIBAPI TBBT_NODE *tbbtless(TBBT_NODE *root, void *key, int (*cmp)(void *, void *, int), int arg, TBBT_NODE **pp); /* Locate a node based on the key given. A pointer to the node in the tree * with a key value matching `key' is returned. If no such node exists, NULL @@ -228,8 +186,8 @@ HDFLIBAPI TBBT_NODE *tbbtindx(TBBT_NODE *root, int32 indx); */ HDFLIBAPI TBBT_NODE *tbbtdins(TBBT_TREE *tree, void *item, void *key); -HDFLIBAPI TBBT_NODE *tbbtins(TBBT_NODE **root, void *item, void *key, intn (*cmp)(void *, void *, intn), - intn arg); +HDFLIBAPI TBBT_NODE *tbbtins(TBBT_NODE **root, void *item, void *key, int (*cmp)(void *, void *, int), + int arg); /* Insert a new node to the tree having a key value of `key' and a data pointer * of `item'. If a node already exists in the tree with key value `key' or if * malloc() fails, NULL is returned (no node is inserted), otherwise a pointer @@ -280,7 +238,7 @@ HDFLIBAPI void tbbtfree(TBBT_NODE **root, void (*fd)(void *), void (*fk)(v HDFLIBAPI void tbbtprint(TBBT_NODE *node); /* Prints out the data in a node */ -HDFLIBAPI void tbbtdump(TBBT_TREE *tree, intn method); +HDFLIBAPI void tbbtdump(TBBT_TREE *tree, int method); /* Prints an entire tree. The method variable determines which sort of * traversal is used: * -1 : Pre-Order Traversal @@ -291,7 +249,7 @@ HDFLIBAPI void tbbtdump(TBBT_TREE *tree, intn method); HDFLIBAPI long tbbtcount(TBBT_TREE *tree); /* Terminate the buffers used in the tbbt*() interface */ -HDFPUBLIC intn tbbt_shutdown(void); +HDFPUBLIC int tbbt_shutdown(void); #ifdef __cplusplus } diff --git a/hdf/src/vgp.c b/hdf/src/vgp.c index 3730ab2c8b..3a7bbc3f64 100644 --- a/hdf/src/vgp.c +++ b/hdf/src/vgp.c @@ -2291,7 +2291,7 @@ Vgetid(HFILEID f, /* IN: file handle */ if (vf->vgtree == NULL) HGOTO_DONE(FAIL); /* just return FAIL, no error */ - if (NULL == (t = (void **)tbbtfirst((TBBT_NODE *)*(vf->vgtree)))) + if (NULL == (t = (void **)tbbtfirst(vf->vgtree->root))) HGOTO_DONE(FAIL); /* just return FAIL, no error */ /* t is assumed to valid at this point */ @@ -2305,8 +2305,8 @@ Vgetid(HFILEID f, /* IN: file handle */ key = (int32)vgid; t = (void **)tbbtdfind(vf->vgtree, (void *)&key, NULL); - if (t == NULL || t == (void **)tbbtlast((TBBT_NODE *)*( - vf->vgtree))) { /* couldn't find the old vgid or at the end */ + if (t == NULL || t == (void **)tbbtlast(vf->vgtree->root)) { + /* couldn't find the old vgid or at the end */ ret_value = (FAIL); } else if (NULL == (t = (void **)tbbtnext((TBBT_NODE *)t))) /* get the next node in the tree */ diff --git a/hdf/src/vio.c b/hdf/src/vio.c index f2b3079f8b..df00da3351 100644 --- a/hdf/src/vio.c +++ b/hdf/src/vio.c @@ -1174,7 +1174,7 @@ VSgetid(HFILEID f, /* IN: file handle */ if (vf->vstree == NULL) HGOTO_DONE(FAIL); - if ((t = (void **)tbbtfirst((TBBT_NODE *)*(vf->vstree))) == NULL) + if ((t = (void **)tbbtfirst(vf->vstree->root)) == NULL) HGOTO_DONE(FAIL); /* we assume 't' is valid at this point */