swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

QSort in src/simtools


From: Rick Riolo
Subject: QSort in src/simtools
Date: Mon, 18 Aug 1997 14:41:54 -0400 (EDT)

How does one use the QSort object/methods that is in src/simtools?

I tried to use it on a List of Heatbugs, as follows:

  [QSort sortObjectsIn: bugList];

I get this error:

fatal: (instance)  does not recognize compare:
IOT trap (core dumped)


My Heatbugs have an unsigned instance variable ID, and a method
getID and then a method compare:

-(int) compare: (id) other {
        unsigned otherV = [other getID];
        if ( ID < otherV )
                return -1;
        else if ( ID > otherV )
                return 1;
        return 0;
}

This looks like what the src/simtools/QSort.m wants in:

int cmpObjs(id a,id b){
  return [a compare: b] ;
}

which QSort uses to pass on to the standard c qsort:

+(void) sortObjectsIn: aCollection {

  [self _flatten_: aCollection] ;

  if(size){
    qsort(flat,size,sizeof(id),
          (int (*)(const void *, const void *)) cmpObjs) ;
    [self _unFlatten_: aCollection] ;
  }
}

After the _flatten_, the array of id's flat seems to
have the heatbugs in it that I expect (ie I can getID for each
entry in that array "flat".)

Has anyone used QSort?
Is it used in the swarm kernel/apps anywhere?
Or more to the point, what am I doing wrong!?

thanks!
 - r

Rick Riolo                       address@hidden
Program for Study of Complex Systems (PSCS)
4068 Randall Lab     University of Michigan
Ann Arbor MI 48109-1120
http://pscs.physics.lsa.umich.edu/PEOPLE/rlr-home.html


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]