32 #include <lal/LALStdlib.h>
33 #include <lal/AVFactories.h>
38 #define COPY(x,i,y,j,s) (memcpy((char*)(x)+(i)*(s),(char*)(y)+(j)*(s),(s)))
41 #define CMP(x,i,y,j,s,p,c) ((c)((p),(char*)(x)+(i)*(s),(char*)(y)+(j)*(s)))
45 int (*compar)(
void *,
const void *,
const void *) )
47 INT4 i, j, k, n = nobj;
50 if ( (
INT4)size <= 0 )
52 if ( ! base || ! compar )
68 COPY(temp,0,base,--n,size);
70 COPY(temp,0,base,j,size);
71 COPY(base,j,base,0,size);
73 COPY(base,0,temp,0,size);
80 if(k<j &&
CMP(base,k,base,k+1,size,params,compar) < 0)
82 if(
CMP(temp,0,base,k,size,params,compar) < 0){
83 COPY(base,i,base,k,size);
90 COPY(base,i,temp,0,size);
99 int (*compar)(
void *,
const void *,
const void *) )
101 INT4 i, j, k, n = nobj;
104 if ( (
INT4)size <= 0 )
106 if ( ! indx || ! base || ! compar )
135 if(k<j &&
CMP(base,indx[k],base,indx[k+1],size,params,compar)<0)
137 if(
CMP(base,itemp,base,indx[k],size,params,compar)<0){
153 int (*compar)(
void *,
const void *,
const void *) )
158 if ( (
INT4)size <= 0 )
160 if ( ! rank || ! base || ! compar )
163 indx =
LALMalloc( nobj *
sizeof( *rank ) );
167 if (
XLALHeapIndex( indx, base, nobj, size, params, compar ) < 0 )
#define COPY(x, i, y, j, s)
#define CMP(x, i, y, j, s, p, c)
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
int XLALHeapSort(void *base, UINT4 nobj, UINT4 size, void *params, int(*compar)(void *, const void *, const void *))
int XLALHeapRank(INT4 *rank, void *base, UINT4 nobj, UINT4 size, void *params, int(*compar)(void *, const void *, const void *))
int XLALHeapIndex(INT4 *indx, void *base, UINT4 nobj, UINT4 size, void *params, int(*compar)(void *, const void *, const void *))
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EINVAL
Invalid argument.