[KLUG Programming] sorting, uniq'ing, and grepping
Tony Gettig
programming@kalamazoolinux.org
Tue, 15 Jul 2003 08:29:08 -0400
Quoting Erik Gillespie <rattles@yakko.cs.wmich.edu>:
> > Not quite that simple. He still has to write the comparison code, which
> > is in essense a qsort callback.
>
> True, the callback can be tricky but in Tony's case he said he's using
> fixed-width ASCII files with the first 7 characters being the important
> piece for identifying unique users. Toss strncmp() in a wrapper function
> to avoid getting a warning from your compiler and you're good to go:
>
> int mycompare(const void* a, const void* b) {
> strncmp((char*)a, (char*)b, 7);
> }
Thanks, Erik! I appreciate this! One of the things I hope to learn through
this experience is how to think like a programmer and write zippy little
functions like this.
>
> > 0(n log n) performance is what you'll get if you're good. I was not
> > too worried about doing better, and it is possible to do a LOT worse! :)
>
> It is possible to do worse but if he sorts before searching for uniques
> and stays away from insertion sort :P he should be fine.
>
Thank you for the heads up!
--
Tony Gettig
Voiceovers, PGP key, and more at
http://gettig.net