summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-03-29 21:26:25 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-03-29 21:26:25 (GMT)
commitd484bd9fb720feecf1ff5249bd096752c187e411 (patch)
tree20bc7dc1018fd6a3d976d53b6f066dcd012298c8 /src
parent785b356d4079e465422f66adeda0281c404242f1 (diff)
downloadhdf5-d484bd9fb720feecf1ff5249bd096752c187e411.zip
hdf5-d484bd9fb720feecf1ff5249bd096752c187e411.tar.gz
hdf5-d484bd9fb720feecf1ff5249bd096752c187e411.tar.bz2
[svn-r10504] Purpose:
New feature Description: Add wrapper for v2 B-tree "neighbor" routine. Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti)
Diffstat (limited to 'src')
-rw-r--r--src/H5BT.c142
-rw-r--r--src/H5BTpkg.h7
-rw-r--r--src/H5BTprivate.h28
3 files changed, 166 insertions, 11 deletions
diff --git a/src/H5BT.c b/src/H5BT.c
index 2373b9e..20c35a7 100644
--- a/src/H5BT.c
+++ b/src/H5BT.c
@@ -655,14 +655,14 @@ done:
/*-------------------------------------------------------------------------
* Function: H5BT_locate_cb
*
- * Purpose: v2 B-tree find callback
+ * Purpose: Block tracker "locate" callback
*
* Return: Success: 0
*
* Failure: 1
*
* Programmer: Quincey Koziol
- * Friday, March 11, 2005
+ * Friday, March 25, 2005
*
* Modifications:
*
@@ -718,14 +718,14 @@ H5BT_locate(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t size, haddr_t *locate
HDassert(H5F_addr_defined(addr));
/* Look up the block tracker header */
- if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_WRITE)))
+ if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_BLKTRK, H5E_CANTPROTECT, FAIL, "unable to load block tracker info")
/* Iterate through blocks, looking for first one that is large enough */
found.search_size = size;
found.found.addr = HADDR_UNDEF;
if (H5B2_iterate(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, H5BT_locate_cb, &found) < 0)
- HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to locate block")
+ HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to iterate over blocks")
/* Update user's information, if block was found */
if(H5F_addr_defined(found.found.addr)) {
@@ -747,6 +747,140 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5BT_iterate
+ *
+ * Purpose: Iterate over blocks in tracker, making callback for each
+ *
+ * If the callback returns non-zero, the iteration breaks out
+ * without finishing all the records.
+ *
+ * Return: Value from callback: non-negative on success, negative on error
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Mar 25 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5BT_iterate(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5BT_operator_t op, void *op_data)
+{
+ H5BT_t *bt = NULL; /* The new B-tree header information */
+ herr_t ret_value;
+
+ FUNC_ENTER_NOAPI(H5BT_iterate, FAIL)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(f);
+ HDassert(H5F_addr_defined(addr));
+ HDassert(op);
+
+ /* Look up the block tracker header */
+ if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_READ)))
+ HGOTO_ERROR(H5E_BLKTRK, H5E_CANTPROTECT, FAIL, "unable to load block tracker info")
+
+ /* Iterate through blocks, passing along op & op_data */
+ if ((ret_value = H5B2_iterate(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, (H5B2_operator_t)op, op_data)) < 0)
+ HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to iterate over blocks")
+
+done:
+ /* Release the block tracker info */
+ if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BLTR, addr, bt, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_BLKTRK, H5E_CANTUNPROTECT, FAIL, "unable to release block tracker info")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5BT_iterate() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5BT_neighbor_cb
+ *
+ * Purpose: Block tracker "neighbor" callback
+ *
+ * Return: Success: 0
+ *
+ * Failure: 1
+ *
+ * Programmer: Quincey Koziol
+ * Monday, March 28, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+H5BT_neighbor_cb(const void *_record, void *_op_data)
+{
+ const H5BT_blk_info_t *record = (const H5BT_blk_info_t *)_record;
+ H5BT_blk_info_t *search = (H5BT_blk_info_t *)_op_data;
+
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5BT_neighbor_cb)
+
+ /* Save block information for later */
+ *search = *record;
+
+ FUNC_LEAVE_NOAPI(SUCCEED);
+} /* end H5BT_neighbor_cb() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5BT_neighbor
+ *
+ * Purpose: Locate block that is related to a given address
+ *
+ * Return: Non-negative on success, negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Mar 28 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5BT_neighbor(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5BT_compare_t range,
+ haddr_t range_addr, H5BT_blk_info_t *found_block)
+{
+ H5BT_t *bt = NULL; /* The new B-tree header information */
+ H5BT_blk_info_t find; /* Information for locating block */
+ H5BT_blk_info_t found; /* Block info found */
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_NOAPI(H5BT_neighbor, FAIL)
+
+ /*
+ * Check arguments.
+ */
+ HDassert(f);
+ HDassert(H5F_addr_defined(addr));
+
+ /* Look up the block tracker header */
+ if (NULL == (bt = H5AC_protect(f, dxpl_id, H5AC_BLTR, addr, NULL, NULL, H5AC_READ)))
+ HGOTO_ERROR(H5E_BLKTRK, H5E_CANTPROTECT, FAIL, "unable to load block tracker info")
+
+ /* Iterate through blocks, looking for first one that is large enough */
+ find.addr = range_addr;
+ find.len = 0;
+ found.addr = HADDR_UNDEF;
+ if (H5B2_neighbor(f, dxpl_id, H5B2_BLKTRK, bt->bt2_addr, (H5B2_compare_t)range,
+ &find, H5BT_neighbor_cb, &found) < 0)
+ HGOTO_ERROR(H5E_BLKTRK, H5E_NOTFOUND, FAIL, "unable to find neighbor for block")
+
+ /* Update user's information, if block was found */
+ if(H5F_addr_defined(found.addr))
+ *found_block = found;
+
+done:
+ /* Release the block tracker info */
+ if (bt && H5AC_unprotect(f, dxpl_id, H5AC_BLTR, addr, bt, H5AC__NO_FLAGS_SET) < 0)
+ HDONE_ERROR(H5E_BLKTRK, H5E_CANTUNPROTECT, FAIL, "unable to release block tracker info")
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5BT_neighbor() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5BT_delete
*
* Purpose: Delete a block tracker from a file
diff --git a/src/H5BTpkg.h b/src/H5BTpkg.h
index e9140ec..2de481d 100644
--- a/src/H5BTpkg.h
+++ b/src/H5BTpkg.h
@@ -32,7 +32,6 @@
/* Other private headers needed by this file */
#include "H5ACprivate.h" /* Metadata cache */
-#include "H5B2private.h" /* v2 B-trees */
#include "H5FLprivate.h" /* Free Lists */
/**************************/
@@ -87,12 +86,6 @@ typedef struct H5BT_t {
haddr_t bt2_addr; /* Address of v2 B-tree that holds block info */
} H5BT_t;
-/* Info for a single block */
-typedef struct H5BT_blk_info_t {
- haddr_t addr; /* Address (offset) of block in file */
- hsize_t len; /* Length of block in file */
-} H5BT_blk_info_t;
-
/*****************************/
/* Package Private Variables */
diff --git a/src/H5BTprivate.h b/src/H5BTprivate.h
index f6470e5..3eab872 100644
--- a/src/H5BTprivate.h
+++ b/src/H5BTprivate.h
@@ -30,17 +30,41 @@
#include "H5BTpublic.h"
/* Private headers needed by this file */
+#include "H5B2private.h" /* v2 B-trees */
#include "H5Fprivate.h" /* File access */
/**************************/
/* Library Private Macros */
/**************************/
+/* Define return values from operator callback function for H5BT_iterate */
+/* (Actually, any positive value will cause the iterator to stop and pass back
+ * that positive value to the function that called the iterator)
+ */
+#define H5BT_ITER_ERROR H5B2_ITER_ERROR
+#define H5BT_ITER_CONT H5B2_ITER_CONT
+#define H5BT_ITER_STOP H5B2_ITER_STOP
+
/****************************/
/* Library Private Typedefs */
/****************************/
+/* Info for a single block (stored as record in B-tree) */
+typedef struct H5BT_blk_info_t {
+ haddr_t addr; /* Address (offset) of block in file */
+ hsize_t len; /* Length of block in file */
+} H5BT_blk_info_t;
+
+/* Define the operator callback function pointer for H5BT_iterate() */
+typedef int (*H5BT_operator_t)(const H5BT_blk_info_t *record, void *op_data);
+
+/* Comparisons for H5BT_neighbor() call */
+typedef enum H5BT_compare_t {
+ H5BT_COMPARE_LESS = H5B2_COMPARE_LESS, /* Records with keys less than query value */
+ H5BT_COMPARE_GREATER = H5B2_COMPARE_GREATER /* Records with keys greater than query value */
+} H5BT_compare_t;
+
/***************************************/
/* Library-private Function Prototypes */
@@ -54,6 +78,10 @@ H5_DLL herr_t H5BT_get_total_size(H5F_t *f, hid_t dxpl_id, haddr_t addr,
hsize_t *tot_size);
H5_DLL herr_t H5BT_locate(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t size,
haddr_t *locate_addr, hsize_t *locate_size);
+H5_DLL herr_t H5BT_iterate(H5F_t *f, hid_t dxpl_id, haddr_t addr,
+ H5BT_operator_t op, void *op_data);
+H5_DLL herr_t H5BT_neighbor(H5F_t *f, hid_t dxpl_id, haddr_t addr,
+ H5BT_compare_t range, haddr_t range_addr, H5BT_blk_info_t *found_block);
H5_DLL herr_t H5BT_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr);
#endif /* _H5BTprivate_H */