DIPlib Documentation - ©1995-2017 Quantitative Imaging Group, Delft University of Technology.

SortCompareFunction

Typedef for comparison function (sorting)

SYNOPSIS

#include "dip_sort.h"

dip_Boolean (*dip_SortCompareFunction) ( data1, index1, data2, index2 )

FUNCTION

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 );
   }
}

ARGUMENTS

Data typeNameDescription
void *data1Pointer to first data array
dip_intindex1Index to element in first data array
void *data2Pointer to second data array
dip_intindex2Index to element in second data array

SEE ALSO

General information about sorting

SortAnything, QuickSortAnything, SortSwapFunction