diff -dur d:/1/dynamic_bitset.hpp d:/2/dynamic_bitset.hpp
old
|
new
|
|
295 | 295 | // lookup |
296 | 296 | size_type find_first() const; |
297 | 297 | size_type find_next(size_type pos) const; |
| 298 | size_type find_last() const; |
| 299 | size_type find_prev(size_type pos) const; |
298 | 300 | |
299 | 301 | |
300 | 302 | #if !defined BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS |
… |
… |
|
336 | 338 | bool m_check_invariants() const; |
337 | 339 | |
338 | 340 | size_type m_do_find_from(size_type first_block) const; |
| 341 | size_type m_do_find_downto(size_type last_block) const; |
339 | 342 | |
340 | 343 | block_width_type count_extra_bits() const { return bit_index(size()); } |
341 | 344 | static size_type block_index(size_type pos) { return pos / bits_per_block; } |
… |
… |
|
1234 | 1237 | |
1235 | 1238 | } |
1236 | 1239 | |
| 1240 | // look for the nearest bit "on", starting |
| 1241 | // from the block with index last_block downto first block |
| 1242 | // |
| 1243 | template <typename Block, typename Allocator> |
| 1244 | typename dynamic_bitset<Block, Allocator>::size_type |
| 1245 | dynamic_bitset<Block, Allocator>::m_do_find_downto(size_type last_block) const |
| 1246 | { |
| 1247 | size_type i = last_block; |
| 1248 | |
| 1249 | // skip null blocks |
| 1250 | while (i >= 0 && i != npos && m_bits[i] == 0) |
| 1251 | --i; |
| 1252 | |
| 1253 | if (i < 0 || i == npos) |
| 1254 | return npos; // not found |
| 1255 | |
| 1256 | return i * bits_per_block + boost::integer_log2(m_bits[i]); |
| 1257 | |
| 1258 | } |
| 1259 | |
1237 | 1260 | |
1238 | 1261 | template <typename Block, typename Allocator> |
1239 | 1262 | typename dynamic_bitset<Block, Allocator>::size_type |
… |
… |
|
1267 | 1290 | |
1268 | 1291 | } |
1269 | 1292 | |
| 1293 | template <typename Block, typename Allocator> |
| 1294 | typename dynamic_bitset<Block, Allocator>::size_type |
| 1295 | dynamic_bitset<Block, Allocator>::find_last() const |
| 1296 | { |
| 1297 | return m_do_find_downto(num_blocks()-1); |
| 1298 | } |
| 1299 | |
| 1300 | template <typename Block, typename Allocator> |
| 1301 | typename dynamic_bitset<Block, Allocator>::size_type |
| 1302 | dynamic_bitset<Block, Allocator>::find_prev(size_type pos) const |
| 1303 | { |
| 1304 | |
| 1305 | const size_type sz = size(); |
| 1306 | if (pos <= 0 || pos == npos || pos >= sz || sz == 0) |
| 1307 | return npos; |
| 1308 | |
| 1309 | --pos; |
| 1310 | |
| 1311 | const size_type blk = block_index(pos); |
| 1312 | const block_width_type ind = bit_index(pos); |
| 1313 | const size_type mask = ind == 0 ? 1 : (1 << ind) | ((1 << ind)-1); |
| 1314 | // mask out bits after pos |
| 1315 | const Block fore = m_bits[blk] & mask; |
| 1316 | |
| 1317 | return fore? |
| 1318 | blk * bits_per_block + boost::integer_log2(fore) |
| 1319 | : |
| 1320 | m_do_find_downto(blk - 1); |
| 1321 | |
| 1322 | } |
1270 | 1323 | |
1271 | 1324 | |
1272 | 1325 | //----------------------------------------------------------------------------- |