Typedef for comparison function (sorting)
#include "dip_sort.h"
dip_Boolean (*dip_SortCompareFunction) ( data1, index1, data2, index2 )
A function of this type must be supplied to the sorting algorithms for data of arbitrary type. It should return DIP_TRUE if data1[index1] > data2[index2].
Example:
dip_Boolean MyComplexCompare( void *data1, dip_int index1, void *data2, dip_int index2 )
{
dip_complex *cmplx1, *cmplx2;
dip_float magnitude1, magnitude2;
cmplx1 = data1;
cmplx2 = data2;
cmplx1 += index1;
cmplx2 += index2;
magnitude1 = sqrt( cmplx1->re * cmplx1->re + cmplx1->im * cmplx1->im );
magnitude2 = sqrt( cmplx2->re * cmplx2->re + cmplx2->im * cmplx2->im );
if ( magnitude1 > magnitude2 )
{
return( DIP_TRUE );
}
else
{
return( DIP_FALSE );
}
}
| Data type | Name | Description |
| void * | data1 | Pointer to first data array |
| dip_int | index1 | Index to element in first data array |
| void * | data2 | Pointer to second data array |
| dip_int | index2 | Index to element in second data array |