Failed to sort range
    Sergei Nosov 
    sergei.nosov at gmail.com
       
    Tue May 28 11:19:00 PDT 2013
    
    
  
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 range, not the container. 
> (Unless it is some special type of range with the 
> responsibility of removing elements from the container.)
I'm not sure I understand this correctly. 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?
> 2) As a minor comment, "back" usually means the last element 
> but your back_ has the meaning of one-past-the-last element.
Yeah, that's probably a not-so-good name.
> 3) You have to rethink the indexing as well. opIndex indexes 
> directly on vec_:
>
>     ref T opIndex(size_t idx) {
>         return vec_[idx];
>     }
>
> However, we may be on a slice which has already been sliced 
> before (as is the case in quick sort, which 
> SwapStrategy.unstable uses). So, I think opIndex should add 
> front_ to idx:
>
>     ref T opIndex(size_t idx) {
>         return vec_[front_ + idx];
>     }
>
> It is a start but still not the solution. Sorry... :/
That's obviously a bug, thanks. But, yeah, not the last one =) I 
updated the gist. And also, replaced the malloc call with new. 
The behavior is the same.
    
    
More information about the Digitalmars-d-learn
mailing list