BRL-CAD
#include "common.h"
#include <stdlib.h>
#include "bu/sort.h"
Include dependency graph for sort.c:

Go to the source code of this file.

Macros

#define MIN(a, b)   (a) < (b) ? a : b
 
#define SWAPCODE(TYPE, parmi, parmj, n)
 
#define SWAPINIT(a, es)
 
#define SWAP(a, b)
 
#define VECSWAP(a, b, n)   if ((n) > 0) swapfunc(a, b, n, swaptype)
 
#define CMP(t, x, y)   (compare((t), (x), (y)))
 

Functions

void bu_sort (void *array, size_t nummemb, size_t sizememb, int(*compare)(const void *, const void *, void *), void *context)
 

Detailed Description

platform-independent re-entrant version of qsort, where the first argument is the array to sort, the second the number of elements inside the array, the third the size of one element, the fourth the comparison-function and the fifth a variable which is handed as a third argument to the comparison-function.

Definition in file sort.c.

Macro Definition Documentation

#define MIN (   a,
 
)    (a) < (b) ? a : b

Definition at line 56 of file sort.c.

Referenced by bu_sort().

#define SWAPCODE (   TYPE,
  parmi,
  parmj,
 
)
Value:
{ \
long i = (n) / sizeof (TYPE); \
TYPE *pi = (TYPE *) (parmi); \
TYPE *pj = (TYPE *) (parmj); \
do { \
TYPE t = *pi; \
*pi++ = *pj; \
*pj++ = t; \
} while (--i > 0); \
}

Definition at line 61 of file sort.c.

#define SWAPINIT (   a,
  es 
)
Value:
swaptype = ((char *)a - (char *)0) % sizeof(long) || \
es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;

Definition at line 73 of file sort.c.

Referenced by bu_sort().

#define SWAP (   a,
 
)
Value:
if (swaptype == 0) { \
long t = *(long *)(a); \
*(long *)(a) = *(long *)(b); \
*(long *)(b) = t; \
} else \
swapfunc(a, b, sizememb, swaptype)

Definition at line 87 of file sort.c.

Referenced by bu_sort().

#define VECSWAP (   a,
  b,
 
)    if ((n) > 0) swapfunc(a, b, n, swaptype)

Definition at line 95 of file sort.c.

Referenced by bu_sort().

#define CMP (   t,
  x,
 
)    (compare((t), (x), (y)))

Definition at line 97 of file sort.c.

Referenced by bu_sort().