Re: noop comparator for qsort

From: kevin.bagust (kevin.bagust_at_ntlworld.com)
Date: 11/14/04


Date: Sun, 14 Nov 2004 19:06:38 GMT

In article <20041114191540.0a12ca75@harpo.marx>,
   Trent Buck <NOSPAMfubarbaz@bigpond.com> wrote:
> The fourth argument is a comparator that returns `an integer less than,
> equal to, or greater than zero' depending on the ordering of its
> arguments.

> If I don't care about the order and simply want qsort() to run as
> quickly as possible, how should the comparator be defined?

How about comparing the pointers rather than the items pointed to? So
something like this:

int compare( void *x, void *y )
{
  if ( x < y ) {
    return -1;
  }
  else if ( y < x ) {
    return 1;
  }
  else {
    return 0;
  }
}

Kevin Bagust.



Relevant Pages

  • Re: how to return Comparator values
    ... positive or zero. ... Of course, you should read the Javadocs for the Comparator interface, but in ... a nutshell, the compare function returns the relative order of the ... compareTo function of Comparables (Strings, Numbers, etc all implement ...
    (comp.lang.java.help)
  • Re: String.equals()
    ... if you know that what you'll submit it to will only care ... whether it gives zero or non-zero? ... So just make a Comparator that returns 0 or 1, and put a note in the ...
    (comp.lang.java.programmer)
  • noop comparator for qsort
    ... The fourth argument is a comparator that returns `an integer less than, ... or greater than zero' depending on the ordering of its ... If I don't care about the order and simply want qsort() to run as ...
    (comp.lang.c)
  • Re: Synchronous rectifier
    ... I have said that the comparator is a zero-crossing detector. ... used to compare Vds with zero, but in fact there are some offset ... a negative several milivolts will cause oscillation under ...
    (sci.electronics.design)
  • Re: noop comparator for qsort
    ... >> The fourth argument is a comparator that returns `an integer less than, ... or greater than zero' depending on the ordering of its ... >> If I don't care about the order and simply want qsort() to run as ... > How about comparing the pointers rather than the items pointed to? ...
    (comp.lang.c)