/*-------------------------------------------------------------------------- NAME H5HP_insert PURPOSE Insert an object into a heap, with an initial value USAGE herr_t H5HP_insert(heap, val, obj) H5HP_t *heap; IN/OUT: Pointer to heap to modify int val; IN: Initial value for object in heap void *obj; IN: Pointer to object to insert into heap RETURNS Returns non-negative on success, negative on failure. DESCRIPTION Inserts a OBJ into a HEAP, with an initial VALue. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ herr_t H5HP_insert(H5HP_t *heap, int val, void *obj) { herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) /* Check args */ HDassert(heap); HDassert(obj); /* Check internal consistency */ /* (Pre-condition) */ HDassert(heap->nobjs<heap->nalloc); HDassert(heap->heap); HDassert((heap->type==H5HP_MAX_HEAP && heap->heap[0].val==INT_MAX) || (heap->type==H5HP_MIN_HEAP && heap->heap[0].val==INT_MIN)); HDassert(heap->heap[0].obj==NULL); /* Increment number of objects in heap */ heap->nobjs++; /* Check if we need to allocate more room for heap array */ if(heap->nobjs>=heap->nalloc) { size_t n = MAX(H5HP_START_SIZE, 2*(heap->nalloc-1)) + 1; H5HP_ent_t *new_heap = H5FL_SEQ_REALLOC(H5HP_ent_t,heap->heap, n); if (!new_heap) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to extend heap array"); heap->heap = new_heap; heap->nalloc = n; } /* end if */ /* Insert new object at end of heap */ heap->heap[heap->nobjs].val = val; heap->heap[heap->nobjs].obj = (H5HP_info_t *)obj; heap->heap[heap->nobjs].obj->heap_loc = heap->nobjs; /* Restore heap condition */ if(heap->type==H5HP_MAX_HEAP) { if(H5HP_swim_max(heap,heap->nobjs)<0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINSERT, FAIL, "unable to restore heap condition"); } /* end if */ else { if(H5HP_swim_min(heap,heap->nobjs)<0) HGOTO_ERROR(H5E_HEAP, H5E_CANTINSERT, FAIL, "unable to restore heap condition"); } /* end else */ done: /* Check internal consistency */ /* (Post-condition) */ HDassert(heap->nobjs<heap->nalloc); HDassert(heap->heap); HDassert((heap->type==H5HP_MAX_HEAP && heap->heap[0].val==INT_MAX) || (heap->type==H5HP_MIN_HEAP && heap->heap[0].val==INT_MIN)); HDassert(heap->heap[0].obj==NULL); FUNC_LEAVE_NOAPI(ret_value); } /* end H5HP_insert() */
/*------------------------------------------------------------------------- * Function: H5A_compact_build_table_cb * * Purpose: Object header iterator callback routine to copy attribute * into table. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol * [email protected] * Dec 18 2006 * * Modification:Raymond Lu * 24 June 2008 * Changed the table of attribute objects to be the table of * pointers to attribute objects for the ease of operation. * * Vailin Choi; September 2011 * Change "oh_modified" from boolean to unsigned * (See H5Oprivate.h for possible flags) *------------------------------------------------------------------------- */ static herr_t H5A_compact_build_table_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, unsigned sequence, unsigned UNUSED *oh_modified, void *_udata/*in,out*/) { H5A_compact_bt_ud_t *udata = (H5A_compact_bt_ud_t *)_udata; /* Operator user data */ herr_t ret_value = H5_ITER_CONT; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* check args */ HDassert(mesg); /* Re-allocate the table if necessary */ if(udata->curr_attr == udata->atable->nattrs) { H5A_t **new_table; /* New table for attributes */ size_t new_table_size; /* Number of attributes in new table */ /* Allocate larger table */ new_table_size = MAX(1, 2 * udata->atable->nattrs); if(NULL == (new_table = (H5A_t **)H5FL_SEQ_REALLOC(H5A_t_ptr, udata->atable->attrs, new_table_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "unable to extend attribute table") /* Update table information in user data */ udata->atable->attrs = new_table; udata->atable->nattrs = new_table_size; } /* end if */ /* Copy attribute into table */ if(NULL == (udata->atable->attrs[udata->curr_attr] = H5A_copy(NULL, (const H5A_t *)mesg->native))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") /* Assign [somewhat arbitrary] creation order value, if requested */ if(udata->bogus_crt_idx) ((udata->atable->attrs[udata->curr_attr])->shared)->crt_idx = sequence; /* Increment current attribute */ udata->curr_attr++; done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_compact_build_table_cb() */