Re: stable sorting

new topic     » goto parent     » topic index » view thread      » older message » newer message

On 26 Feb 2003, at 13:09, Juergen Luethje wrote:

> 
> Hi Kat, you wrote:
> 
> > On 25 Feb 2003, at 17:02, Juergen Luethje wrote:
> 
> [...]
> 
> >> Say I have a list of records with student names and marks, already
> >> sorted by name. Then i want to sort this list by mark, so that students
> >> with the same mark remain listed in alphabetical order.
> >
> > <snip>
> >
> >> Is there a library in the archive, with which this can be achieved?
> >> I didn't find one.
> >
> > Yes, sorttok(). Several examples of sorting multiple fields at the same time
> > are in the readme.html : See:
> > http://www.pell.net/warning/ai/strtok-v2-1.html#sorttok
> 
> Great, thank you!

<curtsey> I try to get my favorite libs out the door before anyone knows they 
need them, so no one is waiting on them.

Hey Rob (again), maybe we could add keywords to the list that the archive 
search program uses? Versatile libs like strtok and win32lib and the internet 
programs like irc/http/ftp/tcp4u programs could use added keywords that 
don't currently appear in the archive webpage descriptions. This would be 
especially useful for programs that are hosted on other sites (like mine), or 
are zipped, in other languages, or can't be in the Eu webring because we 
can't get included in that either (they turned me down again last week).

> > It handles such things as a descending sort in one field, then an ascending
> > sort within that sort, and a descending in that sort, etc,, as many internal
> > sorts as you have fields in the list, mixing up-down sorts as you want.
> >
> > If you want your list not sorted, but you want the trace route thru the list
> > in the sort order you specify, see sortntok().
> 
> The functions are very useful and flexible! I downloaded 'strtok-v2-1.zip'
> and am very curious to have a closer look at the source code, if I've
> some more time. Hopefully I'll understand, how it works.

Don't get too comfy with the source, v2.2 changes some things. More 
options and such. I am trying so hard to not break backwards compatability, 
but make the functions more fault tolerant and possibly faster.
 
> > Strtok v2.2 is due out someday in March 2003.
> 
> Well.. how about making sorttok() and sortntok() (or two additional
> functions) even more generic? At the moment, one "record" must be a
> string:
> 
> sorted = sorttok({"Fred,Astaire,45,Alberta,Canada",
>                   "Lucy,Ball,56,Barre,North Dakota",
>                   "Red,Skelton,34,London,England",
>                   "Pierre,du Pont,12,Paris,France"},
>                   3, ',')
> 
> I don't always have comma (or semicolon or whatever) delimeted fields.

You know you can use any unique delimiter you want, right? As long as the 
char is not a member of the top sequences (this works only on two-deep 
sequences), you can use none, or anything.


> So wouldn't it be more generic, if one field is an atom or a sequence?
> E.g.:
> 
> sorted = sorttok({{"Fred","Astaire",45,"Alberta","Canada"},
>                   {"Lucy","Ball",56,"Barre","North Dakota"},
>                   {"Red","Skelton",34,"London","England"},
>                   {"Pierre","du Pont",12,"Paris","France"}},
>                   3, ',')

I considered this early on, but i myself didn't need that option at the time, 
and there wasn't a request for it when i issued a RFC for the next strtok lib 
version. Looks reasonable to do, since, if the program assumes the 
programmer knows what they are doing, such a list would be of nested 
sequences, and not atoms. I'll take a peek at it tonite. Maybe. I still am 
doing battle with the flu. I was going to make such things part of 2.2, but i 
could do a 2.15 release.

By the way, strtok should be fine with the new Eu versions, since there are 
no includes in the strtok lib.

Kat

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu