Slicing upward

rikki cattermole rikki at cattermole.co.nz
Sun Sep 15 09:18:20 UTC 2019


On 15/09/2019 5:06 AM, Brett wrote:
> 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?

You will still need to store the length separately.

I only commented what the syntax is for that particular problem.

Paul Backus and Jonathan M Davis both deal in the part that is hard that 
you asked about.


More information about the Digitalmars-d-learn mailing list