in reply to Re: Sorting issues
in thread Sorting issues

I find this data structure more intuitive

Just be aware that you'll be using 3-4 times the memory for this data structure. For a relatively small number of points its fine, but you can squeeze more points into memory if you just use plain arrays like the OP has.

BTW, your sort does not work. You can't do sequential sorts and expect it to still be sorted by the previous order (although it sometimes might appear to work, it doesn't always).

Replies are listed 'Best First'.
Re: Re: Re: Sorting issues
by Skylark (Beadle) on Jan 09, 2004 at 18:41 UTC
    > Just be aware that you'll be using 3-4 times the memory for this data structure.

    Thanks for pointing that out, I didn't know.
    update: Now that I think of it, I find it unfortunate that better design would carry such a high cost... But I know, that's Perl: equivalent speed at the cost of higher resource usage.

    > You can't do sequential sorts and expect it to still be sorted by the previous order

    Hmmm, didn't think about that. For my personal knowledge, then, how would you sort by one criteria and then by another? Something similar to the above?
    sort { $a->{z} <=> $b->{z} || $a->{x} <=> $b->{x} } @points;
    ???

      Yes, that sort will work. In the original example, the second sort simply undid the results of your first sort.

      In your new sort, the part after '||' will only happen if $a->{z} == $b->{z}, so it works like you want it to.

        Ah, thanks jmanning2k. Still learning even as I try to answer questions!