Initial import into git.
[galago.git] / cpp / galago / include / Bits.hpp
blobe8071e30022de871cde30db2bf2e4192e649fc03
2 //
3 // Bits
4 //
5 // 13 March 2007 -- tds
6 //
8 #ifndef GALAGO_BITS_HPP
9 #define GALAGO_BITS_HPP
12 // bits_nextUnsetBit
15 inline int bits_nextUnsetBit( UINT64 bitfield, int start, int end ) {
16 for( int i=start; i<end; i++ ) {
17 if( bitfield & (1<<i) )
18 continue;
20 return i;
23 return end;
27 // bits_nextUnsetBit
30 inline int bits_nextUnsetBit( UINT64 bitfield, int start ) {
31 return bits_nextUnsetBit( bitfield, start, 64 );
35 // bits_nextSetBit
38 inline int bits_nextSetBit( UINT64 bitfield, int start, int end ) {
39 for( int i=start; i<end; i++ ) {
40 if( !(bitfield & (1<<i)) )
41 continue;
43 return i;
46 return end;
50 // bits_nextSetBit
53 inline int bits_nextSetBit( UINT64 bitfield, int start ) {
54 return bits_nextSetBit( bitfield, start, 64 );
58 // bits
64 #endif // GALAGO_BITS_HPP