summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-08-10 03:42:51 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-08-10 03:42:51 (GMT)
commitf06e8744a54fdf7454fd5f4d76e9b10f16076d22 (patch)
treec0d936fcf174d860020cce54414bf37f70632e20 /src
parentcb60bf29361e7f21468cdc6900e68f8937f9fec5 (diff)
downloadhdf5-f06e8744a54fdf7454fd5f4d76e9b10f16076d22.zip
hdf5-f06e8744a54fdf7454fd5f4d76e9b10f16076d22.tar.gz
hdf5-f06e8744a54fdf7454fd5f4d76e9b10f16076d22.tar.bz2
[svn-r12561] Description:
Update code formatting a little and refactor to add a better mechanism for performing callbacks when removing records from the B-tree or deleting entire B-tree. Testing: FreeBSD 4.11 (sleipnir) Linux/64 2.4 (mir) Linux/32 2.4 (heping) Mac OS 10.4 (amazon)
Diffstat (limited to 'src')
-rw-r--r--src/H5B2.c68
-rw-r--r--src/H5B2cache.c28
-rw-r--r--src/H5B2dbg.c4
-rw-r--r--src/H5B2int.c62
-rw-r--r--src/H5B2pkg.h9
-rw-r--r--src/H5B2private.h38
-rw-r--r--src/H5B2test.c44
7 files changed, 146 insertions, 107 deletions
diff --git a/src/H5B2.c b/src/H5B2.c
index 98dca71..44dade3 100644
--- a/src/H5B2.c
+++ b/src/H5B2.c
@@ -167,8 +167,8 @@ herr_t
H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
void *udata)
{
- H5B2_t *bt2=NULL; /* Pointer to the B-tree header */
- unsigned bt2_flags = H5AC__NO_FLAGS_SET;
+ H5B2_t *bt2 = NULL; /* Pointer to the B-tree header */
+ unsigned bt2_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for B-tree header */
H5B2_shared_t *shared; /* Pointer to B-tree's shared information */
herr_t ret_value = SUCCEED;
@@ -180,7 +180,7 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
HDassert(H5F_addr_defined(addr));
/* Look up the b-tree header */
- if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_WRITE)))
+ if(NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree header")
/* Get the pointer to the shared B-tree info */
@@ -190,7 +190,7 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
/* Check if the root node is allocated yet */
if(!H5F_addr_defined(bt2->root.addr)) {
/* Create root node as leaf node in B-tree */
- if(H5B2_create_leaf(f, dxpl_id, bt2->shared, &(bt2->root))<0)
+ if(H5B2_create_leaf(f, dxpl_id, bt2->shared, &(bt2->root)) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "unable to create root node")
/* Mark B-tree header as dirty, since we updated the address of the root node */
@@ -200,17 +200,17 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
else if((bt2->depth==0 && bt2->root.node_nrec==shared->split_leaf_nrec) ||
(bt2->depth>0 && bt2->root.node_nrec==shared->split_int_nrec)) {
/* Split root node */
- if(H5B2_split_root(f, dxpl_id, bt2, &bt2_flags, bt2->shared)<0)
+ if(H5B2_split_root(f, dxpl_id, bt2, &bt2_flags, bt2->shared) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to split root node")
} /* end if */
/* Attempt to insert record into B-tree */
- if(bt2->depth>0) {
+ if(bt2->depth > 0) {
if(H5B2_insert_internal(f, dxpl_id, bt2->shared, bt2->depth, &bt2_flags, &bt2->root, udata) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, FAIL, "unable to insert record into B-tree internal node")
} /* end if */
else {
- if(H5B2_insert_leaf(f,dxpl_id,bt2->shared,&bt2->root,udata)<0)
+ if(H5B2_insert_leaf(f,dxpl_id,bt2->shared,&bt2->root, udata) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, FAIL, "unable to insert record into B-tree leaf node")
} /* end else */
@@ -219,7 +219,7 @@ H5B2_insert(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
done:
/* Release the B-tree header info */
- if (bt2 && H5AC_unprotect(f, dxpl_id, H5AC_BT2_HDR, addr, bt2, bt2_flags) < 0)
+ if(bt2 && H5AC_unprotect(f, dxpl_id, H5AC_BT2_HDR, addr, bt2, bt2_flags) < 0)
HDONE_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree header info")
FUNC_LEAVE_NOAPI(ret_value)
@@ -312,7 +312,7 @@ done:
* the record.
*
* If 'OP' is NULL, then this routine just returns "SUCCEED" when
- * a record is found.
+ * a record is present in the B-tree.
*
* Return: Non-negative on success, negative on failure.
*
@@ -391,7 +391,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
next_node_ptr=internal->node_ptrs[idx];
/* Unlock current node */
- if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0)
+ if(H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
/* Set pointer to next node to load */
@@ -399,7 +399,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
} /* end if */
else {
/* Make callback for current record */
- if ( op && (op)(H5B2_INT_NREC(internal,shared,idx), op_data) <0) {
+ if(op && (op)(H5B2_INT_NREC(internal, shared, idx), op_data) < 0) {
/* Unlock current node */
if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
@@ -408,7 +408,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
} /* end if */
/* Unlock current node */
- if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0)
+ if(H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
HGOTO_DONE(SUCCEED);
@@ -422,7 +422,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
H5B2_leaf_t *leaf; /* Pointer to leaf node in B-tree */
/* Lock B-tree leaf node */
- if (NULL == (leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, &(curr_node_ptr.node_nrec), bt2_shared, H5AC_READ)))
+ if(NULL == (leaf = H5AC_protect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, &(curr_node_ptr.node_nrec), bt2_shared, H5AC_READ)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree internal node")
/* Locate record */
@@ -430,7 +430,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
if(cmp != 0) {
/* Unlock leaf node */
- if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
+ if(H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
/* Note: don't push error on stack, leave that to next higher level,
@@ -445,9 +445,9 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
} /* end if */
else {
/* Make callback for current record */
- if ( op && (op)(H5B2_LEAF_NREC(leaf,shared,idx), op_data) <0) {
+ if(op && (op)(H5B2_LEAF_NREC(leaf, shared, idx), op_data) < 0) {
/* Unlock current node */
- if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
+ if(H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "'found' callback failed for B-tree find operation")
@@ -455,9 +455,9 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
} /* end else */
/* Unlock current node */
- if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
+ if(H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
- }
+ } /* end block */
done:
/* Check if we need to decrement the reference count for the B-tree's shared info */
@@ -660,7 +660,7 @@ done:
*/
herr_t
H5B2_remove(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
- void *udata)
+ void *udata, H5B2_remove_t op, void *op_data)
{
H5B2_t *bt2=NULL; /* Pointer to the B-tree header */
unsigned bt2_flags = H5AC__NO_FLAGS_SET;
@@ -687,17 +687,17 @@ H5B2_remove(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "record is not in B-tree")
/* Attempt to remove record from B-tree */
- if(bt2->depth>0) {
- hbool_t depth_decreased=FALSE; /* Flag to indicate whether the depth of the B-tree decreased */
+ if(bt2->depth > 0) {
+ hbool_t depth_decreased = FALSE; /* Flag to indicate whether the depth of the B-tree decreased */
- if(H5B2_remove_internal(f,dxpl_id,bt2->shared, &depth_decreased, NULL, bt2->depth,
- &(bt2->cache_info),&bt2_flags,&bt2->root,udata)<0)
+ if(H5B2_remove_internal(f, dxpl_id, bt2->shared, &depth_decreased, NULL, bt2->depth,
+ &(bt2->cache_info), &bt2_flags, &bt2->root, udata, op, op_data) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to remove record from B-tree internal node")
bt2->depth -= depth_decreased;
} /* end if */
else {
- if(H5B2_remove_leaf(f,dxpl_id,bt2->shared,&bt2->root,udata)<0)
+ if(H5B2_remove_leaf(f, dxpl_id, bt2->shared, &bt2->root, udata, op, op_data) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to remove record from B-tree leaf node")
} /* end else */
@@ -832,6 +832,15 @@ done:
*
* Purpose: Delete an entire B-tree from a file.
*
+ * The 'OP' routine is called for each record and the
+ * OP_DATA pointer, to allow caller to perform an operation as
+ * each record is removed from the B-tree.
+ *
+ * If 'OP' is NULL, the records are just removed in the process
+ * of deleting the B-tree.
+ *
+ * Note: The records are _not_ guaranteed to be visited in order.
+ *
* Return: Non-negative on success, negative on failure.
*
* Programmer: Quincey Koziol
@@ -841,7 +850,8 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5B2_delete(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr)
+H5B2_delete(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
+ H5B2_remove_t op, void *op_data)
{
H5B2_t *bt2=NULL; /* Pointer to the B-tree header */
herr_t ret_value = SUCCEED;
@@ -854,21 +864,21 @@ H5B2_delete(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr)
HDassert(H5F_addr_defined(addr));
/* Look up the B-tree header */
- if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_WRITE)))
+ if(NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_WRITE)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree header")
/* Delete all nodes in B-tree */
if(H5F_addr_defined(bt2->root.addr))
- if(H5B2_delete_node(f, dxpl_id, bt2->shared, bt2->depth, &bt2->root)<0)
+ if(H5B2_delete_node(f, dxpl_id, bt2->shared, bt2->depth, &bt2->root, op, op_data) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to delete B-tree nodes")
/* Release space for B-tree node on disk */
- if (H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, addr, (hsize_t)H5B2_HEADER_SIZE(f))<0)
+ if(H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, addr, (hsize_t)H5B2_HEADER_SIZE(f))<0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free B-tree header info")
done:
/* Release the B-tree header info */
- if (bt2 && H5AC_unprotect(f, dxpl_id, H5AC_BT2_HDR, addr, bt2, H5AC__DELETED_FLAG) < 0)
+ if(bt2 && H5AC_unprotect(f, dxpl_id, H5AC_BT2_HDR, addr, bt2, H5AC__DELETED_FLAG) < 0)
HDONE_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to delete B-tree header info")
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5B2cache.c b/src/H5B2cache.c
index 476e9d1..1e35804 100644
--- a/src/H5B2cache.c
+++ b/src/H5B2cache.c
@@ -175,7 +175,7 @@ H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, vo
p = buf;
/* Magic number */
- if(HDmemcmp(p, H5B2_HDR_MAGIC, H5B2_SIZEOF_MAGIC))
+ if(HDmemcmp(p, H5B2_HDR_MAGIC, (size_t)H5B2_SIZEOF_MAGIC))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree header signature")
p += H5B2_SIZEOF_MAGIC;
@@ -251,10 +251,10 @@ H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B
HDassert(bt2);
if (bt2->cache_info.is_dirty) {
- H5B2_shared_t *shared; /* Shared B-tree information */
- uint8_t *buf = NULL; /* Temporary raw data buffer */
- uint8_t *p; /* Pointer into raw data buffer */
- size_t size; /* Header size on disk */
+ H5B2_shared_t *shared; /* Shared B-tree information */
+ uint8_t *buf; /* Temporary raw data buffer */
+ uint8_t *p; /* Pointer into raw data buffer */
+ size_t size; /* Header size on disk */
/* Get the pointer to the shared B-tree info */
shared = H5RC_GET_OBJ(bt2->shared);
@@ -270,7 +270,7 @@ H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B
p = buf;
/* Magic number */
- HDmemcpy(p, H5B2_HDR_MAGIC, H5B2_SIZEOF_MAGIC);
+ HDmemcpy(p, H5B2_HDR_MAGIC, (size_t)H5B2_SIZEOF_MAGIC);
p += H5B2_SIZEOF_MAGIC;
/* Version # */
@@ -472,7 +472,7 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v
p = shared->page;
/* Magic number */
- if(HDmemcmp(p, H5B2_LEAF_MAGIC, H5B2_SIZEOF_MAGIC))
+ if(HDmemcmp(p, H5B2_LEAF_MAGIC, (size_t)H5B2_SIZEOF_MAGIC))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree leaf node signature")
p += H5B2_SIZEOF_MAGIC;
@@ -497,7 +497,7 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v
native = leaf->leaf_native;
for(u = 0; u < leaf->nrec; u++) {
/* Decode record */
- if((shared->type->decode)(f, p, native) < 0)
+ if((shared->type->decode)(f, shared->type, p, native) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, NULL, "unable to decode B-tree record")
/* Move to next record */
@@ -556,7 +556,7 @@ H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5
p = shared->page;
/* magic number */
- HDmemcpy(p, H5B2_LEAF_MAGIC, H5B2_SIZEOF_MAGIC);
+ HDmemcpy(p, H5B2_LEAF_MAGIC, (size_t)H5B2_SIZEOF_MAGIC);
p += H5B2_SIZEOF_MAGIC;
/* version # */
@@ -569,7 +569,7 @@ H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5
native = leaf->leaf_native;
for(u = 0; u < leaf->nrec; u++) {
/* Encode record */
- if((shared->type->encode)(f, p, native) < 0)
+ if((shared->type->encode)(f, shared->type, p, native) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record")
/* Move to next record */
@@ -767,7 +767,7 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nre
p = shared->page;
/* Magic number */
- if(HDmemcmp(p, H5B2_INT_MAGIC, H5B2_SIZEOF_MAGIC))
+ if(HDmemcmp(p, H5B2_INT_MAGIC, (size_t)H5B2_SIZEOF_MAGIC))
HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, NULL, "wrong B-tree internal node signature")
p += H5B2_SIZEOF_MAGIC;
@@ -796,7 +796,7 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nre
native = internal->int_native;
for(u = 0; u < internal->nrec; u++) {
/* Decode record */
- if((shared->type->decode)(f, p, native) < 0)
+ if((shared->type->decode)(f, shared->type, p, native) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, NULL, "unable to decode B-tree record")
/* Move to next record */
@@ -868,7 +868,7 @@ H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr
p = shared->page;
/* Magic number */
- HDmemcpy(p, H5B2_INT_MAGIC, H5B2_SIZEOF_MAGIC);
+ HDmemcpy(p, H5B2_INT_MAGIC, (size_t)H5B2_SIZEOF_MAGIC);
p += H5B2_SIZEOF_MAGIC;
/* Version # */
@@ -881,7 +881,7 @@ H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr
native = internal->int_native;
for(u = 0; u < internal->nrec; u++) {
/* Encode record */
- if((shared->type->encode)(f, p, native) < 0)
+ if((shared->type->encode)(f, shared->type, p, native) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTENCODE, FAIL, "unable to encode B-tree record")
/* Move to next record */
diff --git a/src/H5B2dbg.c b/src/H5B2dbg.c
index 0bc8cd9..88e6852 100644
--- a/src/H5B2dbg.c
+++ b/src/H5B2dbg.c
@@ -277,7 +277,7 @@ H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
temp_str);
HDassert(H5B2_INT_NREC(internal, shared, u));
(void)(type->debug)(stream, f, dxpl_id, indent + 6, MAX (0, fwidth-6),
- H5B2_INT_NREC(internal,shared,u), NULL);
+ shared->type, H5B2_INT_NREC(internal,shared,u), NULL);
} /* end for */
/* Print final node pointer */
@@ -386,7 +386,7 @@ H5B2_leaf_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
temp_str);
HDassert(H5B2_LEAF_NREC(leaf, shared, u));
(void)(type->debug)(stream, f, dxpl_id, indent+6, MAX (0, fwidth-6),
- H5B2_LEAF_NREC(leaf,shared,u), NULL);
+ shared->type, H5B2_LEAF_NREC(leaf,shared,u), NULL);
} /* end for */
done:
diff --git a/src/H5B2int.c b/src/H5B2int.c
index 1d35cbd..8c6f515 100644
--- a/src/H5B2int.c
+++ b/src/H5B2int.c
@@ -301,9 +301,9 @@ H5B2_locate_record(const H5B2_class_t *type, unsigned nrec, size_t *rec_off,
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_locate_record)
hi = nrec;
- while (lo < hi && cmp) {
+ while(lo < hi && cmp) {
my_idx = (lo + hi) / 2;
- if ((cmp = (type->compare)(udata, native+rec_off[my_idx])) < 0)
+ if((cmp = (type->compare)(type, udata, native + rec_off[my_idx])) < 0)
hi = my_idx;
else
lo = my_idx + 1;
@@ -2239,7 +2239,7 @@ H5B2_insert_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
} /* end else */
/* Make callback to store record in native form */
- if((shared->type->store)(H5B2_LEAF_NREC(leaf,shared,idx),udata)<0)
+ if((shared->type->store)(shared->type, H5B2_LEAF_NREC(leaf,shared,idx), udata) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTINSERT, FAIL, "unable to insert record into leaf node")
/* Update record count for node pointer to current node */
@@ -2251,7 +2251,7 @@ H5B2_insert_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
done:
/* Release the B-tree leaf node (marked as dirty) */
- if (leaf && H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr->addr, leaf, H5AC__DIRTIED_FLAG) < 0)
+ if(leaf && H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr->addr, leaf, H5AC__DIRTIED_FLAG) < 0)
HDONE_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release leaf B-tree node")
FUNC_LEAVE_NOAPI(ret_value)
@@ -2617,16 +2617,16 @@ H5B2_iterate_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, unsigned depth,
native = leaf->leaf_native;
} /* end else */
- /* Iterate through records */
- for(u=0; u<curr_node->node_nrec && !ret_value; u++) {
+ /* Iterate through records, in order */
+ for(u = 0; u < curr_node->node_nrec && !ret_value; u++) {
/* Descend into child node, if current node is an internal node */
- if(depth>0) {
- if((ret_value = H5B2_iterate_node(f,dxpl_id,bt2_shared,depth-1,&(node_ptrs[u]),op,op_data))<0)
+ if(depth > 0) {
+ if((ret_value = H5B2_iterate_node(f, dxpl_id, bt2_shared, depth-1, &(node_ptrs[u]), op, op_data)) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "node iteration failed")
} /* end if */
/* Make callback for current record */
- if ((ret_value = (op)(H5B2_NAT_NREC(native,shared,u), op_data)) <0)
+ if((ret_value = (op)(H5B2_NAT_NREC(native, shared, u), op_data)) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "iterator function failed")
} /* end for */
@@ -2661,7 +2661,8 @@ done:
*/
herr_t
H5B2_remove_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
- H5B2_node_ptr_t *curr_node_ptr, void *udata)
+ H5B2_node_ptr_t *curr_node_ptr, void *udata, H5B2_remove_t op,
+ void *op_data)
{
H5B2_leaf_t *leaf; /* Pointer to leaf node */
haddr_t leaf_addr=HADDR_UNDEF; /* Leaf address on disk */
@@ -2695,9 +2696,10 @@ H5B2_remove_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
if(H5B2_locate_record(shared->type,leaf->nrec,shared->nat_off,leaf->leaf_native,udata,&idx) != 0)
HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "record is not in B-tree")
- /* Make callback to retrieve record in native form */
- if((shared->type->retrieve)(udata,H5B2_LEAF_NREC(leaf,shared,idx))<0)
- HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to remove record into leaf node")
+ /* Make 'remove' callback if there is one */
+ if(op)
+ if((op)(H5B2_LEAF_NREC(leaf,shared,idx), op_data) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to remove record into leaf node")
/* Update number of records in node */
leaf->nrec--;
@@ -2751,7 +2753,8 @@ herr_t
H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
hbool_t *depth_decreased, void *swap_loc, unsigned depth,
H5AC_info_t *parent_cache_info, unsigned *parent_cache_info_flags_ptr,
- H5B2_node_ptr_t *curr_node_ptr, void *udata)
+ H5B2_node_ptr_t *curr_node_ptr, void *udata, H5B2_remove_t op,
+ void *op_data)
{
H5AC_info_t *new_cache_info; /* Pointer to new cache info */
unsigned *new_cache_info_flags_ptr = NULL;
@@ -2802,7 +2805,7 @@ H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
HGOTO_ERROR(H5E_BTREE, H5E_CANTSPLIT, FAIL, "unable to merge child node")
/* Release space for root B-tree node on disk */
- if (H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, internal_addr, (hsize_t)shared->node_size)<0)
+ if(H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, internal_addr, (hsize_t)shared->node_size)<0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free B-tree leaf node")
/* Let the cache know that the object is deleted */
@@ -2914,12 +2917,12 @@ H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
/* Attempt to remove node */
if(depth>1) {
- if(H5B2_remove_internal(f,dxpl_id,bt2_shared,depth_decreased, swap_loc, depth-1,
- new_cache_info,new_cache_info_flags_ptr,new_node_ptr,udata)<0)
+ if(H5B2_remove_internal(f, dxpl_id, bt2_shared, depth_decreased, swap_loc, depth-1,
+ new_cache_info, new_cache_info_flags_ptr, new_node_ptr, udata, op, op_data) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to remove record from B-tree internal node")
} /* end if */
else {
- if(H5B2_remove_leaf(f,dxpl_id,bt2_shared,new_node_ptr,udata)<0)
+ if(H5B2_remove_leaf(f, dxpl_id, bt2_shared, new_node_ptr, udata, op, op_data) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "unable to remove record from B-tree leaf node")
} /* end else */
@@ -3143,11 +3146,12 @@ done:
*/
herr_t
H5B2_delete_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, unsigned depth,
- const H5B2_node_ptr_t *curr_node)
+ const H5B2_node_ptr_t *curr_node, H5B2_remove_t op, void *op_data)
{
H5B2_shared_t *shared; /* Pointer to B-tree's shared information */
const H5AC_class_t *curr_node_class=NULL; /* Pointer to current node's class info */
void *node=NULL; /* Pointers to current node */
+ uint8_t *native; /* Pointers to node's native records */
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI_NOINIT(H5B2_delete_node)
@@ -3172,10 +3176,11 @@ H5B2_delete_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, unsigned depth,
/* Set up information about current node */
curr_node_class = H5AC_BT2_INT;
node = internal;
+ native = internal->int_native;
/* Descend into children */
for(u=0; u<internal->nrec+1; u++)
- if(H5B2_delete_node(f, dxpl_id, bt2_shared, depth-1, &(internal->node_ptrs[u]))<0)
+ if(H5B2_delete_node(f, dxpl_id, bt2_shared, depth-1, &(internal->node_ptrs[u]), op, op_data)<0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "node descent failed")
} /* end if */
else {
@@ -3188,16 +3193,29 @@ H5B2_delete_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared, unsigned depth,
/* Set up information about current node */
curr_node_class = H5AC_BT2_LEAF;
node = leaf;
+ native = leaf->leaf_native;
} /* end else */
+ /* If there's a callback defined, iterate over the records in this node */
+ if(op) {
+ unsigned u; /* Local index */
+
+ /* Iterate through records in this node */
+ for(u = 0; u < curr_node->node_nrec; u++) {
+ /* Make callback for each record */
+ if((op)(H5B2_NAT_NREC(native, shared, u), op_data) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTLIST, FAIL, "iterator function failed")
+ } /* end for */
+ } /* end if */
+
/* Release space for current B-tree node on disk */
- if (H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, curr_node->addr, (hsize_t)shared->node_size)<0)
+ if(H5MF_xfree(f, H5FD_MEM_BTREE, dxpl_id, curr_node->addr, (hsize_t)shared->node_size)<0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free B-tree node")
done:
/* Unlock & delete current node */
if(node)
- if (H5AC_unprotect(f, dxpl_id, curr_node_class, curr_node->addr, node, H5AC__DELETED_FLAG) < 0)
+ if(H5AC_unprotect(f, dxpl_id, curr_node_class, curr_node->addr, node, H5AC__DELETED_FLAG) < 0)
HDONE_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5B2pkg.h b/src/H5B2pkg.h
index 784b1e5..5a27494 100644
--- a/src/H5B2pkg.h
+++ b/src/H5B2pkg.h
@@ -215,13 +215,16 @@ H5_DLL herr_t H5B2_neighbor_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
/* Routines for removing records */
H5_DLL herr_t H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
hbool_t *depth_decreased, void *swap_loc, unsigned depth, H5AC_info_t *parent_cache_info,
- hbool_t * parent_cache_info_dirtied_ptr, H5B2_node_ptr_t *curr_node_ptr, void *udata);
+ hbool_t * parent_cache_info_dirtied_ptr, H5B2_node_ptr_t *curr_node_ptr, void *udata,
+ H5B2_remove_t op, void *op_data);
H5_DLL herr_t H5B2_remove_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
- H5B2_node_ptr_t *curr_node_ptr, void *udata);
+ H5B2_node_ptr_t *curr_node_ptr, void *udata, H5B2_remove_t op,
+ void *op_data);
/* Routines for deleting nodes */
H5_DLL herr_t H5B2_delete_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
- unsigned depth, const H5B2_node_ptr_t *curr_node);
+ unsigned depth, const H5B2_node_ptr_t *curr_node, H5B2_remove_t op,
+ void *op_data);
/* Metadata cache callbacks */
H5_DLL herr_t H5B2_cache_hdr_dest(H5F_t *f, H5B2_t *b);
diff --git a/src/H5B2private.h b/src/H5B2private.h
index 0990317..f71a256 100644
--- a/src/H5B2private.h
+++ b/src/H5B2private.h
@@ -52,7 +52,8 @@
/* B-tree IDs for various internal things. */
typedef enum H5B2_subid_t {
H5B2_TEST_ID = 0, /* B-tree is for testing (do not use for actual data) */
- H5B2_NUM_BTREE_ID /* Number of B-tree IDs (must be last) */
+ H5B2_FHEAP_ID, /* B-tree is for fractal heap */
+ H5B2_NUM_BTREE_ID /* Number of B-tree IDs (must be last) */
} H5B2_subid_t;
/* Define the operator callback function pointer for H5B2_iterate() */
@@ -64,6 +65,9 @@ typedef herr_t (*H5B2_found_t)(const void *record, void *op_data);
/* Define the 'modify' callback function pointer for H5B2_modify() */
typedef herr_t (*H5B2_modify_t)(void *record, void *op_data, hbool_t *changed);
+/* Define the 'remove' callback function pointer for H5B2_remove() & H5B2_delete() */
+typedef herr_t (*H5B2_remove_t)(const void *record, void *op_data);
+
/* Comparisons for H5B2_neighbor() call */
typedef enum H5B2_compare_t {
H5B2_COMPARE_LESS, /* Records with keys less than query value */
@@ -71,29 +75,31 @@ typedef enum H5B2_compare_t {
} H5B2_compare_t;
/*
- * Each class of object that can be pointed to by a B-link tree has a
+ * Each class of object that can be pointed to by a B-tree has a
* variable of this type that contains class variables and methods.
*/
-typedef struct H5B2_class_t {
- H5B2_subid_t id; /*id as found in file*/
- size_t nrec_size; /*size of native (memory) record*/
+typedef struct H5B2_class_t H5B2_class_t;
+struct H5B2_class_t {
+ H5B2_subid_t id; /* ID of B-tree class, as found in file */
+ size_t nrec_size; /* Size of native (memory) record */
+ void *cls_private; /* Pointer to class-private information */
/* Store & retrieve record from application to B-tree 'native' form */
- herr_t (*store)(void *nrecord, const void *udata); /* Store record in native record table */
- herr_t (*retrieve)(void *udata, const void *nrecord); /* Retrieve record in native record table */
+ herr_t (*store)(const H5B2_class_t *cls, void *nrecord, const void *udata); /* Store record in native record table */
+ herr_t (*retrieve)(const H5B2_class_t *cls, void *udata, const void *nrecord); /* Retrieve record in native record table */
/* Compare records, according to a key */
- herr_t (*compare)(const void *rec1, const void *rec2); /* Compare two native records */
+ herr_t (*compare)(const H5B2_class_t *cls, const void *rec1, const void *rec2); /* Compare two native records */
/* Encode & decode record values */
- herr_t (*encode)(const H5F_t *f, uint8_t *raw, const void *record); /* Encode record from native form to disk storage form */
- herr_t (*decode)(const H5F_t *f, const uint8_t *raw, void *record); /* Decode record from disk storage form to native form */
+ herr_t (*encode)(const H5F_t *f, const H5B2_class_t *cls, uint8_t *raw, const void *record); /* Encode record from native form to disk storage form */
+ herr_t (*decode)(const H5F_t *f, const H5B2_class_t *cls, const uint8_t *raw, void *record); /* Decode record from disk storage form to native form */
/* Debug record values */
- herr_t (*debug) (FILE *stream, const H5F_t *f, hid_t dxpl_id, /* Print a record for debugging */
- int indent, int fwidth, const void *record, const void *udata);
-
-} H5B2_class_t;
+ herr_t (*debug)(FILE *stream, const H5F_t *f, hid_t dxpl_id, /* Print a record for debugging */
+ int indent, int fwidth, const H5B2_class_t *cls, const void *record,
+ const void *udata);
+};
/* v2 B-tree metadata statistics info */
typedef struct H5B2_stat_t {
@@ -125,11 +131,11 @@ H5_DLL herr_t H5B2_neighbor(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
H5_DLL herr_t H5B2_modify(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
haddr_t addr, void *udata, H5B2_modify_t op, void *op_data);
H5_DLL herr_t H5B2_remove(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
- haddr_t addr, void *udata);
+ haddr_t addr, void *udata, H5B2_remove_t op, void *op_data);
H5_DLL herr_t H5B2_get_nrec(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
haddr_t addr, hsize_t *nrec);
H5_DLL herr_t H5B2_delete(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
- haddr_t addr);
+ haddr_t addr, H5B2_remove_t op, void *op_data);
/* Statistics routines */
H5_DLL herr_t H5B2_stat_info(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type,
diff --git a/src/H5B2test.c b/src/H5B2test.c
index 3d3f787..68f26ee 100644
--- a/src/H5B2test.c
+++ b/src/H5B2test.c
@@ -51,28 +51,29 @@
/********************/
/* Local Prototypes */
/********************/
-static herr_t H5B2_test_store(void *nrecord, const void *udata);
-static herr_t H5B2_test_retrieve(void *udata, const void *nrecord);
-static herr_t H5B2_test_compare(const void *rec1, const void *rec2);
-static herr_t H5B2_test_encode(const H5F_t *f, uint8_t *raw,
+static herr_t H5B2_test_store(const H5B2_class_t *cls, void *nrecord, const void *udata);
+static herr_t H5B2_test_retrieve(const H5B2_class_t *cls, void *udata, const void *nrecord);
+static herr_t H5B2_test_compare(const H5B2_class_t *cls, const void *rec1, const void *rec2);
+static herr_t H5B2_test_encode(const H5F_t *f, const H5B2_class_t *cls, uint8_t *raw,
const void *nrecord);
-static herr_t H5B2_test_decode(const H5F_t *f, const uint8_t *raw,
+static herr_t H5B2_test_decode(const H5F_t *f, const H5B2_class_t *cls, const uint8_t *raw,
void *nrecord);
static herr_t H5B2_test_debug(FILE *stream, const H5F_t *f, hid_t dxpl_id,
- int indent, int fwidth, const void *record, const void *_udata);
+ int indent, int fwidth, const H5B2_class_t *cls, const void *record, const void *_udata);
/*********************/
/* Package Variables */
/*********************/
const H5B2_class_t H5B2_TEST[1]={{ /* B-tree class information */
- H5B2_TEST_ID, /* Type of B-tree */
- sizeof(hsize_t), /* Size of native key */
- H5B2_test_store, /* Record storage callback */
- H5B2_test_retrieve, /* Record retrieval callback */
- H5B2_test_compare, /* Record comparison callback */
- H5B2_test_encode, /* Record encoding callback */
- H5B2_test_decode, /* Record decoding callback */
- H5B2_test_debug /* Record debugging callback */
+ H5B2_TEST_ID, /* Type of B-tree */
+ sizeof(hsize_t), /* Size of native record */
+ NULL, /* Class private information */
+ H5B2_test_store, /* Record storage callback */
+ H5B2_test_retrieve, /* Record retrieval callback */
+ H5B2_test_compare, /* Record comparison callback */
+ H5B2_test_encode, /* Record encoding callback */
+ H5B2_test_decode, /* Record decoding callback */
+ H5B2_test_debug /* Record debugging callback */
}};
/*****************************/
@@ -100,7 +101,7 @@ const H5B2_class_t H5B2_TEST[1]={{ /* B-tree class information */
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2_test_store(void *nrecord, const void *udata)
+H5B2_test_store(const H5B2_class_t UNUSED *cls, void *nrecord, const void *udata)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_store)
@@ -125,7 +126,7 @@ H5B2_test_store(void *nrecord, const void *udata)
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2_test_retrieve(void *udata, const void *nrecord)
+H5B2_test_retrieve(const H5B2_class_t UNUSED *cls, void *udata, const void *nrecord)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_retrieve)
@@ -150,7 +151,7 @@ H5B2_test_retrieve(void *udata, const void *nrecord)
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2_test_compare(const void *rec1, const void *rec2)
+H5B2_test_compare(const H5B2_class_t UNUSED *cls, const void *rec1, const void *rec2)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_compare)
@@ -173,7 +174,7 @@ H5B2_test_compare(const void *rec1, const void *rec2)
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2_test_encode(const H5F_t *f, uint8_t *raw, const void *nrecord)
+H5B2_test_encode(const H5F_t *f, const H5B2_class_t UNUSED *cls, uint8_t *raw, const void *nrecord)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_encode)
@@ -198,7 +199,7 @@ H5B2_test_encode(const H5F_t *f, uint8_t *raw, const void *nrecord)
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2_test_decode(const H5F_t *f, const uint8_t *raw, void *nrecord)
+H5B2_test_decode(const H5F_t *f, const H5B2_class_t UNUSED *cls, const uint8_t *raw, void *nrecord)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_decode)
@@ -223,8 +224,9 @@ H5B2_test_decode(const H5F_t *f, const uint8_t *raw, void *nrecord)
*-------------------------------------------------------------------------
*/
static herr_t
-H5B2_test_debug(FILE *stream, const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, int indent, int fwidth,
- const void *record, const void UNUSED *_udata)
+H5B2_test_debug(FILE *stream, const H5F_t UNUSED *f, hid_t UNUSED dxpl_id,
+ int indent, int fwidth, const H5B2_class_t UNUSED *cls, const void *record,
+ const void UNUSED *_udata)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5B2_test_debug)