Boost logo

Boost Users :

From: Bo Peng (ben.bob_at_[hidden])
Date: 2006-06-04 01:37:28


> succ.clear();
> size_t numblock = m_N/BitSet::bits_per_block;
> vector<BitSet::block_type> first_blocks(numblock);
> for(size_t i=0; i<numblock; ++i)
> first_blocks[i] = rng().randInt(~BitSet::block_type(0));
> succ.append(first_blocks.begin(), first_blocks.end());
> // last block
> BitSet::block_type last_block = rng().randInt(~BitSet::block_type(0));
> for(size_t i=0; i < m_N - numblock*BitSet::bits_per_block; ++i)
> {
> if((last_block >> i) & 0x1)
> succ.set(numblock*BitSet::bits_per_block+i);
> }

When I think again about this, the special treatment of the last block
is unnecessary, and because succ is already allocated, the following
code is clearer:

vector<BitSet::block_type> blocks(succ.num_blocks());
for(size_t i=0; i<blocks.size(); ++i)
    blocks[i] = rng().randInt(~BitSet::block_type(0));
from_block_range(blocks.begin(), blocks.end(), succ);

I guess more efficiency can only be achieved through block_begin() and
block_end() functions so that I can write to the blocks directly. Is
this possible?

Bo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net