What's the deal with SortedRange

9il ilyayaroshenko at gmail.com
Mon Apr 20 02:33:32 UTC 2020


On Sunday, 19 April 2020 at 21:06:41 UTC, Steven Schveighoffer 
wrote:
> On 4/19/20 3:54 PM, Steven Schveighoffer wrote:
>
>> i.e. instead of if(auto ptr = elem in sortedRange) { /* use 
>> ptr */ }
>> you have to do:
>> 
>> auto eqr = sortedRange.equalRange(elem);
>> if(!eqr.empty) { /* use eqr.front */ }
>
> Another bug I just found. The above doesn't even work for my 
> case.
>
> https://issues.dlang.org/show_bug.cgi?id=20751
>
> -Steve

The following API is used for Mir [1]
  - transitionIndex
  - assumeSortedEqualIndex
  - assumeSortedContains

The sorted range type looks to me like overengineering.

Mir's Series [2] allows getting pointers,  but it is a sorted 
dictionary composed of two arrays (keys and values). The "in" 
operator is always @system because it can return null pointer. 
The safe alternative is `tryGet`.

[1] http://mir-algorithm.libmir.org/mir_ndslice_sorting.html
[2] http://mir-algorithm.libmir.org/mir_series.html


More information about the Digitalmars-d mailing list