21#include <gsl/gsl_rng.h>
22#include <lal/LALHeap.h>
25#define UNUSED __attribute__ ((unused))
37 return *( (
const int * )
x ) - *( (
const int * )
y );
42 return cmp_ptr_int( *( (
const void *
const * )
x ), *( (
const void *
const * )
y ) );
47 printf(
" %i", *( (
const int * )
x ) );
53 int ***
y = (
int ** * ) param;
59 *( (
int * )
x ) = *( (
int * ) param ) - *( (
int * )
x );
67 setvbuf( stdout, NULL, _IONBF, 0 );
68 setvbuf( stderr, NULL, _IONBF, 0 );
93 gsl_rng *
r = gsl_rng_alloc( gsl_rng_mt19937 );
95 for (
size_t i = 0; i < 100; ++i ) {
96 input[i] = -37 + gsl_rng_uniform_int(
r, 100 );
103 for (
int i = 0; i < 100; ++i ) {
104 printf(
"\n----- i=%i -----\n", i );
111 for (
int j = 0; j <= i; ++j ) {
112 printf(
" %i", *ref[j] );
131 const int r_ref = *ref[0];
133 printf(
", root = %i\n",
r );
135 int **ref0 = &ref[0];
154 const int r_ref = *ref[i];
156 printf(
", root = %i\n",
r );
158 int **ref0 = &ref[0];
169 printf(
"min10h={" );
183 const int r_ref = *ref[( i < 10 ) ? 0 : i-9];
185 printf(
", root = %i\n",
r );
187 int **ref0 = &ref[( i < 10 ) ? 0 : i-9];
198 printf(
"max10h={" );
212 const int r_ref = *ref[( i < 10 ) ? i : 9];
214 printf(
", root = %i\n",
r );
216 int **ref0 = &ref[0];
224 printf(
"\n----- XLALHeapModify() -----\n" );
227 for (
int j = 0; j < 100; ++j ) {
228 *ref[j] = param - *ref[j];
232 for (
int j = 0; j < 100; ++j ) {
233 printf(
" %i", *ref[j] );
243 const int r_ref = *ref[0];
245 printf(
", root = %i\n",
r );
247 int **ref0 = &ref[0];
257 const int r_ref = *ref[99];
259 printf(
", root = %i\n",
r );
261 int **ref0 = &ref[0];
267 printf(
"min10h={" );
271 const int r_ref = *ref[0];
273 printf(
", root = %i\n",
r );
275 int **ref0 = &ref[0];
281 printf(
"max10h={" );
285 const int r_ref = *ref[99];
287 printf(
", root = %i\n",
r );
289 int **ref0 = &ref[90];
297 printf(
"\n----- XLALHeapResize() -----\n" );
300 int **ref0 = &ref[80];
310 int **ref0 = &ref[0];
326 printf(
"\n----- cleanup -----\n" );
static int reverse_ptr_int(void *param, void *x)
static int print_ptr_int(UNUSED void *param, const void *x)
static int cmp_ptr_int(const void *x, const void *y)
static int check_ptr_int(void *param, const void *x)
static void * new_int(int x)
static int cmp_ptr_ptr_int(const void *x, const void *y)
void LALCheckMemoryLeaks(void)
int XLALHeapResize(LALHeap *h, int max_size)
Change the maximum size of a heap; if the heap is contracted, excess elements are destroyed.
int XLALHeapVisit(const LALHeap *h, LALHeapVisitFcn visit, void *visit_param)
Visit each element in the heap in the order given by the comparison function.
int XLALHeapAdd(LALHeap *h, void **x)
Add a new element to a heap; if the heap is of fixed size and full, the root element is removed.
LALHeap * XLALHeapCreate(LALHeapDtorFcn dtor, int max_size, int min_or_max_heap, LALHeapCmpFcn cmp)
Create a heap.
int XLALHeapModify(LALHeap *h, LALHeapModifyFcn modify, void *modify_param)
Visit (and possibly modify) each element in the heap in the order given by the comparison function.
int XLALHeapSize(const LALHeap *h)
Return the size of a heap.
const void * XLALHeapRoot(const LALHeap *h)
Return the root element of a heap.
int XLALHeapIsFull(const LALHeap *h)
Return >0 if a limited-size heap is full, 0 otherwise (or if heap has unlimited size),...
int XLALHeapClear(LALHeap *h)
Clear a heap.
const void ** XLALHeapElements(const LALHeap *h)
Allocate and return an array containing all elements in the heap.
void XLALHeapDestroy(LALHeap *h)
Destroy a heap and its elements.
int XLALHeapMaxSize(const LALHeap *h)
Return the maximum size of a heap.
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
#define XLAL_CHECK_MAIN(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a C main() routine.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EFAILED
Generic failure.
@ XLAL_FAILURE
Failure return value (not an error number)