ch-ch-changes

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Jan 28 12:20:02 PST 2009


dsimcha wrote:
> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>> I've worked valiantly on defining the range infrastructure and making
>> std.algorithm work with it. I have to say that I'm even more pleased
>> with the result than I'd ever expected when I started. Ranges and
>> concepts really make for beautiful code, and I am sure pretty darn
>> efficient too.
>> There's a lot to sink one's teeth in, but unfortunately the code hinges
>> on a compiler fix that Walter was kind enough to send me privately. I
>> did document the work, but the documentation doesn't really make justice
>> to the extraordinary possibilities that lay ahead of us. Anyhow, here's
>> a sneak preview into the up-and-coming ranges and their algorithms.
>> http://ssli.ee.washington.edu/~aalexand/d/web/phobos/std_range.html
>> http://ssli.ee.washington.edu/~aalexand/d/web/phobos/std_algorithm.html
>> Ranges are easy to define and compose efficiently. It was, however, a
>> pig to get a zip(r1, r2, ...) working that can mutate back the ranges it
>> iterates on. With that, it's very easy to e.g. sort multiple arrays in
>> parallel. Similarly, chain(r1, r2, ...) is able to offer e.g. random
>> iteration if all components offer it, which means that you can do crazy
>> things like sorting data that sits partially in one array and partially
>> in another.
>> Singly-linked list ranges are in, and to my soothing I found an answer
>> to the container/range dichotomy in the form of a topology policy. A
>> range may or may not be able to modify the topology of the data it's
>> iterating over; if it can, it's a free-standing range, much like
>> built-in arrays are. If it can't, it's a limited range tied to a
>> container (of which I defined none so far, but give me time) and it's
>> only the container that can mess with the topology in controlled ways.
>> More on that later.
>> Feedback welcome.
>> Andrei
> 
> Andrei,
> 
> Here's a good one for std.range that I thought of and implemented this morning
> while waiting for some code to run.  It's a random access range struct that takes
> another random access range and creates a strided version of it.  It also has the
> ability to make a random access range of structs look like a random access range
> of one element of the struct.
> 
> http://dsource.org/projects/scrapple/browser/trunk/stride/stride.d
> 
> For example:
> 
> uint[] foo = [0U, 1, 2, 3, 4, 5];
> // Make a range of every even-indexed element of foo:
> auto fooEven = Strided!(uint[])(foo, 2);
> assert(foo[0] == 0);
> assert(foo[1] == 2);
> assert(foo[2] == 4);

I was working on stride just this minute. Guess I should check this 
group more often :o).

A stride is a great way to get a good pivot into a large array when 
sorting. You sort the stride and then get its median.


Andrei



More information about the Digitalmars-d mailing list