Slicing upward

Brett Brett at gmail.com
Sat Sep 14 11:34:35 UTC 2019


I have an algorithm that is most efficiently implement by taking 
an array and slicing it upward, meaning removing the leading 
elements.

Because the algorithm is complex(deterministic but chaotic) and 
deals with multiple arrays it is difficult to efficiently use 
slicing.

Is there some easy way to take an array and slice it in a way 
that as the array grows any slices will "shift".

Essentially it is sort of reversing how normal slices are 
represented

[2,4,1,64]
slice last 2, [1,64]

append 3 to either one and both become

[2,4,1,64,3]
[1,64,3]


In my case I will never have any slices in the middle.

The easiest way, at the cost of size_t is to have an indexer that 
tells one how much to offset in to a standard array, basically 
skip the head.

In the first it is 0 and the second it is 2.

Since I already have the array though it is wasting space so I'm 
wondering if there is an easier way.


Reversing the direction of the arrays does notwork because this 
then require massive copying of the array to prepend values.

One can make an array type emulating this behavior but I'd rather 
have a simpler solution that is inline with slices, Else I'll 
just use the indexer method for simplicity.





More information about the Digitalmars-d-learn mailing list