# Huffman coding comparison

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun May 30 09:00:23 PDT 2010

```On 05/30/2010 10:27 AM, Simen kjaeraas wrote:
> Philippe Sigaud <philippe.sigaud at gmail.com> wrote:
>
>> That's fun to see, the syntax is cool. I never thought of using operator
>
> I just had a look at Wikipedia's article on it, found that the syntax was
> 'hey, that's neat'. Just wish I could use curly brackets around it, but
> parentheses work:
>
> { 2·x | x ∈ N, x² > 3 }
> =>
> ( list!"2*a" | iota(1,int.max) * where!"x^^2 > 3" )
>
>
>> I did a range comprehension also, a few months ago. It's called comp in
>> http://svn.dsource.org/projects/dranges/trunk/dranges/docs/algorithm2.html
>>
>>
>> Like yours, it takes any range and is lazy, the main difference it
>> that it's
>> multirange: you can give it any number of range as input, it will
>> create the
>> combinations of elements (aka product of ranges), filter it with the
>> predicate and map the generative function on it.
> [snip]
>> auto pyth(int n)
>> {
>> return comp ! ("tuple(a,b,c)", "a*a+b*b==c*c && a<b")
>> (iota(1,n),iota(1,n), iota(1,n));
>> }
>
> This reminded me that Phobos lacks a combinatorial range, taking two or
> more (forward) ranges and giving all combinations thereof:
>
> combine([0,1],[2,3])
> =>
> (0,2), (0,3), (1,2), (1,3)
>
> Work has commenced on implementing just that.

Yah, that would be useful. If Philippe agrees to adapt his work, maybe
that would be the fastest route. And don't forget - the gates of Phobos
are open.

Andrei

```