27 bit_reference& bit_reference::operator = (
bool x) {
28 if (x) {
if (!(*p & mask)) { *p |= mask; bv->change_for_true(ind); } }
29 else {
if (*p & mask) { *p &= ~mask; bv->change_for_false(ind); } }
33 bit_iterator::bit_iterator(bit_vector &b,
size_type i) : p(b, i / WD_BIT)
34 { ind = i; bv = &b, mask = bit_support(1) << (i & WD_MASK); }
36 bit_iterator& bit_iterator::operator+=(difference_type i){
37 ind+=i; mask = bit_support(1) << (ind & WD_MASK);
38 p=bit_container::iterator(*bv, ind/WD_BIT);
42 bit_const_iterator::bit_const_iterator(
const bit_vector &b,
size_type i)
44 { ind = i; bv = &b, mask = bit_support(1) << (i & WD_MASK); }
46 bit_const_iterator& bit_const_iterator::operator+=(difference_type i) {
47 ind += i; mask = bit_support(1) << (ind & WD_MASK);
48 p = bit_container::const_iterator(*bv, ind/WD_BIT);
53 size_type f = i1 / WD_BIT, r = i1 & (WD_BIT-1), l = i2 / WD_BIT;
54 (*((bit_container *)(
this)))[l];
57 if (f < l) std::fill(dal::bit_container::begin()+f,
58 dal::bit_container::begin()+l, 0);
62 void bit_vector::swap(bit_vector &da) {
63 ((bit_container *)(
this))->swap(da);
64 std::swap(ifirst_true, da.ifirst_true);
65 std::swap(ifirst_false, da.ifirst_false);
66 std::swap(ilast_true, da.ilast_true);
67 std::swap(ilast_false, da.ilast_false);
68 std::swap(icard, da.icard);
69 std::swap(icard_valid, da.icard_valid);
85 const_iterator itb = begin(), ite = end();
87 while (itb != ite) {
if (*itb) ++icard; ++itb; }
94 assert(ifirst_true <= ilast_true);
95 const_iterator itx = begin(), ite = end(); itx += ifirst_true;
96 while (itx != ite && !*itx ) { ++itx; ++(ifirst_true); }
97 if (is_in(ifirst_true))
return ifirst_true;
98 else { ifirst_true = ilast_true = 0;
return size_type(-1); }
102 const_iterator itx = begin(), ite = end(); itx += ifirst_false;
103 while (itx != ite && *itx) { ++itx; ++(ifirst_false); }
104 if (!is_in(ifirst_false))
return ifirst_false;
105 else { ifirst_false = ilast_false = size()-1;
return size_type(-1); }
109 const_iterator itb = begin(), itx = itb; itx += ilast_true;
110 while (itx != itb && !*itx) { --itx; --(ilast_true); }
111 if (is_in(ilast_true))
return ilast_true;
116 const_iterator itb = begin(), itx = itb; itx += ilast_false;
117 while (itx != itb && *itx) { --itx; --(ilast_false); }
121 bit_vector &bit_vector::setminus(
const bit_vector& b) {
122 for (bv_visitor i(b); !i.finished(); ++i) del(i);
126 bit_vector &bit_vector::operator |=(
const bit_vector &bv) {
127 for (bv_visitor i(bv); !i.finished(); ++i)
add(i);
131 bit_vector &bit_vector::operator &=(
const bit_vector &bv) {
132 bit_container::iterator it1b = bit_container::begin();
133 bit_container::iterator it1e = bit_container::end();
134 bit_container::const_iterator it2b = bv.bit_container::begin();
135 bit_container::const_iterator it2e = bv.bit_container::end();
137 while (it1b != it1e && it2b != it2e) { *it1b++ &= *it2b++; }
138 while (it1b != it1e) { *it1b++ = 0; }
140 ifirst_true = std::max(ifirst_true, bv.ifirst_true);
141 ilast_true = std::min(ilast_true, bv.ilast_true);
142 if (ifirst_true > ilast_true)
clear();
144 ilast_false = std::min(size()-1, std::max(ilast_false,bv.ilast_false));
145 ifirst_false = std::min(ifirst_false, bv.ifirst_false);
150 bool bit_vector::operator ==(
const bit_vector &bv)
const {
151 bit_container::const_iterator it1b = bit_container::begin();
152 bit_container::const_iterator it1e = bit_container::end();
153 bit_container::const_iterator it2b = bv.bit_container::begin();
154 bit_container::const_iterator it2e = bv.bit_container::end();
156 while (it1b!=it1e && it2b!=it2e)
if (*it1b++ != *it2b++)
return false;
157 while (it1b != it1e)
if (*it1b++ != 0)
return false;
158 while (it2b != it2e)
if (*it2b++ != 0)
return false;
164 {
add(i+nb-1); std::fill(this->begin()+i, this->begin()+(i+nb),
true); }
169 { del(i+nb-1); std::fill(this->begin()+i, this->begin()+(i+nb),
false); }
174 { del(i+nb-1); std::fill(this->begin()+i, this->begin()+(i+nb),
false); }
177 bool bit_vector::contains(
const dal::bit_vector& other)
const {
178 for (dal::bv_visitor i(other); !i.finished(); ++i)
179 if (!this->is_in(i))
return false;
183 std::ostream &operator <<(std::ostream &o,
const bit_vector &s) {
186 for (bv_visitor i(s); !i.finished(); ++i) {
187 if (!first) o <<
" ";
195 bool bv_visitor::operator++() {
200 if (v&1)
return true;
202 ind = ind_b + WD_BIT;
203 if (ind >= ilast)
return false;
205 if (v&1)
return true;
209 const_bv_iterator<bv_iterable> bv_iterable::begin()
const{
210 return const_bv_iterator<bv_iterable>(
this, v_.first_true());
212 const_bv_iterator<bv_iterable> bv_iterable::end()
const{
213 return const_bv_iterator<bv_iterable>(
this, v_.last_true() + 1);
216 const_bv_iterator<bv_iterable_c> bv_iterable_c::begin()
const{
217 return const_bv_iterator<bv_iterable_c>(
this, v_.first_true());
219 const_bv_iterator<bv_iterable_c> bv_iterable_c::end()
const{
220 return const_bv_iterator<bv_iterable_c>(
this, v_.last_true() + 1);
Provide a dynamic bit container.
size_t size_type
used as the common size type in the library
void clear(L &l)
clear (fill with zeros) a vector or matrix.
void add(const L1 &l1, L2 &l2)
*/