summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-03-05 04:04:54 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-03-05 04:04:54 (GMT)
commit9845d40eb5e13f31c33678f834b77451c84a24b7 (patch)
treee027e8a5a4d6064fabb5f1783ef27eaad0bcc3ce /src
parent009f57c1ba45645f3029f54f9e0cdc74f9fe5822 (diff)
downloadhdf5-9845d40eb5e13f31c33678f834b77451c84a24b7.zip
hdf5-9845d40eb5e13f31c33678f834b77451c84a24b7.tar.gz
hdf5-9845d40eb5e13f31c33678f834b77451c84a24b7.tar.bz2
[svn-r10153] Purpose:
New feature Description: Allow records in internal nodes to be removed, not just records in leaf nodes. Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti)
Diffstat (limited to 'src')
-rw-r--r--src/H5B2.c113
-rw-r--r--src/H5Edefin.h1
-rw-r--r--src/H5Einit.h5
-rw-r--r--src/H5Epubgen.h2
-rw-r--r--src/H5Eterm.h1
-rw-r--r--src/H5err.txt1
6 files changed, 121 insertions, 2 deletions
diff --git a/src/H5B2.c b/src/H5B2.c
index 36d57be..0296454 100644
--- a/src/H5B2.c
+++ b/src/H5B2.c
@@ -77,6 +77,8 @@ static herr_t H5B2_merge2(H5F_t *f, hid_t dxpl_id, unsigned depth,
static herr_t H5B2_merge3(H5F_t *f, hid_t dxpl_id, unsigned depth,
H5B2_node_ptr_t *curr_node_ptr, H5AC_info_t *parent_cache_info,
H5B2_internal_t *internal, unsigned idx);
+static herr_t H5B2_swap_child(H5F_t *f, hid_t dxpl_id, unsigned depth,
+ H5B2_internal_t *internal, unsigned idx);
static herr_t H5B2_insert_internal(H5F_t *f, hid_t dxpl_id,
H5RC_t *bt2_shared, unsigned depth, H5AC_info_t *parent_cache_info,
H5B2_node_ptr_t *curr_node_ptr, void *udata);
@@ -2200,6 +2202,109 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5B2_swap_child
+ *
+ * Purpose: Swap a record in a node with a record in a child node
+ *
+ * Return: Success: Non-negative
+ *
+ * Failure: Negative
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Mar 4 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5B2_swap_child(H5F_t *f, hid_t dxpl_id, unsigned depth,
+ H5B2_internal_t *internal, unsigned idx)
+{
+ const H5AC_class_t *child_class; /* Pointer to child node's class info */
+ haddr_t child_addr; /* Address of child node */
+ void *child; /* Pointer to child node */
+ unsigned *child_nrec; /* Pointer to child # of records */
+ uint8_t *child_native; /* Pointer to child's native records */
+ H5B2_shared_t *shared; /* B-tree's shared info */
+ herr_t ret_value=SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5B2_swap_child)
+
+ HDassert(f);
+ HDassert(internal);
+
+ /* Get the pointer to the shared B-tree info */
+ shared=H5RC_GET_OBJ(internal->shared);
+ HDassert(shared);
+
+ /* Check for the kind of B-tree node to swap */
+ if(depth>1) {
+ H5B2_internal_t *child_internal; /* Pointer to internal node */
+
+ /* Setup information for unlocking child node */
+ child_class = H5AC_BT2_INT;
+ child_addr = child_internal->node_ptrs[idx].addr;
+
+HDfprintf(stderr,"%s: Swapping with internal node in B-tree, untested!\n",FUNC);
+HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "Can't delete record in B-tree")
+ /* Lock B-tree child nodes */
+ if (NULL == (child_internal = H5AC_protect(f, dxpl_id, child_class, child_addr, &(internal->node_ptrs[idx].node_nrec), internal->shared, H5AC_WRITE)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree internal node")
+
+ /* More setup for accessing child node information */
+ child = child_internal;
+ child_nrec = &(child_internal->nrec);
+ child_native = child_internal->int_native;
+
+ /* Mark child node as dirty now */
+ child_internal->cache_info.is_dirty = TRUE;
+ } /* end if */
+ else {
+ H5B2_leaf_t *child_leaf; /* Pointer to leaf node */
+
+ /* Setup information for unlocking child nodes */
+ child_class = H5AC_BT2_LEAF;
+ child_addr = internal->node_ptrs[idx].addr;
+
+ /* Lock B-tree child node */
+ if (NULL == (child_leaf = H5AC_protect(f, dxpl_id, child_class, child_addr, &(internal->node_ptrs[idx].node_nrec), internal->shared, H5AC_WRITE)))
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree leaf node")
+
+ /* More setup for accessing child node information */
+ child = child_leaf;
+ child_nrec = &(child_leaf->nrec);
+ child_native = child_leaf->leaf_native;
+
+ /* Mark child node as dirty now */
+ child_leaf->cache_info.is_dirty = TRUE;
+ } /* end else */
+
+ /* Swap records (use disk page as temporary buffer) */
+ HDmemcpy(shared->page, H5B2_NAT_NREC(child_native,shared,0), shared->type->nrec_size);
+ HDmemcpy(H5B2_NAT_NREC(child_native,shared,0), H5B2_INT_NREC(internal,shared,idx-1), shared->type->nrec_size);
+ HDmemcpy(H5B2_INT_NREC(internal,shared,idx-1), shared->page, shared->type->nrec_size);
+
+ /* Mark parent as dirty */
+ internal->cache_info.is_dirty = TRUE;
+
+#ifdef H5B2_DEBUG
+ H5B2_assert_internal((hsize_t)0,shared,internal);
+ if(depth>1)
+ H5B2_assert_internal(internal->node_ptrs[idx].all_nrec,shared,child);
+ else
+ H5B2_assert_leaf(shared,child);
+#endif /* H5B2_DEBUG */
+
+ /* Unlock child node */
+ if (H5AC_unprotect(f, dxpl_id, child_class, child_addr, child, H5AC__NO_FLAGS_SET) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree child node")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value);
+} /* end H5B2_swap_child */
+
+
+/*-------------------------------------------------------------------------
* Function: H5B2_insert_leaf
*
* Purpose: Adds a new record to a B-tree leaf node.
@@ -3304,8 +3409,12 @@ H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
/* Handle deleting a record from an internal node */
if(cmp==0) {
-HDfprintf(stderr,"%s: Deleting record in internal node of non-trival B-tree!\n",FUNC);
-HGOTO_ERROR(H5E_BTREE, H5E_CANTDELETE, FAIL, "Can't delete record in B-tree")
+ /* Increment the index to work with */
+ idx++;
+
+ /* Swap record to delete with record from child */
+ if(H5B2_swap_child(f,dxpl_id,depth,internal,idx) < 0)
+ HGOTO_ERROR(H5E_BTREE, H5E_CANTSWAP, FAIL, "Can't swap records in B-tree")
} /* end if */
diff --git a/src/H5Edefin.h b/src/H5Edefin.h
index 22f825c..b081b16 100644
--- a/src/H5Edefin.h
+++ b/src/H5Edefin.h
@@ -163,6 +163,7 @@ hid_t H5E_CANTENCODE_g = FAIL; /* Unable to encode value */
hid_t H5E_CANTDECODE_g = FAIL; /* Unable to decode value */
hid_t H5E_CANTSPLIT_g = FAIL; /* Unable to split node */
hid_t H5E_CANTREDISTRIBUTE_g = FAIL; /* Unable to redistribute records */
+hid_t H5E_CANTSWAP_g = FAIL; /* Unable to swap records */
hid_t H5E_CANTINSERT_g = FAIL; /* Unable to insert object */
hid_t H5E_CANTLIST_g = FAIL; /* Unable to list node */
diff --git a/src/H5Einit.h b/src/H5Einit.h
index 05a2aa1..8164584 100644
--- a/src/H5Einit.h
+++ b/src/H5Einit.h
@@ -605,6 +605,11 @@ if((msg = H5E_create_msg(cls, H5E_MINOR, "Unable to redistribute records"))==NUL
HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed")
if((H5E_CANTREDISTRIBUTE_g = H5I_register(H5I_ERROR_MSG, msg))<0)
HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't register error message")
+assert(H5E_CANTSWAP_g==(-1));
+if((msg = H5E_create_msg(cls, H5E_MINOR, "Unable to swap records"))==NULL)
+ HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed")
+if((H5E_CANTSWAP_g = H5I_register(H5I_ERROR_MSG, msg))<0)
+ HGOTO_ERROR(H5E_ERROR, H5E_CANTREGISTER, FAIL, "can't register error message")
assert(H5E_CANTINSERT_g==(-1));
if((msg = H5E_create_msg(cls, H5E_MINOR, "Unable to insert object"))==NULL)
HGOTO_ERROR(H5E_ERROR, H5E_CANTINIT, FAIL, "error message initialization failed")
diff --git a/src/H5Epubgen.h b/src/H5Epubgen.h
index a21989f..6a4fcd1 100644
--- a/src/H5Epubgen.h
+++ b/src/H5Epubgen.h
@@ -271,6 +271,7 @@ H5_DLLVAR hid_t H5E_CANTCOMPARE_g; /* Can't compare objects */
#define H5E_CANTDECODE (H5OPEN H5E_CANTDECODE_g)
#define H5E_CANTSPLIT (H5OPEN H5E_CANTSPLIT_g)
#define H5E_CANTREDISTRIBUTE (H5OPEN H5E_CANTREDISTRIBUTE_g)
+#define H5E_CANTSWAP (H5OPEN H5E_CANTSWAP_g)
#define H5E_CANTINSERT (H5OPEN H5E_CANTINSERT_g)
#define H5E_CANTLIST (H5OPEN H5E_CANTLIST_g)
H5_DLLVAR hid_t H5E_NOTFOUND_g; /* Object not found */
@@ -279,6 +280,7 @@ H5_DLLVAR hid_t H5E_CANTENCODE_g; /* Unable to encode value */
H5_DLLVAR hid_t H5E_CANTDECODE_g; /* Unable to decode value */
H5_DLLVAR hid_t H5E_CANTSPLIT_g; /* Unable to split node */
H5_DLLVAR hid_t H5E_CANTREDISTRIBUTE_g; /* Unable to redistribute records */
+H5_DLLVAR hid_t H5E_CANTSWAP_g; /* Unable to swap records */
H5_DLLVAR hid_t H5E_CANTINSERT_g; /* Unable to insert object */
H5_DLLVAR hid_t H5E_CANTLIST_g; /* Unable to list node */
diff --git a/src/H5Eterm.h b/src/H5Eterm.h
index ca9413a..67b3415 100644
--- a/src/H5Eterm.h
+++ b/src/H5Eterm.h
@@ -165,6 +165,7 @@ H5E_CANTENCODE_g=
H5E_CANTDECODE_g=
H5E_CANTSPLIT_g=
H5E_CANTREDISTRIBUTE_g=
+H5E_CANTSWAP_g=
H5E_CANTINSERT_g=
H5E_CANTLIST_g=
diff --git a/src/H5err.txt b/src/H5err.txt
index 3836cb0..dcfb5b0 100644
--- a/src/H5err.txt
+++ b/src/H5err.txt
@@ -163,6 +163,7 @@ MINOR, BTREE, H5E_CANTENCODE, Unable to encode value
MINOR, BTREE, H5E_CANTDECODE, Unable to decode value
MINOR, BTREE, H5E_CANTSPLIT, Unable to split node
MINOR, BTREE, H5E_CANTREDISTRIBUTE, Unable to redistribute records
+MINOR, BTREE, H5E_CANTSWAP, Unable to swap records
MINOR, BTREE, H5E_CANTINSERT, Unable to insert object
MINOR, BTREE, H5E_CANTLIST, Unable to list node