Commit ef648758 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

kdtree: inline qcmp().

parent b6268893
......@@ -48,6 +48,20 @@ typedef struct kd_point {
unsigned index;
} kd_point;
static inline
int qcmp(const void *p1, const void *p2, int axis)
{
struct kd_point *a = (struct kd_point *) p1;
struct kd_point *b = (struct kd_point *) p2;
int ret = (a->point[axis] > b->point[axis]) ? 1 : (a->point[axis] < b->point[axis]) ? -1 : 0;
if ( ret == 0 ) ret = (a->index > b->index) ? 1 : (a->index < b->index) ? -1 : 0;
return ret;
}
/*!
* \struct kdNode
* \brief kd-tree node structure definition
......
......@@ -91,18 +91,6 @@ kd_printTree(struct kdNode *node)
******************************************************************** */
static int
_compPoints(const void *p1, const void *p2, int axis)
{
struct kd_point *a = (struct kd_point *) p1;
struct kd_point *b = (struct kd_point *) p2;
int ret = (a->point[axis] > b->point[axis]) ? 1 : (a->point[axis] < b->point[axis]) ? -1 : 0;
if ( ret == 0 ) ret = (a->index > b->index) ? 1 : (a->index < b->index) ? -1 : 0;
return ret;
}
static int
_compPoints0(const void *p1, const void *p2)
{
......@@ -200,14 +188,14 @@ kd_doBuildTree(void *threadarg)
* If this iteration is allowed to start more threads, we first
* use them to parallelize the sorting
*/
#if defined(KDTEST)
pmergesort(points, nPoints, sizeof(struct kd_point), sortaxis, max_threads);
#else
int (*qcomp) (const void *, const void *);
if ( sortaxis == 0 ) qcomp = _compPoints0;
else if ( sortaxis == 1 ) qcomp = _compPoints1;
else qcomp = _compPoints2;
#if defined(KDTEST)
pmergesort(points, nPoints, sizeof(struct kd_point), sortaxis, max_threads);
#else
pmergesort(points, nPoints, sizeof(struct kd_point), qcomp, max_threads);
#endif
......
......@@ -5,18 +5,6 @@
#include "kdtree.h"
static int
_compPoints(const void *p1, const void *p2, int axis)
{
struct kd_point *a = (struct kd_point *) p1;
struct kd_point *b = (struct kd_point *) p2;
int ret = (a->point[axis] > b->point[axis]) ? 1 : (a->point[axis] < b->point[axis]) ? -1 : 0;
if ( ret == 0 ) ret = (a->index > b->index) ? 1 : (a->index < b->index) ? -1 : 0;
return ret;
}
typedef struct param_t {
char *a;
......@@ -197,9 +185,9 @@ mergesort_t(void *args)
*/
else if (
#if defined(KDTEST)
_compPoints(mya->a + li * mya->size,
mya->a + ri * mya->size,
mya->axis)
qcmp(mya->a + li * mya->size,
mya->a + ri * mya->size,
mya->axis)
#else
mya->cmp(mya->a + li * mya->size,
mya->a + ri * mya->size)
......
......@@ -5,18 +5,6 @@
#include "kdtree.h"
static int
qcmp(const void *p1, const void *p2, int axis)
{
struct kd_point *a = (struct kd_point *) p1;
struct kd_point *b = (struct kd_point *) p2;
int ret = (a->point[axis] > b->point[axis]) ? 1 : (a->point[axis] < b->point[axis]) ? -1 : 0;
if ( ret == 0 ) ret = (a->index > b->index) ? 1 : (a->index < b->index) ? -1 : 0;
return ret;
}
/*-
* Copyright (c) 1980, 1983 The Regents of the University of California.
* All rights reserved.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment