in reply to fast bit twiddling
USE: stest( $bit_string, @indexes ) Should be ridiculously fast, because it takes every opportunity to jump out of the main loop as soon as the relevant data is available, and often before it is stored. There is no recursion, and extremely tiny memory footprint. The only potential bottleneck is that it requires the bit list to be sorted.sub stest { my $str = shift; my $last_index=1; my @sorted_indexes = sort { $a <=> $b } @_; die "bad index" if( $sorted_indexes[0] < 1 ); my $offset; do { $last_index += ( ( $offset = ( (shift @sorted_indexes || return true) - $last_index ) || next ) ); substr($str, 0, $offset, ""); } while( $str=~/^01|^10/ ); return false; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: fast bit twiddling
by BrowserUk (Patriarch) on May 03, 2004 at 13:55 UTC | |
by esialb (Initiate) on May 03, 2004 at 15:15 UTC |