testing bits in sequence

spir denis.spir at gmail.com
Sun Dec 26 05:47:39 PST 2010


On Sun, 26 Dec 2010 13:40:22 +0100
"Simen kjaeraas" <simen.kjaras at gmail.com> wrote:

> > 	foreach (i ; 0..BIT_SIZE) {
> > 	    mask = MASKS[i];
> > 	    bit = !!(code & mask);
> > 	    node = node.nodes[bit];
> > 	}
> > But as you see masking that way lets a value of 2^i, not 1, in the  
> > 'true' case, which needs to be converted, either with "cast(bool)bit" or  
> > "!!bit". And this seems _very_ slow: runs about 3 times slower than  
> > backward traversal.  
> 
> This seems better implemented like this:
> 
> foreach ( i; 0..BIT_SIZE ) {
>      bit = ( code >> i ) & 1;
>      node = node.nodes[bit];
> }

You have not read my post carefully enough ;-) That's ~ how I coded traversing the bit seq backwards (right-to-left, LSB -> MSB); but I was trying to find a way to traverse it forwards.
Anyway, than you for the pointer to std.intrinsic, seems helpful.

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list