POV-Ray : Newsgroups : povray.general : Linked Arrays : Re: Linked Arrays Server Time
29 Jul 2024 14:20:22 EDT (-0400)
  Re: Linked Arrays  
From: Le Forgeron
Date: 4 May 2011 03:26:02
Message: <4dc0ff8a$1@news.povray.org>
Le 03/05/2011 23:00, Warp a écrit :
> Leroy Whetstone <lrw### [at] joplincom> wrote:
> 
>> Warp wrote:
>>>   The standard arrays.inc already provides a Sort_Array() macro.
>>>
>>> http://wiki.povray.org/content/Documentation:Reference_Section_7#arrays.inc
>>>
> 
>> True, but it does one array! It doesn't move associated arrays with it. 
>> My idea is you have a group of arrays linked so if you sort using one of 
>> them all the others are also move around. The Sort_Array() macro could 
>> be modified to do so. You would have to rewrite it for every time the 
>> number of arrays you have changed.
> 
>   You don't need to rewrite it. You simply implement your own comparison
> and swapping macros (Sort_Compare() and Sort_Swap_Data()) to perform those
> operations.
> 
Why sorting the other arrays if you can use explicit indirection instead ?

Let's A[] be the array to be sorted, and B[], C[], D[]... the associated
data.

You can of course re-order/swap items in A, and then swap also B, C, ...

Or you can leave A as it is, and compute an ordering array XOX[] of integer.

So that accessing the first element is no more A[0], B[0],... but
A[XOX[0]], B[XOX[0]]

The best data are the data that do not move. The order is in the eye of
the user.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.