Do sorted ranges have any special properties?

Philippe Sigaud philippe.sigaud at gmail.com
Tue Jul 27 05:56:01 PDT 2010


On Tue, Jul 27, 2010 at 07:13, Andrei Alexandrescu <
SeeWebsiteForEmail at erdani.org> wrote:

> Tomek Sowiński wrote:
>
>> Andrei Alexandrescu wrote:
>>
>>  median -> r[r.length / 2]
>>>
>>
>> Generalize to quantile.
>> http://en.wikipedia.org/wiki/Quantile
>>
>
> Makes sense.
>
> Andrei
>


Ah, not as methods, but free functions taking sorted ranges:


*  fast merge (on n ranges in one go),
* fast intersection, union, difference, symmetricDifference. But I see these
already exist in std.algo for sets.
* Also, maybe, some kind of takeUpTo(range, Max), that takes all values up
to a certain value Max. As it's ordered, we know there is no more value less
than Max. I don't if there is a mathematical name for that.

It's just a specialized takeWhile!((ElementType!R v) { return
v<Max;})(range);

btw, takeWhile is a _very_ useful function to add to std.algorithm.



Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100727/6dab0c8c/attachment.html>


More information about the Digitalmars-d mailing list