Re: Arrays - Inserting and moving data

2012-02-14 Thread Manfred Nowak
MattCodr wrote: I have a doubt about the best way to insert and move (not replace) some data on an array. I have the vision, that a mapping from a dense range of integers to some value type and wast (i.e. Theta( n)) changes of this mapping are a severe hint for a maldesign. -manfred

Re: Arrays - Inserting and moving data

2012-02-13 Thread James Miller
On 11 February 2012 10:45, Jonathan M Davis jmdavisp...@gmx.com wrote: On Friday, February 10, 2012 13:32:56 Marco Leise wrote: I know that feeling. I had no exposure to functional programming and options like chain never come to my head. Although map is a concept that I made friends with

Re: Arrays - Inserting and moving data

2012-02-13 Thread Timon Gehr
On 02/13/2012 03:19 PM, James Miller wrote: On 11 February 2012 10:45, Jonathan M Davisjmdavisp...@gmx.com wrote: On Friday, February 10, 2012 13:32:56 Marco Leise wrote: I know that feeling. I had no exposure to functional programming and options like chain never come to my head. Although

Re: Arrays - Inserting and moving data

2012-02-13 Thread James Miller
On 14 February 2012 06:25, Timon Gehr timon.g...@gmx.ch wrote: On 02/13/2012 03:19 PM, James Miller wrote: On 11 February 2012 10:45, Jonathan M Davisjmdavisp...@gmx.com  wrote: On Friday, February 10, 2012 13:32:56 Marco Leise wrote: I know that feeling. I had no exposure to functional

Re: Arrays - Inserting and moving data

2012-02-13 Thread Ali Çehreli
On 02/13/2012 03:34 PM, James Miller wrote: Saying it is not quicksort as much as it may conceptually resemble quicksort is kinda odd, its like saying it is not a car, as much as it may conceptually resemble a car because it doesn't run on petrol or gas, but instead runs on environment

Re: Arrays - Inserting and moving data

2012-02-13 Thread James Miller
On 14 February 2012 12:45, Ali Çehreli acehr...@yahoo.com wrote: On 02/13/2012 03:34 PM, James Miller wrote: Saying it is not quicksort as much as it may conceptually resemble quicksort is kinda odd, its like saying it is not a car, as much as it may conceptually resemble a car because it

Re: Arrays - Inserting and moving data

2012-02-13 Thread Jonathan M Davis
On Tuesday, February 14, 2012 13:02:43 James Miller wrote: On 14 February 2012 12:45, Ali Çehreli acehr...@yahoo.com wrote: On 02/13/2012 03:34 PM, James Miller wrote: Saying it is not quicksort as much as it may conceptually resemble quicksort is kinda odd, its like saying it is not a car,

Re: Arrays - Inserting and moving data

2012-02-13 Thread Timon Gehr
On 02/14/2012 12:34 AM, James Miller wrote: On 14 February 2012 06:25, Timon Gehrtimon.g...@gmx.ch wrote: On 02/13/2012 03:19 PM, James Miller wrote: On 11 February 2012 10:45, Jonathan M Davisjmdavisp...@gmx.comwrote: On Friday, February 10, 2012 13:32:56 Marco Leise wrote: I know

Re: Arrays - Inserting and moving data

2012-02-10 Thread Marco Leise
Am 09.02.2012, 22:03 Uhr, schrieb MattCodr matheus_...@hotmail.com: On Thursday, 9 February 2012 at 19:49:43 UTC, Timon Gehr wrote: Note that this code does the same, but is more efficient if you don't actually need the array: Yes I know, In fact I need re-think the way I code with this new

Re: Arrays - Inserting and moving data

2012-02-10 Thread Jonathan M Davis
On Friday, February 10, 2012 13:32:56 Marco Leise wrote: I know that feeling. I had no exposure to functional programming and options like chain never come to my head. Although map is a concept that I made friends with early. It would benefit your programming in general to learn a functional

Re: Arrays - Inserting and moving data

2012-02-09 Thread Pedro Lacerda
I __believe__ that insertInPlace doesn't shift the elements, but use an appender allocating another array instead. Maybe this function do what you want. int[] arr = [0,1,2,3,4,5,6,7,8,9]; void maybe(T)(T[] arr, size_t pos, T value) { size_t i; for (i = arr.length - 1; i

Re: Arrays - Inserting and moving data

2012-02-09 Thread MattCodr
On Thursday, 9 February 2012 at 12:51:09 UTC, Pedro Lacerda wrote: I __believe__ that insertInPlace doesn't shift the elements, Yes, It appears that it really doesn't shift the array, insertInPlace just returns a new array with a new element in n position. Maybe this function do what you

Re: Arrays - Inserting and moving data

2012-02-09 Thread Ali Çehreli
On 02/09/2012 03:47 AM, MattCodr wrote: I have a doubt about the best way to insert and move (not replace) some data on an array. For example, In some cases if I want to do action above, I do a loop moving the data until the point that I want and finally I insert the new data there. In D I

Re: Arrays - Inserting and moving data

2012-02-09 Thread H. S. Teoh
On Thu, Feb 09, 2012 at 10:30:22AM -0800, Ali Çehreli wrote: [...] But if you don't actually want to modify the data, you can merely access the elements in-place by std.range.chain: import std.stdio; import std.range; void main() { int[] arr = [0,1,2,3,4,5,6,7,8,9]; immutable

Re: Arrays - Inserting and moving data

2012-02-09 Thread MattCodr
On Thursday, 9 February 2012 at 18:30:22 UTC, Ali Çehreli wrote: On 02/09/2012 03:47 AM, MattCodr wrote: I have a doubt about the best way to insert and move (not replace) some data on an array. For example, In some cases if I want to do action above, I do a loop moving the data until the

Re: Arrays - Inserting and moving data

2012-02-09 Thread Ali Çehreli
On 02/09/2012 11:03 AM, H. S. Teoh wrote: On Thu, Feb 09, 2012 at 10:30:22AM -0800, Ali Çehreli wrote: [...] But if you don't actually want to modify the data, you can merely access the elements in-place by std.range.chain: import std.stdio; import std.range; void main() { int[]

Re: Arrays - Inserting and moving data

2012-02-09 Thread MattCodr
On Thursday, 9 February 2012 at 19:49:43 UTC, Timon Gehr wrote: Note that this code does the same, but is more efficient if you don't actually need the array: Yes I know, In fact I need re-think the way I code with this new features of D, like ranges for example. Thanks, Matheus.