diff options
Diffstat (limited to 'src/H5HFdtable.c')
-rw-r--r-- | src/H5HFdtable.c | 146 |
1 files changed, 57 insertions, 89 deletions
diff --git a/src/H5HFdtable.c b/src/H5HFdtable.c index 1952a30..cdf3ed6 100644 --- a/src/H5HFdtable.c +++ b/src/H5HFdtable.c @@ -6,7 +6,7 @@ * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * distribution tree, or in https://www.hdfgroup.org/licenses. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -15,7 +15,7 @@ * * Created: H5HFdtable.c * Apr 10 2006 - * Quincey Koziol <koziol@ncsa.uiuc.edu> + * Quincey Koziol * * Purpose: "Doubling table" routines for fractal heaps. * @@ -26,53 +26,45 @@ /* Module Setup */ /****************/ -#define H5HF_PACKAGE /*suppress error about including H5HFpkg */ +#define H5HF_PACKAGE /*suppress error about including H5HFpkg */ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5HFpkg.h" /* Fractal heaps */ -#include "H5MMprivate.h" /* Memory management */ -#include "H5VMprivate.h" /* Vectors and arrays */ +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5HFpkg.h" /* Fractal heaps */ +#include "H5MMprivate.h" /* Memory management */ +#include "H5VMprivate.h" /* Vectors and arrays */ /****************/ /* Local Macros */ /****************/ - /******************/ /* Local Typedefs */ /******************/ - /********************/ /* Package Typedefs */ /********************/ - /********************/ /* Local Prototypes */ /********************/ - /*********************/ /* Package Variables */ /*********************/ - /*****************************/ /* Library Private Variables */ /*****************************/ - /*******************/ /* Local Variables */ /*******************/ - - /*------------------------------------------------------------------------- * Function: H5HF_dtable_init * @@ -81,7 +73,6 @@ * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu * Mar 6 2006 * *------------------------------------------------------------------------- @@ -89,10 +80,10 @@ herr_t H5HF_dtable_init(H5HF_dtable_t *dtable) { - hsize_t tmp_block_size; /* Temporary block size */ - hsize_t acc_block_off; /* Accumulated block offset */ - size_t u; /* Local index variable */ - herr_t ret_value = SUCCEED; /* Return value */ + hsize_t tmp_block_size; /* Temporary block size */ + hsize_t acc_block_off; /* Accumulated block offset */ + size_t u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -102,30 +93,33 @@ H5HF_dtable_init(H5HF_dtable_t *dtable) HDassert(dtable); /* Compute/cache some values */ - dtable->start_bits = H5VM_log2_of2((uint32_t)dtable->cparam.start_block_size); - dtable->first_row_bits = dtable->start_bits + H5VM_log2_of2(dtable->cparam.width); - dtable->max_root_rows = (dtable->cparam.max_index - dtable->first_row_bits) + 1; - dtable->max_direct_bits = H5VM_log2_of2((uint32_t)dtable->cparam.max_direct_size); - dtable->max_direct_rows = (dtable->max_direct_bits - dtable->start_bits) + 2; - dtable->num_id_first_row = dtable->cparam.start_block_size * dtable->cparam.width; + dtable->start_bits = H5VM_log2_of2((uint32_t)dtable->cparam.start_block_size); + dtable->first_row_bits = dtable->start_bits + H5VM_log2_of2(dtable->cparam.width); + dtable->max_root_rows = (dtable->cparam.max_index - dtable->first_row_bits) + 1; + dtable->max_direct_bits = H5VM_log2_of2((uint32_t)dtable->cparam.max_direct_size); + dtable->max_direct_rows = (dtable->max_direct_bits - dtable->start_bits) + 2; + dtable->num_id_first_row = dtable->cparam.start_block_size * dtable->cparam.width; dtable->max_dir_blk_off_size = H5HF_SIZEOF_OFFSET_LEN(dtable->cparam.max_direct_size); /* Build table of block sizes for each row */ - if(NULL == (dtable->row_block_size = (hsize_t *)H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table block size table") - if(NULL == (dtable->row_block_off = (hsize_t *)H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table block offset table") - if(NULL == (dtable->row_tot_dblock_free = (hsize_t *)H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table total direct block free space table") - if(NULL == (dtable->row_max_dblock_free = (size_t *)H5MM_malloc(dtable->max_root_rows * sizeof(size_t)))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table max. direct block free space table") - tmp_block_size = dtable->cparam.start_block_size; - acc_block_off = dtable->cparam.start_block_size * dtable->cparam.width; + if (NULL == (dtable->row_block_size = (hsize_t *)H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table block size table") + if (NULL == (dtable->row_block_off = (hsize_t *)H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create doubling table block offset table") + if (NULL == + (dtable->row_tot_dblock_free = (hsize_t *)H5MM_malloc(dtable->max_root_rows * sizeof(hsize_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "can't create doubling table total direct block free space table") + if (NULL == (dtable->row_max_dblock_free = (size_t *)H5MM_malloc(dtable->max_root_rows * sizeof(size_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, + "can't create doubling table max. direct block free space table") + tmp_block_size = dtable->cparam.start_block_size; + acc_block_off = dtable->cparam.start_block_size * dtable->cparam.width; dtable->row_block_size[0] = dtable->cparam.start_block_size; - dtable->row_block_off[0] = 0; - for(u = 1; u < dtable->max_root_rows; u++) { + dtable->row_block_off[0] = 0; + for (u = 1; u < dtable->max_root_rows; u++) { dtable->row_block_size[u] = tmp_block_size; - dtable->row_block_off[u] = acc_block_off; + dtable->row_block_off[u] = acc_block_off; tmp_block_size *= 2; acc_block_off *= 2; } /* end for */ @@ -134,7 +128,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5HF_dtable_init() */ - /*------------------------------------------------------------------------- * Function: H5HF_dtable_lookup * @@ -143,7 +136,6 @@ done: * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu * Mar 6 2006 * *------------------------------------------------------------------------- @@ -159,22 +151,16 @@ H5HF_dtable_lookup(const H5HF_dtable_t *dtable, hsize_t off, unsigned *row, unsi HDassert(dtable); HDassert(row); HDassert(col); -#ifdef QAK -HDfprintf(stderr, "%s: off = %Hu\n", "H5HF_dtable_lookup", off); -#endif /* QAK */ /* Check for offset in first row */ - if(off < dtable->num_id_first_row) { + if (off < dtable->num_id_first_row) { *row = 0; H5_CHECKED_ASSIGN(*col, unsigned, (off / dtable->cparam.start_block_size), hsize_t); } /* end if */ else { - unsigned high_bit = H5VM_log2_gen(off); /* Determine the high bit in the offset */ - hsize_t off_mask = ((hsize_t)1) << high_bit; /* Compute mask for determining column */ + unsigned high_bit = H5VM_log2_gen(off); /* Determine the high bit in the offset */ + hsize_t off_mask = ((hsize_t)1) << high_bit; /* Compute mask for determining column */ -#ifdef QAK -HDfprintf(stderr, "%s: high_bit = %u, off_mask = %Hu\n", "H5HF_dtable_lookup", high_bit, off_mask); -#endif /* QAK */ *row = (high_bit - dtable->first_row_bits) + 1; H5_CHECKED_ASSIGN(*col, unsigned, ((off - off_mask) / dtable->row_block_size[*row]), hsize_t); } /* end else */ @@ -182,7 +168,6 @@ HDfprintf(stderr, "%s: high_bit = %u, off_mask = %Hu\n", "H5HF_dtable_lookup", h FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HF_dtable_lookup() */ - /*------------------------------------------------------------------------- * Function: H5HF_dtable_dest * @@ -191,7 +176,6 @@ HDfprintf(stderr, "%s: high_bit = %u, off_mask = %Hu\n", "H5HF_dtable_lookup", h * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu * Mar 27 2006 * *------------------------------------------------------------------------- @@ -221,7 +205,6 @@ H5HF_dtable_dest(H5HF_dtable_t *dtable) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5HF_dtable_dest() */ - /*------------------------------------------------------------------------- * Function: H5HF_dtable_size_to_row * @@ -230,7 +213,6 @@ H5HF_dtable_dest(H5HF_dtable_t *dtable) * Return: Non-negative on success (can't fail) * * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu * Apr 25 2006 * *------------------------------------------------------------------------- @@ -238,7 +220,7 @@ H5HF_dtable_dest(H5HF_dtable_t *dtable) unsigned H5HF_dtable_size_to_row(const H5HF_dtable_t *dtable, size_t block_size) { - unsigned row; /* Row where block will fit */ + unsigned row = 0; /* Row where block will fit */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -247,15 +229,16 @@ H5HF_dtable_size_to_row(const H5HF_dtable_t *dtable, size_t block_size) */ HDassert(dtable); - if(block_size == dtable->cparam.start_block_size) + if (block_size == dtable->cparam.start_block_size) row = 0; else - row = (H5VM_log2_of2((uint32_t)block_size) - H5VM_log2_of2((uint32_t)dtable->cparam.start_block_size)) + 1; + row = + (H5VM_log2_of2((uint32_t)block_size) - H5VM_log2_of2((uint32_t)dtable->cparam.start_block_size)) + + 1; FUNC_LEAVE_NOAPI(row) } /* end H5HF_dtable_size_to_row() */ - /*------------------------------------------------------------------------- * Function: H5HF_dtable_size_to_rows * @@ -264,7 +247,6 @@ H5HF_dtable_size_to_row(const H5HF_dtable_t *dtable, size_t block_size) * Return: Non-negative on success (can't fail) * * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu * May 31 2006 * *------------------------------------------------------------------------- @@ -272,7 +254,7 @@ H5HF_dtable_size_to_row(const H5HF_dtable_t *dtable, size_t block_size) unsigned H5HF_dtable_size_to_rows(const H5HF_dtable_t *dtable, hsize_t size) { - unsigned rows; /* # of rows required for indirect block */ + unsigned rows = 0; /* # of rows required for indirect block */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -286,7 +268,6 @@ H5HF_dtable_size_to_rows(const H5HF_dtable_t *dtable, hsize_t size) FUNC_LEAVE_NOAPI(rows) } /* end H5HF_dtable_size_to_rows() */ - /*------------------------------------------------------------------------- * Function: H5HF_dtable_span_size * @@ -295,20 +276,19 @@ H5HF_dtable_size_to_rows(const H5HF_dtable_t *dtable, hsize_t size) * Return: Non-zero span size on success/zero on failure * * Programmer: Quincey Koziol - * koziol@ncsa.uiuc.edu * July 25 2006 * *------------------------------------------------------------------------- */ hsize_t -H5HF_dtable_span_size(const H5HF_dtable_t *dtable, unsigned start_row, - unsigned start_col, unsigned num_entries) +H5HF_dtable_span_size(const H5HF_dtable_t *dtable, unsigned start_row, unsigned start_col, + unsigned num_entries) { unsigned start_entry; /* Entry for first block covered */ unsigned end_row; /* Row for last block covered */ unsigned end_col; /* Column for last block covered */ unsigned end_entry; /* Entry for last block covered */ - hsize_t acc_span_size; /* Accumulated span size */ + hsize_t acc_span_size = 0; /* Accumulated span size */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -323,12 +303,8 @@ H5HF_dtable_span_size(const H5HF_dtable_t *dtable, unsigned start_row, /* Compute ending entry, column & row */ end_entry = (start_entry + num_entries) - 1; - end_row = end_entry / dtable->cparam.width; - end_col = end_entry % dtable->cparam.width; -#ifdef QAK -HDfprintf(stderr, "%s: start_row = %u, start_col = %u, start_entry = %u\n", "H5HF_sect_indirect_span_size", start_row, start_col, start_entry); -HDfprintf(stderr, "%s: end_row = %u, end_col = %u, end_entry = %u\n", "H5HF_sect_indirect_span_size", end_row, end_col, end_entry); -#endif /* QAK */ + end_row = end_entry / dtable->cparam.width; + end_col = end_entry % dtable->cparam.width; /* Initialize accumulated span size */ acc_span_size = 0; @@ -336,34 +312,26 @@ HDfprintf(stderr, "%s: end_row = %u, end_col = %u, end_entry = %u\n", "H5HF_sect /* Compute span size covered */ /* Check for multi-row span */ - if(start_row != end_row) { - /* Accomodate partial starting row */ - if(start_col > 0) { - acc_span_size = dtable->row_block_size[start_row] * - (dtable->cparam.width - start_col); + if (start_row != end_row) { + /* Accommodate partial starting row */ + if (start_col > 0) { + acc_span_size = dtable->row_block_size[start_row] * (dtable->cparam.width - start_col); start_row++; } /* end if */ /* Accumulate full rows */ - while(start_row < end_row) { - acc_span_size += dtable->row_block_size[start_row] * - dtable->cparam.width; + while (start_row < end_row) { + acc_span_size += dtable->row_block_size[start_row] * dtable->cparam.width; start_row++; } /* end while */ - /* Accomodate partial ending row */ - acc_span_size += dtable->row_block_size[start_row] * - (end_col + 1); + /* Accommodate partial ending row */ + acc_span_size += dtable->row_block_size[start_row] * (end_col + 1); } /* end if */ else { /* Span is in same row */ - acc_span_size = dtable->row_block_size[start_row] * - ((end_col - start_col) + 1); + acc_span_size = dtable->row_block_size[start_row] * ((end_col - start_col) + 1); } /* end else */ -#ifdef QAK -HDfprintf(stderr, "%s: acc_span_size = %Hu\n", "H5HF_dtable_span_size", acc_span_size); -#endif /* QAK */ FUNC_LEAVE_NOAPI(acc_span_size) } /* end H5HF_sect_indirect_span_size() */ - |