Slicing upward

Brett Brett at gmail.com
Sat Sep 14 17:06:05 UTC 2019


On Saturday, 14 September 2019 at 11:39:21 UTC, rikki cattermole 
wrote:
> On 14/09/2019 11:34 PM, Brett wrote:
>> 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]
>
> That part is easy.
>
> ```
> import std.stdio;
>
> void main() {
> 	int[] array = [2,4,1,64];
> 	array[$-2 .. $].writeln;
> }
> ```

I hope you are being factious.

What happens when one appends to array?







More information about the Digitalmars-d-learn mailing list