summaryrefslogtreecommitdiffstats
path: root/src/H5B.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-05-31 20:01:29 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-05-31 20:01:29 (GMT)
commitb4ac48552d74bcd4ad465d61d2fa294420f2525d (patch)
tree7925b715974b10b69bc2662c2045eb8281f1b726 /src/H5B.c
parentfbe777b67a3b859d6688111a43f24444cff7d335 (diff)
downloadhdf5-b4ac48552d74bcd4ad465d61d2fa294420f2525d.zip
hdf5-b4ac48552d74bcd4ad465d61d2fa294420f2525d.tar.gz
hdf5-b4ac48552d74bcd4ad465d61d2fa294420f2525d.tar.bz2
[svn-r8601] Purpose:
Code optimization & cleanup Description: Don't recompute the internal index value for looking up the chunk in the hash table, just use the value already computed from iterating through the chunks. Also, back-port some of the various cleanups to the source code from the development branch, to make diffing the code easier. Platforms tested: Solaris 2.7 (arabica) FreeBSD 4.9 (sleipnir) w/parallel
Diffstat (limited to 'src/H5B.c')
-rw-r--r--src/H5B.c560
1 files changed, 284 insertions, 276 deletions
diff --git a/src/H5B.c b/src/H5B.c
index ccc1f425..cf285fa 100644
--- a/src/H5B.c
+++ b/src/H5B.c
@@ -118,9 +118,6 @@
#include "H5Pprivate.h" /* Property lists */
/* Local macros */
-
-#define BOUND(MIN,X,MAX) ((X)<(MIN)?(MIN):((X)>(MAX)?(MAX):(X)))
-
#define H5B_SIZEOF_HDR(F) \
(H5B_SIZEOF_MAGIC + /*magic number */ \
4 + /*type, level, num entries */ \
@@ -137,17 +134,17 @@ static H5B_ins_t H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr,
uint8_t *rt_key,
hbool_t *rt_key_changed,
haddr_t *retval);
-static herr_t H5B_insert_child(H5F_t *f, const H5B_class_t *type,
- H5B_t *bt, int idx, haddr_t child,
- H5B_ins_t anchor, void *md_key);
-static herr_t H5B_decode_key(H5F_t *f, H5B_t *bt, int idx);
-static herr_t H5B_decode_keys(H5F_t *f, H5B_t *bt, int idx);
-static size_t H5B_nodesize(H5F_t *f, const H5B_class_t *type,
+static herr_t H5B_insert_child(const H5F_t *f, const H5B_class_t *type,
+ H5B_t *bt, unsigned idx, haddr_t child,
+ H5B_ins_t anchor, const void *md_key);
+static herr_t H5B_decode_key(H5F_t *f, H5B_t *bt, unsigned idx);
+static herr_t H5B_decode_keys(H5F_t *f, H5B_t *bt, unsigned idx);
+static size_t H5B_nodesize(const H5F_t *f, const H5B_class_t *type,
size_t *total_nkey_size, size_t sizeof_rkey);
static herr_t H5B_split(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_t *old_bt,
- haddr_t old_addr, int idx,
- void *udata, haddr_t *new_addr/*out*/);
-static H5B_t * H5B_copy(H5F_t *f, const H5B_t *old_bt);
+ haddr_t old_addr, unsigned idx,
+ void *udata, haddr_t *new_addr/*out*/);
+static H5B_t * H5B_copy(const H5F_t *f, const H5B_t *old_bt);
#ifdef H5B_DEBUG
static herr_t H5B_assert(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type,
void *udata);
@@ -217,13 +214,13 @@ H5B_create(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, void *udata,
{
H5B_t *bt = NULL;
size_t sizeof_rkey;
- size_t size;
+ size_t size=0;
size_t total_native_keysize;
size_t offset;
- int i;
+ unsigned u;
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI(H5B_create, FAIL);
+ FUNC_ENTER_NOAPI(H5B_create, FAIL)
/*
* Check arguments.
@@ -239,9 +236,9 @@ H5B_create(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, void *udata,
size = H5B_nodesize(f, type, &total_native_keysize, sizeof_rkey);
H5_CHECK_OVERFLOW(size,size_t,hsize_t);
if (HADDR_UNDEF==(*addr_p=H5MF_alloc(f, H5FD_MEM_BTREE, dxpl_id, (hsize_t)size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for B-tree root node");
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "file allocation failed for B-tree root node")
if (NULL==(bt = H5FL_CALLOC(H5B_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree root node");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree root node")
bt->type = type;
bt->sizeof_rkey = sizeof_rkey;
bt->cache_info.dirty = TRUE;
@@ -254,21 +251,21 @@ H5B_create(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, void *udata,
NULL==(bt->native=H5FL_BLK_MALLOC(native_block,total_native_keysize)) ||
NULL==(bt->child=H5FL_SEQ_MALLOC(haddr_t,(size_t)(2*H5F_KVALUE(f,type)))) ||
NULL==(bt->key=H5FL_SEQ_MALLOC(H5B_key_t,(size_t)(2*H5F_KVALUE(f,type)+1))))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree root node");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for B-tree root node")
/*
* Initialize each entry's raw child and key pointers to point into the
* `page' buffer. Each native key pointer should be null until the key is
* translated to native format.
*/
- for (i = 0, offset = H5B_SIZEOF_HDR(f);
- i < 2 * H5F_KVALUE(f, type);
- i++, offset += bt->sizeof_rkey + H5F_SIZEOF_ADDR(f)) {
-
- bt->key[i].dirty = FALSE;
- bt->key[i].rkey = bt->page + offset;
- bt->key[i].nkey = NULL;
- bt->child[i] = HADDR_UNDEF;
+ for (u = 0, offset = H5B_SIZEOF_HDR(f);
+ u < 2 * H5F_KVALUE(f, type);
+ u++, offset += bt->sizeof_rkey + H5F_SIZEOF_ADDR(f)) {
+
+ bt->key[u].dirty = FALSE;
+ bt->key[u].rkey = bt->page + offset;
+ bt->key[u].nkey = NULL;
+ bt->child[u] = HADDR_UNDEF;
}
/*
@@ -282,21 +279,23 @@ H5B_create(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, void *udata,
* Cache the new B-tree node.
*/
if (H5AC_set(f, dxpl_id, H5AC_BT, *addr_p, bt) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "can't add B-tree root node to cache");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "can't add B-tree root node to cache")
#ifdef H5B_DEBUG
H5B_assert(f, dxpl_id, *addr_p, type, udata);
#endif
done:
if (ret_value<0) {
- H5_CHECK_OVERFLOW(size,size_t,hsize_t);
- H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, *addr_p, (hsize_t)size);
+ if(size>0) {
+ H5_CHECK_OVERFLOW(size,size_t,hsize_t);
+ (void)H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, *addr_p, (hsize_t)size);
+ } /* end if */
if (bt)
- H5B_dest(f,bt);
+ (void)H5B_dest(f,bt);
}
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /*lint !e818 Can't make udata a pointer to const */
/*-------------------------------------------------------------------------
@@ -328,11 +327,11 @@ H5B_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata)
size_t total_nkey_size;
size_t size;
H5B_t *bt = NULL;
- int i;
uint8_t *p;
+ unsigned u; /* Local index variable */
H5B_t *ret_value;
- FUNC_ENTER_NOAPI(H5B_load, NULL);
+ FUNC_ENTER_NOAPI(H5B_load, NULL)
/* Check arguments */
assert(f);
@@ -341,7 +340,7 @@ H5B_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata)
assert(type->get_sizeof_rkey);
if (NULL==(bt = H5FL_CALLOC(H5B_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
bt->sizeof_rkey = (type->get_sizeof_rkey) (f, udata);
size = H5B_nodesize(f, type, &total_nkey_size, bt->sizeof_rkey);
bt->type = type;
@@ -351,19 +350,19 @@ H5B_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata)
NULL==(bt->native=H5FL_BLK_MALLOC(native_block,total_nkey_size)) ||
NULL==(bt->key=H5FL_SEQ_MALLOC(H5B_key_t,(size_t)(2*H5F_KVALUE(f,type)+1))) ||
NULL==(bt->child=H5FL_SEQ_MALLOC(haddr_t,(size_t)(2*H5F_KVALUE(f,type)))))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
if (H5F_block_read(f, H5FD_MEM_BTREE, addr, size, dxpl_id, bt->page)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_READERROR, NULL, "can't read B-tree node")
p = bt->page;
/* magic number */
if (HDmemcmp(p, H5B_MAGIC, H5B_SIZEOF_MAGIC))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree signature");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree signature")
p += 4;
/* node type and level */
if (*p++ != type->id)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "incorrect B-tree node level");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "incorrect B-tree node type")
bt->level = *p++;
/* entries used */
@@ -374,17 +373,17 @@ H5B_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata)
H5F_addr_decode(f, (const uint8_t **) &p, &(bt->right));
/* the child/key pairs */
- for (i = 0; i < 2 * H5F_KVALUE(f, type); i++) {
+ for (u = 0; u < 2 * H5F_KVALUE(f, type); u++) {
- bt->key[i].dirty = FALSE;
- bt->key[i].rkey = p;
+ bt->key[u].dirty = FALSE;
+ bt->key[u].rkey = p;
p += bt->sizeof_rkey;
- bt->key[i].nkey = NULL;
+ bt->key[u].nkey = NULL;
- if (i < bt->nchildren) {
- H5F_addr_decode(f, (const uint8_t **) &p, bt->child + i);
+ if (u < bt->nchildren) {
+ H5F_addr_decode(f, (const uint8_t **) &p, bt->child + u);
} else {
- bt->child[i] = HADDR_UNDEF;
+ bt->child[u] = HADDR_UNDEF;
p += H5F_SIZEOF_ADDR(f);
}
}
@@ -398,9 +397,9 @@ H5B_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, void *udata)
done:
if (!ret_value && bt)
- H5B_dest(f,bt);
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ (void)H5B_dest(f,bt);
+ FUNC_LEAVE_NOAPI(ret_value)
+} /*lint !e818 Can't make udata a pointer to const */
/*-------------------------------------------------------------------------
@@ -429,16 +428,14 @@ done:
static herr_t
H5B_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B_t *bt)
{
- int i;
+ unsigned i;
size_t size = 0;
uint8_t *p = bt->page;
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5B_flush, FAIL);
+ FUNC_ENTER_NOAPI(H5B_flush, FAIL)
- /*
- * Check arguments.
- */
+ /* check arguments */
assert(f);
assert(H5F_addr_defined(addr));
assert(bt);
@@ -488,22 +485,22 @@ H5B_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B_t *bt)
}
/*
- * Write the disk page. We always write the header, but we don't
- * bother writing data for the child entries that don't exist or
- * for the final unchanged children.
+ * Write the disk page. We always write the header, but we don't
+ * bother writing data for the child entries that don't exist or
+ * for the final unchanged children.
*/
if (H5F_block_write(f, H5FD_MEM_BTREE, addr, size, dxpl_id, bt->page)<0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTFLUSH, FAIL, "unable to save B-tree node to disk");
bt->cache_info.dirty = FALSE;
bt->ndirty = 0;
}
- if (destroy) {
- if(H5B_dest(f,bt)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree node");
- }
+
+ if (destroy)
+ if (H5B_dest(f,bt) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to destroy B-tree node")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -522,10 +519,11 @@ done:
*
*-------------------------------------------------------------------------
*/
+/* ARGSUSED */
static herr_t
H5B_dest(H5F_t UNUSED *f, H5B_t *bt)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B_dest);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B_dest)
/*
* Check arguments.
@@ -541,7 +539,7 @@ H5B_dest(H5F_t UNUSED *f, H5B_t *bt)
H5FL_BLK_FREE(native_block,bt->native);
H5FL_FREE(H5B_t,bt);
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5B_dest() */
@@ -563,9 +561,9 @@ H5B_dest(H5F_t UNUSED *f, H5B_t *bt)
static herr_t
H5B_clear(H5B_t *bt)
{
- int i; /* Local index variable */
+ unsigned u; /* Local index variable */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B_clear);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B_clear)
/*
* Check arguments.
@@ -573,11 +571,11 @@ H5B_clear(H5B_t *bt)
assert(bt);
/* Look for dirty keys and reset the dirty flag. */
- for (i=0; i<=bt->nchildren; i++)
- bt->key[i].dirty = FALSE;
+ for (u=0; u<=bt->nchildren; u++)
+ bt->key[u].dirty = FALSE;
bt->cache_info.dirty = FALSE;
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5B_clear() */
@@ -611,10 +609,11 @@ herr_t
H5B_find(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void *udata)
{
H5B_t *bt = NULL;
- int idx = -1, lt = 0, rt, cmp = 1;
+ unsigned idx=0, lt = 0, rt; /* Final, left & right key indices */
+ int cmp = 1; /* Key comparison value */
int ret_value = SUCCEED;
- FUNC_ENTER_NOAPI(H5B_find, FAIL);
+ FUNC_ENTER_NOAPI(H5B_find, FAIL)
/*
* Check arguments.
@@ -631,13 +630,13 @@ H5B_find(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void *u
* the thing for which we're searching.
*/
if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node")
rt = bt->nchildren;
while (lt < rt && cmp) {
idx = (lt + rt) / 2;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode B-tree key(s)");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode B-tree key(s)")
/* compare */
if ((cmp = (type->cmp3) (f, dxpl_id, bt->key[idx].nkey, udata,
bt->key[idx+1].nkey)) < 0) {
@@ -647,25 +646,25 @@ H5B_find(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void *u
}
}
if (cmp)
- HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "B-tree key not found");
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "B-tree key not found")
/*
* Follow the link to the subtree or to the data node.
*/
- assert(idx >= 0 && idx < bt->nchildren);
+ assert(idx < bt->nchildren);
if (bt->level > 0) {
if (H5B_find(f, dxpl_id, type, bt->child[idx], udata) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "key not found in subtree");
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "key not found in subtree")
} else {
if ((type->found) (f, dxpl_id, bt->child[idx], bt->key[idx].nkey, udata, bt->key[idx+1].nkey) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "key not found in leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "key not found in leaf node")
}
done:
- if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BT, addr, bt, FALSE) < 0 && ret_value>=0)
- HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release node");
+ if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BT, addr, bt, FALSE) < 0)
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release node")
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -697,16 +696,18 @@ done:
*/
static herr_t
H5B_split(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_t *old_bt, haddr_t old_addr,
- int idx, void *udata, haddr_t *new_addr_p/*out*/)
+ unsigned idx, void *udata, haddr_t *new_addr_p/*out*/)
{
H5P_genplist_t *dx_plist; /* Data transfer property list */
H5B_t *new_bt = NULL, *tmp_bt = NULL;
- herr_t ret_value = SUCCEED;
- int i, k, nleft, nright;
- double split_ratios[3]; /* B-tree split ratios */
+ unsigned k; /* B-tree 'K' value for the maximum number of entries in node */
+ unsigned nleft, nright; /* Number of keys in left & right halves */
size_t recsize = 0;
+ double split_ratios[3]; /* B-tree split ratios */
+ unsigned u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5B_split);
+ FUNC_ENTER_NOAPI_NOINIT(H5B_split)
/*
* Check arguments.
@@ -744,7 +745,7 @@ H5B_split(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_t *old_bt, haddr
} else {
side = "MIDDLE";
}
- fprintf(H5DEBUG(B), "H5B_split: %3d {%5.3f,%5.3f,%5.3f} %6s",
+ fprintf(H5DEBUG(B), "H5B_split: %3u {%5.3f,%5.3f,%5.3f} %6s",
2*k, split_ratios[0], split_ratios[1], split_ratios[2], side);
}
#endif
@@ -754,11 +755,11 @@ H5B_split(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_t *old_bt, haddr
* and the new node.
*/
if (!H5F_addr_defined(old_bt->right)) {
- nleft = (int)(2 * k * split_ratios[2]); /*right*/
+ nleft = (unsigned)(2 * (double)k * split_ratios[2]); /*right*/
} else if (!H5F_addr_defined(old_bt->left)) {
- nleft = (int)(2 * k * split_ratios[0]); /*left*/
+ nleft = (unsigned)(2 * (double)k * split_ratios[0]); /*left*/
} else {
- nleft = (int)(2 * k * split_ratios[1]); /*middle*/
+ nleft = (unsigned)(2 * (double)k * split_ratios[1]); /*middle*/
}
/*
@@ -781,9 +782,9 @@ H5B_split(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_t *old_bt, haddr
* Create the new B-tree node.
*/
if (H5B_create(f, dxpl_id, type, udata, new_addr_p/*out*/) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to create B-tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to create B-tree")
if (NULL==(new_bt=H5AC_protect(f, dxpl_id, H5AC_BT, *new_addr_p, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to protect B-tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to protect B-tree")
new_bt->level = old_bt->level;
/*
@@ -796,15 +797,15 @@ H5B_split(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_t *old_bt, haddr
old_bt->native + nleft * type->sizeof_nkey,
(nright+1) * type->sizeof_nkey);
- for (i=0; i<=nright; i++) {
+ for (u=0; u<=nright; u++) {
/* key */
- new_bt->key[i].dirty = old_bt->key[nleft+i].dirty;
- if (old_bt->key[nleft+i].nkey)
- new_bt->key[i].nkey = new_bt->native + i * type->sizeof_nkey;
+ new_bt->key[u].dirty = old_bt->key[nleft+u].dirty;
+ if (old_bt->key[nleft+u].nkey)
+ new_bt->key[u].nkey = new_bt->native + u * type->sizeof_nkey;
/* child */
- if (i < nright)
- new_bt->child[i] = old_bt->child[nleft+i];
+ if (u < nright)
+ new_bt->child[u] = old_bt->child[nleft+u];
}
new_bt->ndirty = new_bt->nchildren = nright;
@@ -823,17 +824,17 @@ H5B_split(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_t *old_bt, haddr
if (H5F_addr_defined(old_bt->right)) {
if (NULL == (tmp_bt = H5AC_find(f, dxpl_id, H5AC_BT, old_bt->right, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load right sibling");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load right sibling")
tmp_bt->cache_info.dirty = TRUE;
tmp_bt->left = *new_addr_p;
}
old_bt->right = *new_addr_p;
done:
- if (new_bt && H5AC_unprotect(f, dxpl_id, H5AC_BT, *new_addr_p, new_bt, FALSE) < 0 && ret_value>=0)
- HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree node");
+ if (new_bt && H5AC_unprotect(f, dxpl_id, H5AC_BT, *new_addr_p, new_bt, FALSE) < 0)
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree node")
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -855,20 +856,20 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5B_decode_key(H5F_t *f, H5B_t *bt, int idx)
+H5B_decode_key(H5F_t *f, H5B_t *bt, unsigned idx)
{
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5B_decode_key);
+ FUNC_ENTER_NOAPI_NOINIT(H5B_decode_key)
assert(bt->key[idx].dirty==0);
bt->key[idx].nkey = bt->native + idx * bt->type->sizeof_nkey;
if ((bt->type->decode) (f, bt, bt->key[idx].rkey, bt->key[idx].nkey) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -887,23 +888,23 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5B_decode_keys(H5F_t *f, H5B_t *bt, int idx)
+H5B_decode_keys(H5F_t *f, H5B_t *bt, unsigned idx)
{
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5B_decode_keys);
+ FUNC_ENTER_NOAPI_NOINIT(H5B_decode_keys)
assert(f);
assert(bt);
- assert(idx >= 0 && idx < bt->nchildren);
+ assert(idx < bt->nchildren);
if (!bt->key[idx].nkey && H5B_decode_key(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key")
if (!bt->key[idx+1].nkey && H5B_decode_key(f, bt, idx+1) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -954,11 +955,9 @@ H5B_insert(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr,
H5B_ins_t my_ins = H5B_INS_ERROR;
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI(H5B_insert, FAIL);
+ FUNC_ENTER_NOAPI(H5B_insert, FAIL)
- /*
- * Check arguments.
- */
+ /* Check arguments. */
assert(f);
assert(type);
assert(type->sizeof_nkey <= sizeof _lt_key);
@@ -967,28 +966,29 @@ H5B_insert(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr,
if ((my_ins = H5B_insert_helper(f, dxpl_id, addr, type, lt_key,
&lt_key_changed, md_key, udata, rt_key, &rt_key_changed, &child/*out*/))<0 ||
my_ins<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to insert key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to insert key")
if (H5B_INS_NOOP == my_ins)
- HGOTO_DONE(SUCCEED);
+ HGOTO_DONE(SUCCEED)
assert(H5B_INS_RIGHT == my_ins);
/* the current root */
if (NULL == (bt = H5AC_find(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to locate root of B-tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to locate root of B-tree")
level = bt->level;
if (!lt_key_changed) {
if (!bt->key[0].nkey && H5B_decode_key(f, bt, 0) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key")
HDmemcpy(lt_key, bt->key[0].nkey, type->sizeof_nkey);
}
/* the new node */
if (NULL == (bt = H5AC_find(f, dxpl_id, H5AC_BT, child, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load new node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load new node")
+
if (!rt_key_changed) {
if (!bt->key[bt->nchildren].nkey &&
H5B_decode_key(f, bt, bt->nchildren) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode key")
HDmemcpy(rt_key, bt->key[bt->nchildren].nkey, type->sizeof_nkey);
}
@@ -999,11 +999,12 @@ H5B_insert(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr,
*/
size = H5B_nodesize(f, type, NULL, bt->sizeof_rkey);
if (HADDR_UNDEF==(old_root=H5MF_alloc(f, H5FD_MEM_BTREE, dxpl_id, size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate file space to move root");
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate file space to move root")
/* update the new child's left pointer */
if (NULL == (bt = H5AC_find(f, dxpl_id, H5AC_BT, child, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load new child");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load new child")
+
bt->cache_info.dirty = TRUE;
bt->left = old_root;
@@ -1013,7 +1014,7 @@ H5B_insert(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr,
*/
/* Bring the old root into the cache if it's not already */
if (NULL == (bt = H5AC_find(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load new child");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load new child")
/* Make certain the old root info is marked as dirty before moving it, */
/* so it is certain to be written out at the new location */
@@ -1021,11 +1022,11 @@ H5B_insert(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr,
/* Make a copy of the old root information */
if (NULL == (bt = H5B_copy(f, bt)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to copy old root");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to copy old root")
/* Move the location on the disk */
if (H5AC_rename(f, dxpl_id, H5AC_BT, addr, old_root) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to move B-tree root node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to move B-tree root node")
/* Insert the copy of the old root into the file again */
if (H5AC_set(f, dxpl_id, H5AC_BT, addr, bt) < 0)
@@ -1060,7 +1061,7 @@ H5B_insert(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr,
#endif
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -1083,13 +1084,13 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5B_insert_child(H5F_t *f, const H5B_class_t *type, H5B_t *bt,
- int idx, haddr_t child, H5B_ins_t anchor, void *md_key)
+H5B_insert_child(const H5F_t *f, const H5B_class_t *type, H5B_t *bt,
+ unsigned idx, haddr_t child, H5B_ins_t anchor, const void *md_key)
{
size_t recsize;
- int i;
+ unsigned u; /* Local index variable */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B_insert_child);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B_insert_child)
assert(bt);
assert(bt->nchildren<2*H5F_KVALUE(f, type));
@@ -1111,12 +1112,12 @@ H5B_insert_child(H5F_t *f, const H5B_class_t *type, H5B_t *bt,
bt->native + idx * type->sizeof_nkey,
((bt->nchildren - idx) + 1) * type->sizeof_nkey);
- for (i=bt->nchildren; i>=idx; --i) {
- bt->key[i+1].dirty = bt->key[i].dirty;
- if (bt->key[i].nkey) {
- bt->key[i+1].nkey = bt->native + (i+1) * type->sizeof_nkey;
+ for (u=bt->nchildren; u>=idx; --u) {
+ bt->key[u+1].dirty = bt->key[u].dirty;
+ if (bt->key[u].nkey) {
+ bt->key[u+1].nkey = bt->native + (u+1) * type->sizeof_nkey;
} else {
- bt->key[i+1].nkey = NULL;
+ bt->key[u+1].nkey = NULL;
}
}
bt->key[idx].dirty = TRUE;
@@ -1137,12 +1138,12 @@ H5B_insert_child(H5F_t *f, const H5B_class_t *type, H5B_t *bt,
bt->native + (idx+1) * type->sizeof_nkey,
(bt->nchildren - idx) * type->sizeof_nkey);
- for (i = bt->nchildren; i > idx; --i) {
- bt->key[i+1].dirty = bt->key[i].dirty;
- if (bt->key[i].nkey) {
- bt->key[i+1].nkey = bt->native + (i+1) * type->sizeof_nkey;
+ for (u = bt->nchildren; u > idx; --u) {
+ bt->key[u+1].dirty = bt->key[u].dirty;
+ if (bt->key[u].nkey) {
+ bt->key[u+1].nkey = bt->native + (u+1) * type->sizeof_nkey;
} else {
- bt->key[i+1].nkey = NULL;
+ bt->key[u+1].nkey = NULL;
}
}
bt->key[idx+1].dirty = TRUE;
@@ -1158,7 +1159,7 @@ H5B_insert_child(H5F_t *f, const H5B_class_t *type, H5B_t *bt,
bt->nchildren += 1;
bt->ndirty = bt->nchildren;
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
}
@@ -1216,12 +1217,13 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
haddr_t *new_node_p/*out*/)
{
H5B_t *bt = NULL, *twin = NULL, *tmp_bt = NULL;
- int lt = 0, idx = -1, rt, cmp = -1;
- haddr_t child_addr;
+ unsigned lt = 0, idx = 0, rt; /* Left, final & right index values */
+ int cmp = -1; /* Key comparison value */
+ haddr_t child_addr = HADDR_UNDEF;
H5B_ins_t my_ins = H5B_INS_ERROR;
- H5B_ins_t ret_value = H5B_INS_ERROR;
+ H5B_ins_t ret_value = H5B_INS_ERROR; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5B_insert_helper);
+ FUNC_ENTER_NOAPI_NOINIT(H5B_insert_helper)
/*
* Check arguments
@@ -1247,13 +1249,13 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
* should get the new data.
*/
if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to load node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to load node")
rt = bt->nchildren;
while (lt < rt && cmp) {
idx = (lt + rt) / 2;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
if ((cmp = (type->cmp3) (f, dxpl_id, bt->key[idx].nkey, udata,
bt->key[idx+1].nkey)) < 0) {
rt = idx;
@@ -1273,7 +1275,7 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
if ((type->new_node)(f, dxpl_id, H5B_INS_FIRST, bt->key[0].nkey, udata,
bt->key[1].nkey, bt->child + 0/*out*/) < 0) {
bt->key[0].nkey = bt->key[1].nkey = NULL;
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, H5B_INS_ERROR, "unable to create leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, H5B_INS_ERROR, "unable to create leaf node")
}
bt->nchildren = 1;
bt->cache_info.dirty = TRUE;
@@ -1286,51 +1288,48 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
if ((my_ins = (type->insert)(f, dxpl_id, bt->child[idx], bt->key[idx].nkey,
lt_key_changed, md_key, udata, bt->key[idx+1].nkey,
rt_key_changed, &child_addr/*out*/)) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "unable to insert first leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "unable to insert first leaf node")
} else {
my_ins = H5B_INS_NOOP;
}
- } else if (cmp < 0 && idx <= 0 && bt->level > 0) {
+ } else if (cmp < 0 && idx == 0 && bt->level > 0) {
/*
* The value being inserted is less than any value in this tree.
* Follow the minimum branch out of this node to a subtree.
*/
- idx = 0;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
if ((my_ins = H5B_insert_helper(f, dxpl_id, bt->child[idx], type,
bt->key[idx].nkey, lt_key_changed, md_key,
udata, bt->key[idx+1].nkey, rt_key_changed,
&child_addr/*out*/))<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum subtree");
- } else if (cmp < 0 && idx <= 0 && type->follow_min) {
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum subtree")
+ } else if (cmp < 0 && idx == 0 && type->follow_min) {
/*
* The value being inserted is less than any leaf node out of this
* current node. Follow the minimum branch to a leaf node and let the
* subclass handle the problem.
*/
- idx = 0;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
if ((my_ins = (type->insert)(f, dxpl_id, bt->child[idx], bt->key[idx].nkey,
lt_key_changed, md_key, udata, bt->key[idx+1].nkey,
rt_key_changed, &child_addr/*out*/)) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum leaf node");
- } else if (cmp < 0 && idx <= 0) {
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum leaf node")
+ } else if (cmp < 0 && idx == 0) {
/*
* The value being inserted is less than any leaf node out of the
* current node. Create a new minimum leaf node out of this B-tree
* node. This node is not empty (handled above).
*/
- idx = 0;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
my_ins = H5B_INS_LEFT;
HDmemcpy(md_key, bt->key[idx].nkey, type->sizeof_nkey);
if ((type->new_node)(f, dxpl_id, H5B_INS_LEFT, bt->key[idx].nkey, udata,
md_key, &child_addr/*out*/) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert minimum leaf node")
*lt_key_changed = TRUE;
} else if (cmp > 0 && idx + 1 >= bt->nchildren && bt->level > 0) {
@@ -1340,11 +1339,11 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
*/
idx = bt->nchildren - 1;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
if ((my_ins = H5B_insert_helper(f, dxpl_id, bt->child[idx], type,
bt->key[idx].nkey, lt_key_changed, md_key, udata,
bt->key[idx+1].nkey, rt_key_changed, &child_addr/*out*/)) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum subtree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum subtree")
} else if (cmp > 0 && idx + 1 >= bt->nchildren && type->follow_max) {
/*
* The value being inserted is larger than any leaf node out of the
@@ -1353,11 +1352,11 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
*/
idx = bt->nchildren - 1;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
if ((my_ins = (type->insert)(f, dxpl_id, bt->child[idx], bt->key[idx].nkey,
lt_key_changed, md_key, udata, bt->key[idx+1].nkey,
rt_key_changed, &child_addr/*out*/)) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum leaf node")
} else if (cmp > 0 && idx + 1 >= bt->nchildren) {
/*
* The value being inserted is larger than any leaf node out of the
@@ -1366,12 +1365,12 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
*/
idx = bt->nchildren - 1;
if (H5B_decode_keys(f, bt, idx) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
my_ins = H5B_INS_RIGHT;
HDmemcpy(md_key, bt->key[idx+1].nkey, type->sizeof_nkey);
if ((type->new_node)(f, dxpl_id, H5B_INS_RIGHT, md_key, udata,
bt->key[idx+1].nkey, &child_addr/*out*/) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert maximum leaf node")
*rt_key_changed = TRUE;
} else if (cmp) {
@@ -1380,26 +1379,27 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
* IS A MAJOR PROBLEM THAT NEEDS TO BE FIXED --rpm.
*/
assert("INTERNAL HDF5 ERROR (contact rpm)" && 0);
+#ifdef NDEBUG
HDabort();
-
+#endif /* NDEBUG */
} else if (bt->level > 0) {
/*
* Follow a branch out of this node to another subtree.
*/
- assert(idx >= 0 && idx < bt->nchildren);
+ assert(idx < bt->nchildren);
if ((my_ins = H5B_insert_helper(f, dxpl_id, bt->child[idx], type,
bt->key[idx].nkey, lt_key_changed, md_key, udata,
bt->key[idx+1].nkey, rt_key_changed, &child_addr/*out*/)) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert subtree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert subtree")
} else {
/*
* Follow a branch out of this node to a leaf node of some other type.
*/
- assert(idx >= 0 && idx < bt->nchildren);
+ assert(idx < bt->nchildren);
if ((my_ins = (type->insert)(f, dxpl_id, bt->child[idx], bt->key[idx].nkey,
lt_key_changed, md_key, udata, bt->key[idx+1].nkey,
rt_key_changed, &child_addr/*out*/)) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert leaf node")
}
assert(my_ins >= 0);
@@ -1439,9 +1439,9 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
*/
if (bt->nchildren == 2 * H5F_KVALUE(f, type)) {
if (H5B_split(f, dxpl_id, type, bt, addr, idx, udata, new_node_p/*out*/)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, H5B_INS_ERROR, "unable to split node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, H5B_INS_ERROR, "unable to split node")
if (NULL == (twin = H5AC_protect(f, dxpl_id, H5AC_BT, *new_node_p, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to load node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to load node")
if (idx<bt->nchildren) {
tmp_bt = bt;
} else {
@@ -1454,7 +1454,7 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
/* Insert the child */
if (H5B_insert_child(f, type, tmp_bt, idx, child_addr, my_ins, md_key) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert child");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, H5B_INS_ERROR, "can't insert child")
}
/*
@@ -1463,7 +1463,7 @@ H5B_insert_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
*/
if (twin) {
if (!twin->key[0].nkey && H5B_decode_key(f, twin, 0) < 0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode key")
HDmemcpy(md_key, twin->key[0].nkey, type->sizeof_nkey);
ret_value = H5B_INS_RIGHT;
#ifdef H5B_DEBUG
@@ -1488,10 +1488,10 @@ done:
herr_t e1 = (bt && H5AC_unprotect(f, dxpl_id, H5AC_BT, addr, bt, FALSE) < 0);
herr_t e2 = (twin && H5AC_unprotect(f, dxpl_id, H5AC_BT, *new_node_p, twin, FALSE)<0);
if (e1 || e2) /*use vars to prevent short-circuit of side effects */
- HDONE_ERROR(H5E_BTREE, H5E_PROTECT, H5B_INS_ERROR, "unable to release node(s)");
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, H5B_INS_ERROR, "unable to release node(s)")
}
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -1526,10 +1526,11 @@ H5B_iterate (H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_operator_t op
haddr_t cur_addr = HADDR_UNDEF;
haddr_t *child = NULL;
uint8_t *key = NULL;
- int i, nchildren;
+ unsigned nchildren; /* Number of children of B-tree node */
+ unsigned u; /* Local index variable */
herr_t ret_value;
- FUNC_ENTER_NOAPI(H5B_iterate, FAIL);
+ FUNC_ENTER_NOAPI(H5B_iterate, FAIL)
/*
* Check arguments.
@@ -1541,11 +1542,11 @@ H5B_iterate (H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_operator_t op
assert(udata);
if (NULL == (bt=H5AC_find(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node")
if (bt->level > 0) {
/* Keep following the left-most child until we reach a leaf node. */
if ((ret_value=H5B_iterate(f, dxpl_id, type, op, bt->child[0], udata))<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "unable to list B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "unable to list B-tree node")
} else {
/*
* We've reached the left-most leaf. Now follow the right-sibling
@@ -1553,22 +1554,22 @@ H5B_iterate (H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_operator_t op
*/
if (NULL==(child=H5FL_SEQ_MALLOC(haddr_t,(size_t)(2*H5F_KVALUE(f,type)))) ||
NULL==(key=H5MM_malloc((2*H5F_KVALUE(f, type)+1)*type->sizeof_nkey)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
- for (cur_addr=addr, ret_value=0; H5F_addr_defined(cur_addr) && !ret_value; cur_addr=next_addr) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ for (cur_addr=addr, ret_value=0; H5F_addr_defined(cur_addr) && !ret_value; cur_addr=next_addr) {
/*
* Save all the child addresses and native keys since we can't
* leave the B-tree node protected during an application
* callback.
*/
if (NULL==(bt=H5AC_find (f, dxpl_id, H5AC_BT, cur_addr, type, udata)))
- HGOTO_ERROR (H5E_BTREE, H5E_CANTLOAD, FAIL, "B-tree node");
- for (i=0; i<bt->nchildren; i++)
- child[i] = bt->child[i];
- for (i=0; i<bt->nchildren+1; i++) {
- if (!bt->key[i].nkey)
- H5B_decode_key(f, bt, i);
- HDmemcpy(key+i*type->sizeof_nkey, bt->key[i].nkey,
+ HGOTO_ERROR (H5E_BTREE, H5E_CANTLOAD, FAIL, "B-tree node")
+ for (u=0; u<bt->nchildren; u++)
+ child[u] = bt->child[u];
+ for (u=0; u<bt->nchildren+1; u++) {
+ if (!bt->key[u].nkey)
+ H5B_decode_key(f, bt, u);
+ HDmemcpy(key+u*type->sizeof_nkey, bt->key[u].nkey,
type->sizeof_nkey);
}
next_addr = bt->right;
@@ -1579,11 +1580,11 @@ H5B_iterate (H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, H5B_operator_t op
* Perform the iteration operator, which might invoke an
* application callback.
*/
- for (i=0, ret_value=H5B_ITER_CONT; i<nchildren && !ret_value; i++) {
- ret_value = (*op)(f, dxpl_id, key+i*type->sizeof_nkey,
- child[i], key+(i+1)*type->sizeof_nkey, udata);
+ for (u=0, ret_value=H5B_ITER_CONT; u<nchildren && !ret_value; u++) {
+ ret_value = (*op)(f, dxpl_id, key+u*type->sizeof_nkey,
+ child[u], key+(u+1)*type->sizeof_nkey, udata);
if (ret_value<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "iterator function failed");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "iterator function failed")
} /* end for */
} /* end for */
} /* end else */
@@ -1593,7 +1594,7 @@ done:
H5FL_SEQ_FREE(haddr_t,child);
if(key!=NULL)
H5MM_xfree(key);
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -1632,11 +1633,13 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
{
H5B_t *bt = NULL, *sibling = NULL;
H5B_ins_t ret_value = H5B_INS_ERROR;
- int idx=-1, lt=0, rt, cmp=1, i;
+ unsigned idx=0, lt=0, rt; /* Final, left & right indices */
+ int cmp=1; /* Key comparison value */
+ unsigned u; /* Local index variable */
size_t sizeof_rkey, sizeof_rec;
hsize_t sizeof_node;
- FUNC_ENTER_NOAPI(H5B_remove_helper, H5B_INS_ERROR);
+ FUNC_ENTER_NOAPI(H5B_remove_helper, H5B_INS_ERROR)
assert(f);
assert(H5F_addr_defined(addr));
@@ -1653,12 +1656,12 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
* for which we're searching.
*/
if (NULL==(bt=H5AC_protect(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to load B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to load B-tree node")
rt = bt->nchildren;
while (lt<rt && cmp) {
idx = (lt+rt)/2;
if (H5B_decode_keys(f, bt, idx)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode B-tree key(s)");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, H5B_INS_ERROR, "unable to decode B-tree key(s)")
if ((cmp=(type->cmp3)(f, dxpl_id, bt->key[idx].nkey, udata,
bt->key[idx+1].nkey))<0) {
rt = idx;
@@ -1667,20 +1670,20 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
}
}
if (cmp)
- HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, H5B_INS_ERROR, "B-tree key not found");
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, H5B_INS_ERROR, "B-tree key not found")
/*
* Follow the link to the subtree or to the data node. The return value
* will be one of H5B_INS_ERROR, H5B_INS_NOOP, or H5B_INS_REMOVE.
*/
- assert(idx>=0 && idx<bt->nchildren);
+ assert(idx<bt->nchildren);
if (bt->level>0) {
/* We're at an internal node -- call recursively */
if ((ret_value=H5B_remove_helper(f, dxpl_id,
bt->child[idx], type, level+1, bt->key[idx].nkey/*out*/,
lt_key_changed/*out*/, udata, bt->key[idx+1].nkey/*out*/,
rt_key_changed/*out*/))<0)
- HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, H5B_INS_ERROR, "key not found in subtree");
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, H5B_INS_ERROR, "key not found in subtree")
} else if (type->remove) {
/*
* We're at a leaf node but the leaf node points to an object that
@@ -1690,7 +1693,7 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
if ((ret_value=(type->remove)(f, dxpl_id,
bt->child[idx], bt->key[idx].nkey, lt_key_changed, udata,
bt->key[idx+1].nkey, rt_key_changed))<0)
- HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, H5B_INS_ERROR, "key not found in leaf node");
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, H5B_INS_ERROR, "key not found in leaf node")
} else {
/*
* We're at a leaf node which points to an object that has no removal
@@ -1736,7 +1739,7 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
if (ret_value!=H5B_INS_REMOVE && level>0) {
if (H5F_addr_defined(bt->right)) {
if (NULL==(sibling=H5AC_find(f, dxpl_id, H5AC_BT, bt->right, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree")
/* Make certain the native key for the right sibling is set up */
if (!sibling->key[0].nkey && H5B_decode_key(f, sibling, 0) < 0)
@@ -1766,13 +1769,13 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
if (level>0) {
if (H5F_addr_defined(bt->left)) {
if (NULL==(sibling=H5AC_find(f, dxpl_id, H5AC_BT, bt->left, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree")
sibling->right = bt->right;
sibling->cache_info.dirty = TRUE;
}
if (H5F_addr_defined(bt->right)) {
if (NULL==(sibling=H5AC_find(f, dxpl_id, H5AC_BT, bt->right, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree")
/* Copy left-most key from deleted node to left-most key in it's right neighbor */
/* (Make certain the native key for the right sibling is set up) */
@@ -1791,7 +1794,7 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
if (H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, addr, sizeof_node)<0
|| H5AC_unprotect(f, dxpl_id, H5AC_BT, addr, bt, TRUE)<0) {
bt = NULL;
- HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, H5B_INS_ERROR, "unable to free B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, H5B_INS_ERROR, "unable to free B-tree node")
}
bt = NULL;
}
@@ -1817,12 +1820,12 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
HDmemmove(bt->child,
bt->child+1,
bt->nchildren * sizeof(haddr_t));
- for (i=0; i<=bt->nchildren; i++) {
- bt->key[i].dirty = bt->key[i+1].dirty;
- if (bt->key[i+1].nkey) {
- bt->key[i].nkey = bt->native + i*type->sizeof_nkey;
+ for (u=0; u<=bt->nchildren; u++) {
+ bt->key[u].dirty = bt->key[u+1].dirty;
+ if (bt->key[u+1].nkey) {
+ bt->key[u].nkey = bt->native + u*type->sizeof_nkey;
} else {
- bt->key[i].nkey = NULL;
+ bt->key[u].nkey = NULL;
}
}
assert(bt->key[0].nkey);
@@ -1851,7 +1854,7 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
if (level>0) {
if (H5F_addr_defined(bt->right)) {
if (NULL==(sibling=H5AC_find(f, dxpl_id, H5AC_BT, bt->right, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, H5B_INS_ERROR, "unable to unlink node from tree")
/* Make certain the native key for the right sibling is set up */
if (!sibling->key[0].nkey && H5B_decode_key(f, sibling, 0) < 0)
@@ -1885,12 +1888,12 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
HDmemmove(bt->child+idx,
bt->child+idx+1,
(bt->nchildren-idx) * sizeof(haddr_t));
- for (i=idx; i<=bt->nchildren; i++) {
- bt->key[i].dirty = bt->key[i+1].dirty;
- if (bt->key[i+1].nkey) {
- bt->key[i].nkey = bt->native + i*type->sizeof_nkey;
+ for (u=idx; u<=bt->nchildren; u++) {
+ bt->key[u].dirty = bt->key[u+1].dirty;
+ if (bt->key[u+1].nkey) {
+ bt->key[u].nkey = bt->native + u*type->sizeof_nkey;
} else {
- bt->key[i].nkey = NULL;
+ bt->key[u].nkey = NULL;
}
}
ret_value = H5B_INS_NOOP;
@@ -1898,13 +1901,12 @@ H5B_remove_helper(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type
} else {
ret_value = H5B_INS_NOOP;
}
-
-
+
done:
- if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BT, addr, bt, FALSE)<0 && ret_value>=0)
- HDONE_ERROR(H5E_BTREE, H5E_PROTECT, H5B_INS_ERROR, "unable to release node");
+ if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BT, addr, bt, FALSE)<0)
+ HDONE_ERROR(H5E_BTREE, H5E_PROTECT, H5B_INS_ERROR, "unable to release node")
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -1914,6 +1916,7 @@ done:
* Purpose: Removes an item from a B-tree.
*
* Note: The current version does not attempt to rebalance the tree.
+ * (Read the paper Yao & Lehman paper for details on why)
*
* Return: Non-negative on success/Negative on failure (failure includes
* not being able to find the object which is to be removed).
@@ -1938,7 +1941,7 @@ H5B_remove(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void
H5B_t *bt = NULL; /*btree node */
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5B_remove, FAIL);
+ FUNC_ENTER_NOAPI(H5B_remove, FAIL)
/* Check args */
assert(f);
@@ -1949,14 +1952,15 @@ H5B_remove(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void
/* The actual removal */
if (H5B_remove_helper(f, dxpl_id, addr, type, 0, lt_key, &lt_key_changed,
udata, rt_key, &rt_key_changed)==H5B_INS_ERROR)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to remove entry from B-tree");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to remove entry from B-tree")
/*
* If the B-tree is now empty then make sure we mark the root node as
* being at level zero
*/
if (NULL==(bt=H5AC_find(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree root node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree root node")
+
if (0==bt->nchildren && 0!=bt->level) {
bt->level = 0;
bt->cache_info.dirty = TRUE;
@@ -1966,7 +1970,7 @@ H5B_remove(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void
H5B_assert(f, dxpl_id, addr, type, udata);
#endif
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -1991,10 +1995,10 @@ H5B_delete(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void
H5B_t *bt; /* B-tree node being operated on */
size_t sizeof_rkey; /* Size of raw key */
hsize_t sizeof_node; /* Size of B-tree node */
- int i; /* Local index variable */
- herr_t ret_value=SUCCEED; /* Return value */
+ unsigned u; /* Local index variable */
+ herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5B_delete, FAIL);
+ FUNC_ENTER_NOAPI(H5B_delete, FAIL)
/* Check args */
assert(f);
@@ -2003,14 +2007,14 @@ H5B_delete(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void
/* Lock this B-tree node into memory for now */
if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node")
/* Iterate over all children in tree, deleting them */
if (bt->level > 0) {
/* Iterate over all children in node, deleting them */
- for (i=0; i<bt->nchildren; i++)
- if (H5B_delete(f, dxpl_id, type, bt->child[i], udata)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "unable to delete B-tree node");
+ for (u=0; u<bt->nchildren; u++)
+ if (H5B_delete(f, dxpl_id, type, bt->child[u], udata)<0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "unable to delete B-tree node")
} else {
hbool_t lt_key_changed, rt_key_changed; /* Whether key changed (unused here, just for callback) */
@@ -2018,16 +2022,16 @@ H5B_delete(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void
/* Check for removal callback */
if(type->remove) {
/* Iterate over all entries in node, calling callback */
- for (i=0; i<bt->nchildren; i++) {
+ for (u=0; u<bt->nchildren; u++) {
/* Decode native keys */
- if (H5B_decode_keys(f, bt, i)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode B-tree key(s)");
+ if (H5B_decode_keys(f, bt, u)<0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode B-tree key(s)")
/* Call user's callback for each entry */
if ((type->remove)(f, dxpl_id,
- bt->child[i], bt->key[i].nkey, &lt_key_changed, udata,
- bt->key[i+1].nkey, &rt_key_changed)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "can't remove B-tree node");
+ bt->child[u], bt->key[u].nkey, &lt_key_changed, udata,
+ bt->key[u+1].nkey, &rt_key_changed)<0)
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "can't remove B-tree node")
} /* end for */
} /* end if */
} /* end else */
@@ -2036,14 +2040,14 @@ H5B_delete(H5F_t *f, hid_t dxpl_id, const H5B_class_t *type, haddr_t addr, void
sizeof_rkey = (type->get_sizeof_rkey)(f, udata);
sizeof_node = H5B_nodesize(f, type, NULL, sizeof_rkey);
if (H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, addr, sizeof_node)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free B-tree node")
/* Release node in metadata cache */
if (H5AC_unprotect(f, dxpl_id, H5AC_BT, addr, bt, TRUE)<0)
- HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree node in cache");
+ HGOTO_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree node in cache")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5B_delete() */
@@ -2071,13 +2075,13 @@ done:
*-------------------------------------------------------------------------
*/
static size_t
-H5B_nodesize(H5F_t *f, const H5B_class_t *type,
+H5B_nodesize(const H5F_t *f, const H5B_class_t *type,
size_t *total_nkey_size/*out*/, size_t sizeof_rkey)
{
size_t size;
size_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5B_nodesize, (size_t) 0);
+ FUNC_ENTER_NOAPI(H5B_nodesize, 0)
/*
* Check arguments.
@@ -2104,7 +2108,7 @@ H5B_nodesize(H5F_t *f, const H5B_class_t *type,
ret_value=size;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -2126,7 +2130,7 @@ done:
*-------------------------------------------------------------------------
*/
static H5B_t *
-H5B_copy(H5F_t *f, const H5B_t *old_bt)
+H5B_copy(const H5F_t *f, const H5B_t *old_bt)
{
H5B_t *new_node = NULL;
size_t total_native_keysize;
@@ -2135,7 +2139,7 @@ H5B_copy(H5F_t *f, const H5B_t *old_bt)
size_t u;
H5B_t *ret_value;
- FUNC_ENTER_NOAPI(H5B_copy, NULL);
+ FUNC_ENTER_NOAPI(H5B_copy, NULL)
/*
* Check arguments.
@@ -2150,7 +2154,7 @@ H5B_copy(H5F_t *f, const H5B_t *old_bt)
/* Allocate memory for the new H5B_t object */
if (NULL==(new_node = H5FL_MALLOC(H5B_t)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree root node");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree root node")
/* Copy the main structure */
HDmemcpy(new_node,old_bt,sizeof(H5B_t));
@@ -2162,7 +2166,7 @@ H5B_copy(H5F_t *f, const H5B_t *old_bt)
NULL==(new_node->native=H5FL_BLK_MALLOC(native_block,total_native_keysize)) ||
NULL==(new_node->child=H5FL_SEQ_MALLOC(haddr_t,nkeys)) ||
NULL==(new_node->key=H5FL_SEQ_MALLOC(H5B_key_t,(nkeys+1))))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree root node");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for B-tree root node")
/* Copy the other structures */
HDmemcpy(new_node->page,old_bt->page,(size_t)size);
@@ -2191,7 +2195,7 @@ done:
} /* end if */
} /* end if */
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5B_copy */
@@ -2216,10 +2220,10 @@ H5B_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int f
const H5B_class_t *type, void *udata)
{
H5B_t *bt = NULL;
- int i;
+ unsigned u; /* Local index variable */
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5B_debug, FAIL);
+ FUNC_ENTER_NOAPI(H5B_debug, FAIL)
/*
* Check arguments.
@@ -2235,7 +2239,7 @@ H5B_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int f
* Load the tree node.
*/
if (NULL == (bt = H5AC_find(f, dxpl_id, H5AC_BT, addr, type, udata)))
- HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node");
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree node")
/*
* Print the values.
@@ -2253,9 +2257,9 @@ H5B_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int f
HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
"Dirty flag:",
bt->cache_info.dirty ? "True" : "False");
- HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Number of initial dirty children:",
- (int) (bt->ndirty));
+ bt->ndirty);
HDfprintf(stream, "%*s%-*s %d\n", indent, "", fwidth,
"Level:",
(int) (bt->level));
@@ -2268,41 +2272,44 @@ H5B_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int f
"Address of right sibling:",
bt->right);
- HDfprintf(stream, "%*s%-*s %d (%d)\n", indent, "", fwidth,
+ HDfprintf(stream, "%*s%-*s %u (%u)\n", indent, "", fwidth,
"Number of children (max):",
- (int) (bt->nchildren),
- (int) (2 * H5F_KVALUE(f, type)));
+ bt->nchildren, (2 * H5F_KVALUE(f, type)));
/*
* Print the child addresses
*/
- for (i = 0; i < bt->nchildren; i++) {
- HDfprintf(stream, "%*sChild %d...\n", indent, "", i);
+ for (u = 0; u < bt->nchildren; u++) {
+ HDfprintf(stream, "%*sChild %d...\n", indent, "", u);
HDfprintf(stream, "%*s%-*s %a\n", indent + 3, "", MAX(0, fwidth - 3),
- "Address:", bt->child[i]);
+ "Address:", bt->child[u]);
/* If there is a key debugging routine, use it to display the left & right keys */
if (type->debug_key) {
/* Decode the 'left' key & print it */
HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
"Left Key:");
- if(bt->key[i].nkey==NULL)
- H5B_decode_key(f, bt, i);
- (type->debug_key)(stream, f, dxpl_id, indent+6, MAX (0, fwidth-6),
- bt->key[i].nkey, udata);
+ if(bt->key[u].nkey==NULL) {
+ if(H5B_decode_key(f, bt, u)<0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode B-tree key(s)")
+ } /* end if */
+ (void)(type->debug_key)(stream, f, dxpl_id, indent+6, MAX (0, fwidth-6),
+ bt->key[u].nkey, udata);
/* Decode the 'right' key & print it */
HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
"Right Key:");
- if(bt->key[i+1].nkey==NULL)
- H5B_decode_key(f, bt, i+1);
- (type->debug_key)(stream, f, dxpl_id, indent+6, MAX (0, fwidth-6),
- bt->key[i+1].nkey, udata);
+ if(bt->key[u+1].nkey==NULL) {
+ if(H5B_decode_key(f, bt, u+1)<0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDECODE, FAIL, "unable to decode B-tree key(s)")
+ } /* end if */
+ (void)(type->debug_key)(stream, f, dxpl_id, indent+6, MAX (0, fwidth-6),
+ bt->key[u+1].nkey, udata);
}
}
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -2340,7 +2347,7 @@ H5B_assert(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type, void
struct child_t *next;
} *head = NULL, *tail = NULL, *prev = NULL, *cur = NULL, *tmp = NULL;
- FUNC_ENTER_NOAPI(H5B_assert, FAIL);
+ FUNC_ENTER_NOAPI(H5B_assert, FAIL)
if (0==ncalls++) {
if (H5DEBUG(B)) {
@@ -2367,7 +2374,7 @@ H5B_assert(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type, void
assert(bt);
/* Check node header */
- assert(bt->ndirty >= 0 && bt->ndirty <= bt->nchildren);
+ assert(bt->ndirty <= bt->nchildren);
assert(bt->level == cur->level);
if (cur->next && cur->next->level == bt->level) {
assert(H5F_addr_eq(bt->right, cur->next->addr));
@@ -2410,6 +2417,7 @@ H5B_assert(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type, void
/* Release node */
status = H5AC_unprotect(f, dxpl_id, H5AC_BT, cur->addr, bt, FALSE);
assert(status >= 0);
+ bt=NULL; /* Make certain future references will be caught */
/* Advance current location in queue */
prev = cur;
@@ -2424,6 +2432,6 @@ H5B_assert(H5F_t *f, hid_t dxpl_id, haddr_t addr, const H5B_class_t *type, void
}
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
#endif /* H5B_DEBUG */