Failed to sort range

2013-05-28 Thread Sergei Nosov
Hi! I'm trying to implement an array, which uses malloc to allocate memory. Also, I want to implement a random access range interface for it. That went pretty well, until I tried to sort it. Sorting function asserted "Failed to sort range of type Array!(int)." I've s

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 12:57:12 UTC, Sergei Nosov wrote: Hi! I'm trying to implement an array, which uses malloc to allocate memory. Also, I want to implement a random access range interface for it. That went pretty well, until I tried to sort it. Sorting function asserted "

Re: Failed to sort range

2013-05-28 Thread bearophile
Sergei Nosov: That went pretty well, until I tried to sort it. Sorting function asserted "Failed to sort range of type Array!(int)." If you take a look a the implementation of Phobos sort, you see there is a recently added runtime test mostly meant to catch wrongly implemented

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 13:41:19 UTC, bearophile wrote: Sergei Nosov: That went pretty well, until I tried to sort it. Sorting function asserted "Failed to sort range of type Array!(int)." If you take a look a the implementation of Phobos sort, you see there is a recently add

Re: Failed to sort range

2013-05-28 Thread Ali Çehreli
On 05/28/2013 05:57 AM, Sergei Nosov wrote: Hi! I'm trying to implement an array, which uses malloc to allocate memory. Also, I want to implement a random access range interface for it. That went pretty well, until I tried to sort it. Sorting function asserted "Failed to sort ran

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
Thx, Ali! 1) First, an observation: This Array design conflates the concepts of container and range. If there are actual elements that are being stored (as opposed to elements being generated), it is better tha a range merely provides access to those elements. popFront should consume the rang

Re: Failed to sort range

2013-05-28 Thread Ali Çehreli
On 05/28/2013 11:19 AM, Sergei Nosov wrote: > Do you mean it's a good idea > to separate storage and access (via range) to the container? Like > std.container's containers (heh) have nested Range struct? Yes, that is generally the right approach. Note that built-in arrays have a similar design

Re: Failed to sort range

2013-05-28 Thread Ali Çehreli
On 05/28/2013 11:31 AM, Ali Çehreli wrote: > @property Array!T opSlice(size_t i, size_t j) { > // ... > ret.front_ = i; > > I feel like the initialization of front_ above is not right either. > Imagine quick sort where we are slicing the right-hand side of a range > as [0..

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 18:38:01 UTC, Ali Çehreli wrote: On 05/28/2013 11:31 AM, Ali Çehreli wrote: > @property Array!T opSlice(size_t i, size_t j) { > // ... > ret.front_ = i; > > I feel like the initialization of front_ above is not right either. > Imagine quick sort

Re: Failed to sort range

2013-05-28 Thread Anthony Goins
On Tuesday, 28 May 2013 at 12:57:12 UTC, Sergei Nosov wrote: Hi! I'm trying to implement an array, which uses malloc to allocate memory. Also, I want to implement a random access range interface for it. That went pretty well, until I tried to sort it. Sorting function asserted "

Re: Failed to sort range

2013-05-28 Thread Ali Çehreli
On 05/28/2013 12:47 PM, Anthony Goins wrote: > sort!("a > This worked for me with the code at your link. I've noticed that too. The reason that works is because in that case it uses Tim Sort. Apparently, the Tim Sort algorithm does not expose the bugs that were in the code. Ali

Re: Failed to sort range

2013-05-28 Thread Sergei Nosov
On Tuesday, 28 May 2013 at 20:43:32 UTC, Ali Çehreli wrote: On 05/28/2013 12:47 PM, Anthony Goins wrote: > sort!("a > This worked for me with the code at your link. I've noticed that too. The reason that works is because in that case it uses Tim Sort. Apparently, the Tim Sort algorithm does n