in reply to Re: Sorting multi-dimensional arrays
in thread Sorting multi-dimensional arrays

Unless he's going to sort a VERY large AoAs, cmp should be plenty fast enough. He probably does not need to go to through setting up an ST or GRT.

And judging from his example, it looks like his keys are fixed width, so he doesn't have to worry about "CG100" vs "CG1000", for instance.
--
Mike

  • Comment on Re: Re: Sorting multi-dimensional arrays

Replies are listed 'Best First'.
Re^3: Sorting multi-dimensional arrays
by Aristotle (Chancellor) on Sep 11, 2002 at 18:24 UTC
    Even fixed length strings are not really a guarantee; cmp will do the wrong thing for CC100A vs CC1000 too. It's always better to be safe than sorry. Note my code sample did not use a Schwartzian Transform because if the data set is as small as what he showed, it isn't worth the CPU time to set it up; I merely wanted him to be aware of it, should he need such.

    Makeshifts last the longest.

      Good point about making him aware of the ST option.

      However, why are you so sure that lexicographic sorting would be wrong? It's quite possible that CC100A _does_ go after CC1000, in his system... (Well, ok, CCI10A vs CCI100, to follow his format more closely).

      The sort order is under-specified, but it appears from his one example that cmp would be satisfactory... I admit that a 4 item example is a bit slim :)
      --
      Mike

        It's quite possible that CC100A _does_ go after CC1000, in his system...
        That would be what I call an accidental feature.. :-) Better to be safe than sorry, remember? The substr solution will work regardless of circumstances and won't surprisingly blow up if he moves the script to a system with different alphanumeric order. I am in no way dismissing cmp off hand as it is indeed a candidate if you are absolutely certain about your data format. But that's just what I find to be a dangerous assumption. I mean, who needs four digit years, right? :-) See also my signature..

        Makeshifts last the longest.