Re: fast way to insert element at index 0

2015-06-23 Thread Baz via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 11:22:31 UTC, Steven Schveighoffer wrote: On 6/23/15 1:51 AM, jkpl wrote: On Tuesday, 23 June 2015 at 05:16:23 UTC, Assembly wrote: [...] * Option 1/ if most of the time you have to insert at the beginning, then start reading from the end and append to the end,

Re: fast way to insert element at index 0

2015-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/15 8:12 AM, Baz wrote: On Tuesday, 23 June 2015 at 11:22:31 UTC, Steven Schveighoffer wrote: On 6/23/15 1:51 AM, jkpl wrote: On Tuesday, 23 June 2015 at 05:16:23 UTC, Assembly wrote: [...] * Option 1/ if most of the time you have to insert at the beginning, then start reading from

Re: fast way to insert element at index 0

2015-06-23 Thread Baz via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 13:29:41 UTC, Steven Schveighoffer wrote: On 6/23/15 8:12 AM, Baz wrote: On Tuesday, 23 June 2015 at 11:22:31 UTC, Steven Schveighoffer wrote: [...] according to the C library, memmove handle overlapps, you mismatch with memcpy which does not. The above is

Re: fast way to insert element at index 0

2015-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/15 10:20 AM, Baz wrote: On Tuesday, 23 June 2015 at 13:29:41 UTC, Steven Schveighoffer wrote: On 6/23/15 8:12 AM, Baz wrote: On Tuesday, 23 June 2015 at 11:22:31 UTC, Steven Schveighoffer wrote: [...] according to the C library, memmove handle overlapps, you mismatch with memcpy

Re: fast way to insert element at index 0

2015-06-23 Thread Ali Çehreli via Digitalmars-d-learn
On 06/22/2015 10:16 PM, Assembly wrote: What's a fast way to insert an element at index 0 of array? now that the code is working I want to clean this: void push(T val) { T[] t = new T[buffer.length + 1]; t[0] = val; t[1 .. $] = buffer; buffer = t;

Re: fast way to insert element at index 0

2015-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/15 1:51 AM, jkpl wrote: On Tuesday, 23 June 2015 at 05:16:23 UTC, Assembly wrote: What's a fast way to insert an element at index 0 of array? now that the code is working I want to clean this: void push(T val) { T[] t = new T[buffer.length + 1]; t[0] = val;

fast way to insert element at index 0

2015-06-22 Thread Assembly via Digitalmars-d-learn
What's a fast way to insert an element at index 0 of array? now that the code is working I want to clean this: void push(T val) { T[] t = new T[buffer.length + 1]; t[0] = val; t[1 .. $] = buffer; buffer = t; } I

Re: fast way to insert element at index 0

2015-06-22 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 05:16:23 UTC, Assembly wrote: What's a fast way to insert an element at index 0 of array? now that the code is working I want to clean this: void push(T val) { T[] t = new T[buffer.length + 1]; t[0] = val; t[1

Re: fast way to insert element at index 0

2015-06-22 Thread jkpl via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 05:16:23 UTC, Assembly wrote: What's a fast way to insert an element at index 0 of array? now that the code is working I want to clean this: void push(T val) { T[] t = new T[buffer.length + 1]; t[0] = val; t[1