1 #ifndef BMALGO_IMPL__H__INCLUDED__
2 #define BMALGO_IMPL__H__INCLUDED__
26 #pragma warning( push )
27 #pragma warning( disable : 4311 4312 4127)
309 dmd.
result += (*gfunc)(blk, arg_blk);
637 return unsigned(dmd.
result);
707 const typename BV::blocks_manager_type& bman1 = bv1.get_blocks_manager();
708 const typename BV::blocks_manager_type& bman2 = bv2.get_blocks_manager();
710 bool is_all_and =
true;
713 bm::word_t*** blk_root = bman1.top_blocks_root();
714 typename BV::size_type block_idx = 0;
720 unsigned top_block_size = bman1.top_block_size();
721 unsigned ebs2 = bman2.top_block_size();
723 if (ebs2 > top_block_size)
726 top_size = top_block_size;
728 for (i = 0; i < top_size; ++i)
730 bm::word_t** blk_blk = (blk_root && (i < top_block_size)) ? blk_root[i] : 0;
739 const bm::word_t*
const* bvbb = bman2.get_topblock(i);
749 arg_blk = bman2.get_block(i, j);
761 blk = bman1.get_block(i, j);
762 if (blk == 0 && is_all_and)
765 arg_blk = bman2.get_block(i, j);
792 const typename BV::blocks_manager_type& bman1 = bv1.get_blocks_manager();
793 const typename BV::blocks_manager_type& bman2 = bv2.get_blocks_manager();
795 if (!bman1.is_init() || !bman2.is_init())
798 bm::word_t*** blk_root = bman1.top_blocks_root();
799 bm::word_t*** blk_root_arg = bman2.top_blocks_root();
800 typename BV::size_type count = 0;
802 unsigned top_block_size =
803 bm::min_value(bman1.top_block_size(),bman2.top_block_size());
805 for (
unsigned i = 0; i < top_block_size; ++i)
809 if ((blk_blk = blk_root[i]) == 0 || (blk_blk_arg= blk_root_arg[i]) == 0)
819 (blk_blk[j] && blk_blk_arg[j]) ?
822 (blk_blk[j+1] && blk_blk_arg[j+1]) ?
825 (blk_blk[j+2] && blk_blk_arg[j+2]) ?
828 (blk_blk[j+3] && blk_blk_arg[j+3]) ?
863 const typename BV::blocks_manager_type& bman1 = bv1.get_blocks_manager();
864 const typename BV::blocks_manager_type& bman2 = bv2.get_blocks_manager();
866 bool is_all_and =
true;
869 bm::word_t*** blk_root = bman1.top_blocks_root();
870 unsigned block_idx = 0;
878 unsigned top_block_size = bman1.top_block_size();
879 unsigned ebs2 = bman2.top_block_size();
881 if (ebs2 > top_block_size)
884 top_size = top_block_size;
886 for (i = 0; i < top_size; ++i)
888 bm::word_t** blk_blk = (blk_root && (i < top_block_size)) ? blk_root[i] : 0;
898 const bm::word_t*
const* bvbb = bman2.get_topblock(i);
910 arg_blk = bman2.get_block(i, j);
920 bool all_resolved =
false;
926 all_resolved =
false;
930 }
while (it < dmit_end);
940 blk = bman1.get_block(i, j);
941 if (blk == 0 && is_all_and)
944 arg_blk = bman2.get_block(i, j);
946 if (blk == 0 && arg_blk == 0)
957 bool all_resolved =
true;
963 all_resolved =
false;
967 }
while (it < dmit_end);
982 template<
typename It,
typename SIZE_TYPE>
984 SIZE_TYPE nblock, SIZE_TYPE* max_id)
BMNOEXCEPT
986 SIZE_TYPE m = *max_id;
988 for (right = first; right != last; ++right)
990 SIZE_TYPE v = SIZE_TYPE(*right);
1015 template<
class BV,
class It>
1018 typedef typename BV::size_type size_type;
1019 typename BV::blocks_manager_type& bman = bv.get_blocks_manager();
1020 if (!bman.is_init())
1023 size_type max_id = 0;
1025 while (first < last)
1029 if (max_id >= bv.size())
1032 bv.resize(max_id + 1);
1041 bman.check_allocate_block(nblock,
1043 bv.get_new_blocks_strat(),
1048 if (block_type == 1)
1053 for (; first < right; ++first)
1058 unsigned new_block_len =
1060 if (new_block_len > threshold)
1062 bman.extend_gap_block(nblock, gap_blk);
1070 for (; first < right; ++first)
1072 size_type pos = *first;
1076 blk[nword] |= (1u << nbit);
1096 template<
class BV,
class It>
1099 typename BV::blocks_manager_type& bman = bv.get_blocks_manager();
1100 if (!bman.is_init())
1103 typename BV::size_type max_id = 0;
1105 while (first < last)
1110 if (max_id >= bv.size())
1113 bv.resize(max_id + 1);
1122 bman.check_allocate_block(nblock,
1124 bv.get_new_blocks_strat(),
1129 if (block_type == 1)
1134 for (; first < right; ++first)
1143 unsigned new_block_len =
1145 if (new_block_len > threshold)
1147 bman.extend_gap_block(nblock, gap_blk);
1155 for (; first < right; ++first)
1160 blk[nword] ^= (1u << nbit);
1183 template<
class BV,
class It>
1186 typename BV::blocks_manager_type& bman = bv.get_blocks_manager();
1187 if (!bman.is_init())
1190 typename BV::size_type max_id = 0;
1192 while (first < last)
1197 if (max_id >= bv.size())
1200 bv.resize(max_id + 1);
1209 bman.check_allocate_block(nblock,
1211 bv.get_new_blocks_strat(),
1217 if (block_type == 1)
1222 for (; first < right; ++first)
1231 unsigned new_block_len =
1233 if (new_block_len > threshold)
1235 bman.extend_gap_block(nblock, gap_blk);
1243 for (; first < right; ++first)
1268 template<
class BV,
class It>
1271 typename BV::size_type prev = 0;
1272 for ( ;first < last; ++first)
1274 typename BV::size_type
id = *first;
1276 bv.set_bit_and(
id,
true);
1279 bv.set_range(prev,
id-1,
false);
1300 template<
class BV,
class It>
1327 const typename BV::blocks_manager_type& bman = bv.get_blocks_manager();
1329 if (!bman.is_init())
1332 bm::word_t*** blk_root = bman.top_blocks_root();
1333 typename BV::blocks_manager_type::block_count_change_func func(bman);
1334 typename BV::blocks_manager_type::block_idx_type st = 0;
1337 typename BV::size_type intervals = func.count();
1340 intervals -= last_bit_set;
1358 template<
typename BV,
class It>
1361 typename BV::blocks_manager_type& bman = bv.get_blocks_manager();
1362 if (!bman.is_init())
1365 unsigned inp_word_size =
sizeof(*first);
1366 size_t array_size = size_t(last - first);
1367 size_t bit_cnt = array_size * inp_word_size * 8;
1372 if (bit_cnt >= bv.size())
1375 bv.set_range((
typename BV::size_type)bit_cnt, bv.size() - 1,
false);
1376 switch (inp_word_size)
1380 size_t word_cnt = array_size / 4;
1384 bman.check_allocate_block(i,
1389 if (block_type == 1)
1391 blk = bman.deoptimize_block(i);
1400 tmp = b1 | (b2 << 8u) | (b3 << 16u) | (b4 << 24u);
1402 }
while (wrd_ptr < wrd_end);
1407 size_t to_convert = size_t(last - first);
1408 for (
size_t j = 0; j < to_convert / 4; ++j)
1412 tmp = b1 | (b2 << 8u) | (b3 << 16u) | (b4 << 24u);
1417 if (first == last)
break;
1419 if (first == last)
break;
1421 if (first == last)
break;
1423 if (first == last)
break;
1428 if (first == last)
break;
1434 size_t word_cnt = array_size / 2;
1438 bman.check_allocate_block(i,
1444 blk = bman.deoptimize_block(i);
1451 tmp = b1 | (b2 << 16);
1453 }
while (wrd_ptr < wrd_end);
1458 size_t to_convert = size_t(last - first);
1459 for (
unsigned j = 0; j < to_convert / 2; ++j)
1462 tmp = b1 | (b2 << 16u);
1467 if (first == last)
break;
1469 if (first == last)
break;
1474 if (first == last)
break;
1480 size_t word_cnt = array_size;
1484 bman.check_allocate_block(i,
1489 if (block_type == 1)
1490 blk = bman.deoptimize_block(i);
1498 }
while (wrd_ptr < wrd_end);
1505 if (first == last)
break;
1510 if (first == last)
break;
1531 template<
typename Func,
typename SIZE_TYPE>
1543 SIZE_TYPE offs = offset;
1550 bit_functor.add_bits(offs, bits, cnt);
1553 }
while (block < block_end);
1568 template<
typename Func,
typename SIZE_TYPE>
1570 unsigned left,
unsigned right,
1579 unsigned sz = right - left + 1;
1580 bit_functor.add_range(offset + left, sz);
1585 unsigned cnt, nword, nbit, bitcount, temp;
1591 if ((*word >> nbit) & 1u)
1593 bits[0] = (
unsigned char)nbit;
1594 bit_functor.add_bits(offset + (nword * 32), bits, 1);
1599 bitcount = right - left + 1u;
1602 unsigned right_margin = nbit + right - left;
1603 if (right_margin < 32)
1608 temp = (*word & mask);
1611 bit_functor.add_bits(offset + (nword * 32), bits, cnt);
1618 bit_functor.add_bits(offset + (nword * 32), bits, cnt);
1619 bitcount -= 32 - nbit;
1624 bitcount = right - left + 1u;
1629 for ( ;bitcount >= 128;
1635 bit_functor.add_bits(offset + (nword * 32), bits, cnt);
1638 for ( ;bitcount >= 32; bitcount-=32, ++word)
1643 bit_functor.add_bits(offset + (nword * 32), bits, cnt);
1654 bit_functor.add_bits(offset + (nword * 32), bits, cnt);
1671 template<
typename T,
typename Func,
typename SIZE_TYPE>
1675 const T* pcurr = buf + 1;
1676 const T* pend = buf + (*buf >> 3);
1680 bit_functor.add_range(offset, *pcurr + 1);
1683 for (++pcurr; pcurr <= pend; pcurr += 2)
1685 T prev = *(pcurr-1);
1686 bit_functor.add_range(offset + prev + 1, *pcurr - prev);
1702 template<
typename T,
typename Func,
typename SIZE_TYPE>
1705 unsigned left,
unsigned right,
1717 if (right <= *pcurr)
1719 bit_functor.add_range(offset + left, (right + 1)-left);
1722 bit_functor.add_range(offset + left, (*pcurr + 1)-left);
1726 const T*
BMRESTRICT pend = buf + (*buf >> 3);
1727 for (++pcurr; pcurr <= pend; pcurr += 2)
1729 T prev = *(pcurr-1);
1730 if (right <= *pcurr)
1732 int sz = int(right) - int(prev);
1734 bit_functor.add_range(offset + prev + 1,
unsigned(sz));
1737 bit_functor.add_range(offset + prev + 1, *pcurr - prev);
1746 template<
typename T,
typename N,
typename F>
1748 N top_size, N nb_from, N nb_to, F& f)
1751 if (nb_from > nb_to)
1758 if (i_from >= top_size)
1760 if (i_to >= top_size)
1762 i_to = unsigned(top_size-1);
1766 for (
unsigned i = i_from; i <= i_to; ++i)
1768 T** blk_blk = root[i];
1773 unsigned j = (i == i_from) ? j_from : 0;
1774 if (!j && (i != i_to))
1776 N base_idx = bm::get_super_block_start<N>(i);
1783 N base_idx = bm::get_block_start<N>(i, j);
1785 if ((i == i_to) && (j == j_to))
1792 unsigned j = (i == i_from) ? j_from : 0;
1798 N base_idx = bm::get_block_start<N>(i, j);
1799 if (0 != (block = blk_blk[j]))
1812 if ((i == i_to) && (j == j_to))
1824 template<
class BV,
class Func>
1826 typename BV::size_type left,
1827 typename BV::size_type right,
1830 typedef typename BV::size_type size_type;
1831 typedef typename BV::block_idx_type block_idx_type;
1833 const typename BV::blocks_manager_type& bman = bv.get_blocks_manager();
1834 bm::word_t*** blk_root = bman.top_blocks_root();
1843 const bm::word_t* block = bman.get_block_ptr(i0, j0);
1847 if (nblock_left == nblock_right)
1855 nbit_left, nbit_right, bit_functor);
1865 if (nbit_left && block)
1882 block_idx_type top_blocks_size = bman.top_block_size();
1884 nblock_left, nblock_right-1, bit_functor);
1889 block = bman.get_block_ptr(i0, j0);
1897 0, nbit_right, bit_functor);
1911 #pragma warning( pop )