Commit cd2ff6cc authored by Karl Wette's avatar Karl Wette

LALHeap: add function XLALHeapIsFull()

- Return >0 if a limited-size heap is full, 0 otherwise
  (or if heap has unlimited size), or <0 on error
Original: c566bb3373e7caa5742a9e23dbe0732de62dc453
parent d3ff5dbd
......@@ -135,7 +135,7 @@ static int heap_add_not_full(
heap_bubble_up( h, h->n - 1 );
/* If (limited) heap is now full, switch add function to heap_add_full() */
if ( h->max_size > 0 && h->n == h->max_size ) {
if ( XLALHeapIsFull( h ) ) {
h->add = heap_add_full;
}
......@@ -222,6 +222,14 @@ int XLALHeapMaxSize(
return h->max_size;
}
int XLALHeapIsFull(
const LALHeap *h
)
{
XLAL_CHECK( h != NULL, XLAL_EFAULT );
return h->max_size > 0 && h->n == h->max_size;
}
const void *XLALHeapRoot(
const LALHeap *h
)
......
......@@ -108,6 +108,13 @@ int XLALHeapMaxSize(
const LALHeap *h /**< [in] Pointer to heap */
);
/**
* Return >0 if a limited-size heap is full, 0 otherwise (or if heap has unlimited size), or <0 on error
*/
int XLALHeapIsFull(
const LALHeap *h /**< [in] Pointer to heap */
);
/**
* Return the root element of a heap
*/
......
......@@ -116,6 +116,7 @@ int main( void )
/* Add integer to unlimited min-heap, and check properties */
{
XLAL_CHECK_MAIN( XLALHeapIsFull( minh ) == 0, XLAL_EFAILED );
void *x = NULL;
x = new_int( input[i] );
XLAL_CHECK_MAIN( x != NULL, XLAL_ENOMEM );
......@@ -138,6 +139,7 @@ int main( void )
/* Add integer to unlimited max-heap, and check properties */
{
XLAL_CHECK_MAIN( XLALHeapIsFull( maxh ) == 0, XLAL_EFAILED );
void *x = NULL;
x = new_int( input[i] );
XLAL_CHECK_MAIN( x != NULL, XLAL_ENOMEM );
......@@ -160,6 +162,7 @@ int main( void )
/* Add integer to limited min-heap, and check properties */
{
XLAL_CHECK_MAIN( XLALHeapIsFull( min10h ) == (i >= 10), XLAL_EFAILED );
void *x = new_int( input[i] );
XLAL_CHECK_MAIN( x != NULL, XLAL_ENOMEM );
XLAL_CHECK_MAIN( XLALHeapAdd( min10h, &x ) == XLAL_SUCCESS, XLAL_EFUNC );
......@@ -188,6 +191,7 @@ int main( void )
/* Add integer to limited max-heap, and check properties */
{
XLAL_CHECK_MAIN( XLALHeapIsFull( max10h ) == (i >= 10), XLAL_EFAILED );
void *x = new_int( input[i] );
XLAL_CHECK_MAIN( x != NULL, XLAL_ENOMEM );
XLAL_CHECK_MAIN( XLALHeapAdd( max10h, &x ) == XLAL_SUCCESS, XLAL_EFUNC );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment