passing predicates to lowerBound, or alternatively, how lazy is map?

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 11 06:25:02 PDT 2014


On Wednesday, 11 June 2014 at 13:20:37 UTC, Andrew Brown wrote:
>>
>> You are correct. assumeSorted and lowerBound will provide 
>> better time complexity than countUntil
>
> I'm sorry, one final question because I think I'm close to 
> understanding. Map produces a forward range (lazily) but not a 
> random access range? Therefore, lowerBound will move along this 
> range until the pred is not true? This means it would be better 
> to do:
>
> numbers.indexed(order).assumeSorted.lowerBound
>
> than:
>
> map(a => numbers[a])(order).assumeSorted.lowerBound
>
> as the lowerBound will be faster on a random access range as 
> produced by indexed?

map preserves the random access capabilities of it's source. An 
array is random access, therefore map applied to an array is also 
random access.

There isn't any practical difference between indices.map!((i) => 
src[i])() and src.indexed(indices) that I know of.


More information about the Digitalmars-d-learn mailing list