|
PPL
0.12.1
|
A row in a matrix of bits. More...
#include <Bit_Row.defs.hh>
Public Member Functions | |
| Bit_Row () | |
| Default constructor. | |
| Bit_Row (const Bit_Row &y) | |
| Copy constructor. | |
| Bit_Row (const Bit_Row &y, const Bit_Row &z) | |
| Set-union constructor. | |
| ~Bit_Row () | |
| Destructor. | |
| Bit_Row & | operator= (const Bit_Row &y) |
| Assignment operator. | |
| void | m_swap (Bit_Row &y) |
Swaps *this with y. | |
| bool | operator[] (unsigned long k) const |
Returns the truth value corresponding to the bit in position k. | |
| void | set (unsigned long k) |
Sets the bit in position k. | |
| void | set_until (unsigned long k) |
Sets bits up to position k (excluded). | |
| void | clear (unsigned long k) |
Clears the bit in position k. | |
| void | clear_from (unsigned long k) |
Clears bits from position k (included) onward. | |
| void | clear () |
| Clears all the bits of the row. | |
| void | union_assign (const Bit_Row &x, const Bit_Row &y) |
Assigns to *this the set-theoretic union of x and y. | |
| void | intersection_assign (const Bit_Row &x, const Bit_Row &y) |
Assigns to *this the set-theoretic intersection of x and y. | |
| void | difference_assign (const Bit_Row &x, const Bit_Row &y) |
Assigns to *this the set-theoretic difference of x and y. | |
| unsigned long | first () const |
| Returns the index of the first set bit or ULONG_MAX if no bit is set. | |
| unsigned long | next (unsigned long position) const |
Returns the index of the first set bit after position or ULONG_MAX if no bit after position is set. | |
| unsigned long | last () const |
| Returns the index of the last set bit or ULONG_MAX if no bit is set. | |
| unsigned long | prev (unsigned long position) const |
Returns the index of the first set bit before position or ULONG_MAX if no bits before position is set. | |
| unsigned long | count_ones () const |
| Returns the number of set bits in the row. | |
| bool | empty () const |
Returns true if no bit is set in the row. | |
| memory_size_type | total_memory_in_bytes () const |
Returns the total size in bytes of the memory occupied by *this. | |
| memory_size_type | external_memory_in_bytes () const |
Returns the size in bytes of the memory managed by *this. | |
| bool | OK () const |
| Checks if all the invariants are satisfied. | |
Private Member Functions | |
| void | union_helper (const Bit_Row &y, const Bit_Row &z) |
Assigns to *this the union of y and z. | |
Private Attributes | |
| mpz_t | vec |
| Bit-vector representing the row. | |
Friends | |
| int | compare (const Bit_Row &x, const Bit_Row &y) |
| bool | operator== (const Bit_Row &x, const Bit_Row &y) |
| bool | operator!= (const Bit_Row &x, const Bit_Row &y) |
| bool | subset_or_equal (const Bit_Row &x, const Bit_Row &y) |
| bool | subset_or_equal (const Bit_Row &x, const Bit_Row &y, bool &strict_subset) |
| bool | strict_subset (const Bit_Row &x, const Bit_Row &y) |
Related Functions | |
(Note that these are not member functions.) | |
| int | compare (const Bit_Row &x, const Bit_Row &y) |
| bool | subset_or_equal (const Bit_Row &x, const Bit_Row &y) |
| bool | subset_or_equal (const Bit_Row &x, const Bit_Row &y, bool &strict_subset) |
| bool | strict_subset (const Bit_Row &x, const Bit_Row &y) |
| bool | operator== (const Bit_Row &x, const Bit_Row &y) |
| bool | operator!= (const Bit_Row &x, const Bit_Row &y) |
| void | swap (Bit_Row &x, Bit_Row &y) |
Swaps x with y. | |
| void | iter_swap (std::vector< Bit_Row >::iterator x, std::vector< Bit_Row >::iterator y) |
Swaps objects referred by x and y. | |
| bool | operator== (const Bit_Row &x, const Bit_Row &y) |
Returns true if and only if x and y are equal. | |
| bool | operator!= (const Bit_Row &x, const Bit_Row &y) |
Returns true if and only if x and y are not equal. | |
| int | compare (const Bit_Row &x, const Bit_Row &y) |
| The basic comparison function. | |
| bool | subset_or_equal (const Bit_Row &x, const Bit_Row &y) |
| Set-theoretic inclusion test. | |
| bool | subset_or_equal (const Bit_Row &x, const Bit_Row &y, bool &strict_subset) |
Set-theoretic inclusion test: sets strict_subset to a Boolean indicating whether the inclusion is strict or not. | |
| bool | strict_subset (const Bit_Row &x, const Bit_Row &y) |
| Set-theoretic strict inclusion test. | |
| void | swap (Bit_Row &x, Bit_Row &y) |
| void | iter_swap (std::vector< Bit_Row >::iterator x, std::vector< Bit_Row >::iterator y) |
A row in a matrix of bits.
Definition at line 108 of file Bit_Row.defs.hh.
|
inline |
Default constructor.
Definition at line 43 of file Bit_Row.inlines.hh.
References vec.
{
mpz_init(vec);
}
|
inline |
Copy constructor.
Definition at line 48 of file Bit_Row.inlines.hh.
References vec.
{
mpz_init_set(vec, y.vec);
}
|
inline |
Set-union constructor.
Constructs an object containing the set-union of y and z.
Definition at line 53 of file Bit_Row.inlines.hh.
References PPL_ASSERT, PPL_BITS_PER_GMP_LIMB, union_helper(), and vec.
{
const mp_size_t y_size = y.vec->_mp_size;
PPL_ASSERT(y_size >= 0);
const mp_size_t z_size = z.vec->_mp_size;
PPL_ASSERT(z_size >= 0);
if (y_size < z_size) {
PPL_ASSERT(static_cast<unsigned long>(z_size)
<= C_Integer<unsigned long>::max / PPL_BITS_PER_GMP_LIMB);
mpz_init2(vec, static_cast<unsigned long>(z_size) * PPL_BITS_PER_GMP_LIMB);
union_helper(y, z);
}
else {
PPL_ASSERT(static_cast<unsigned long>(y_size)
<= C_Integer<unsigned long>::max / PPL_BITS_PER_GMP_LIMB);
mpz_init2(vec, static_cast<unsigned long>(y_size) * PPL_BITS_PER_GMP_LIMB);
union_helper(z, y);
}
}
|
inline |
|
inline |
Clears the bit in position k.
Definition at line 89 of file Bit_Row.inlines.hh.
References vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact(), Parma_Polyhedra_Library::Polyhedron::select_H79_constraints(), and Parma_Polyhedra_Library::BD_Shape< T >::shortest_path_reduction_assign().
{
mpz_clrbit(vec, k);
}
|
inline |
Clears all the bits of the row.
Definition at line 116 of file Bit_Row.inlines.hh.
References vec.
{
mpz_set_ui(vec, 0UL);
}
|
inline |
Clears bits from position k (included) onward.
Definition at line 94 of file Bit_Row.inlines.hh.
References vec.
|
inline |
Returns the number of set bits in the row.
Definition at line 99 of file Bit_Row.inlines.hh.
References PPL_ASSERT, and vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::conversion().
{
mp_size_t x_size = vec->_mp_size;
PPL_ASSERT(x_size >= 0);
return (x_size == 0) ? 0 : mpn_popcount(vec->_mp_d, x_size);
}
|
inline |
Assigns to *this the set-theoretic difference of x and y.
Definition at line 156 of file Bit_Row.inlines.hh.
References PPL_DIRTY_TEMP, and vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact().
{
PPL_DIRTY_TEMP(mpz_class, complement_y);
mpz_com(complement_y.get_mpz_t(), y.vec);
mpz_and(vec, x.vec, complement_y.get_mpz_t());
}
|
inline |
Returns true if no bit is set in the row.
Definition at line 106 of file Bit_Row.inlines.hh.
References vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact(), and Parma_Polyhedra_Library::Polyhedron::simplify_using_context_assign().
{
return mpz_sgn(vec) == 0;
}
Returns the size in bytes of the memory managed by *this.
Definition at line 121 of file Bit_Row.inlines.hh.
References vec.
Referenced by total_memory_in_bytes().
{
return static_cast<memory_size_type>(vec[0]._mp_alloc) * PPL_SIZEOF_MP_LIMB_T;
}
| unsigned long Parma_Polyhedra_Library::Bit_Row::first | ( | ) | const |
Returns the index of the first set bit or ULONG_MAX if no bit is set.
Definition at line 32 of file Bit_Row.cc.
References Parma_Polyhedra_Library::Implementation::first_one(), PPL_ASSERT, PPL_BITS_PER_GMP_LIMB, and vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact().
{
const mp_size_t vec_size = vec->_mp_size;
PPL_ASSERT(vec_size >= 0);
mp_srcptr p = vec->_mp_d;
for (mp_size_t li = 0; li < vec_size; ++li, ++p) {
const mp_limb_t limb = *p;
if (limb != 0)
return static_cast<unsigned long>(li) * PPL_BITS_PER_GMP_LIMB
+ Implementation::first_one(limb);
}
return C_Integer<unsigned long>::max;
}
|
inline |
Assigns to *this the set-theoretic intersection of x and y.
Definition at line 151 of file Bit_Row.inlines.hh.
References vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact().
{
mpz_and(vec, x.vec, y.vec);
}
| unsigned long Parma_Polyhedra_Library::Bit_Row::last | ( | ) | const |
Returns the index of the last set bit or ULONG_MAX if no bit is set.
Definition at line 86 of file Bit_Row.cc.
References Parma_Polyhedra_Library::Implementation::last_one(), PPL_ASSERT, and PPL_BITS_PER_GMP_LIMB.
Referenced by Parma_Polyhedra_Library::Bit_Matrix::OK().
{
mp_size_t li = vec->_mp_size;
PPL_ASSERT(li >= 0);
if (li == 0)
return C_Integer<unsigned long>::max;
--li;
const mp_srcptr p = vec->_mp_d + li;
const mp_limb_t limb = *p;
PPL_ASSERT(limb != 0);
return static_cast<unsigned long>(li) * PPL_BITS_PER_GMP_LIMB
+ Implementation::last_one(limb);
}
|
inline |
Swaps *this with y.
Definition at line 111 of file Bit_Row.inlines.hh.
References vec.
Referenced by swap().
{
mpz_swap(vec, y.vec);
}
| unsigned long Parma_Polyhedra_Library::Bit_Row::next | ( | unsigned long | position | ) | const |
Returns the index of the first set bit after position or ULONG_MAX if no bit after position is set.
Definition at line 46 of file Bit_Row.cc.
References Parma_Polyhedra_Library::Implementation::first_one(), PPL_ASSERT, and PPL_BITS_PER_GMP_LIMB.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact().
{
++position;
// The alternative implementation using the mpz_scan1() function
// of GMP was measured to be slower that ours. Here it is, in
// case mpz_scan1() is improved.
//
// <CODE>
// unsigned long r = mpz_scan1(vec, position);
// return (r == C_Integer<unsigned long>::max) ? -1 : r;
// </CODE>
const unsigned long uli = position / PPL_BITS_PER_GMP_LIMB;
mp_size_t li = static_cast<mp_size_t>(uli);
const mp_size_t vec_size = vec->_mp_size;
PPL_ASSERT(vec_size >= 0);
if (li >= vec_size)
return C_Integer<unsigned long>::max;
// Get the first limb.
mp_srcptr p = vec->_mp_d + li;
// Mask off any bits before `position' in the first limb.
mp_limb_t limb
= *p & ((~static_cast<mp_limb_t>(0)) << (position % PPL_BITS_PER_GMP_LIMB));
while (true) {
if (limb != 0)
return static_cast<unsigned long>(li) * PPL_BITS_PER_GMP_LIMB
+ Implementation::first_one(limb);
++li;
if (li == vec_size)
break;
++p;
limb = *p;
}
return C_Integer<unsigned long>::max;
}
| bool Parma_Polyhedra_Library::Bit_Row::OK | ( | ) | const |
Checks if all the invariants are satisfied.
Definition at line 309 of file Bit_Row.cc.
Referenced by Parma_Polyhedra_Library::Bit_Matrix::OK().
Assignment operator.
Definition at line 78 of file Bit_Row.inlines.hh.
References vec.
{
mpz_set(vec, y.vec);
return *this;
}
| bool Parma_Polyhedra_Library::Bit_Row::operator[] | ( | unsigned long | k | ) | const |
Returns the truth value corresponding to the bit in position k.
Definition at line 142 of file Bit_Row.cc.
References PPL_ASSERT.
{
const mp_size_t vec_size = vec->_mp_size;
PPL_ASSERT(vec_size >= 0);
unsigned long i = k / static_cast<unsigned long>(GMP_NUMB_BITS);
if (i >= static_cast<unsigned long>(vec_size))
return false;
mp_limb_t limb = *(vec->_mp_d + i);
return ((limb >> (k % static_cast<unsigned long>(GMP_NUMB_BITS))) & 1U) != 0;
}
| unsigned long Parma_Polyhedra_Library::Bit_Row::prev | ( | unsigned long | position | ) | const |
Returns the index of the first set bit before position or ULONG_MAX if no bits before position is set.
Definition at line 100 of file Bit_Row.cc.
References Parma_Polyhedra_Library::Implementation::last_one(), PPL_ASSERT, and PPL_BITS_PER_GMP_LIMB.
{
if (position == 0)
return C_Integer<unsigned long>::max;
--position;
const mp_size_t vec_size = vec->_mp_size;
PPL_ASSERT(vec_size > 0);
const unsigned long uli = position / PPL_BITS_PER_GMP_LIMB;
mp_size_t li = static_cast<mp_size_t>(uli);
mp_limb_t limb;
mp_srcptr p = vec->_mp_d;
// Get the first limb.
if (li >= vec_size) {
li = vec_size - 1;
p += li;
limb = *p;
}
else {
const mp_limb_t mask
= (~static_cast<mp_limb_t>(0))
>> (PPL_BITS_PER_GMP_LIMB - 1U - position % PPL_BITS_PER_GMP_LIMB);
p += li;
limb = *p & mask;
}
while (true) {
if (limb != 0)
return static_cast<unsigned long>(li) * PPL_BITS_PER_GMP_LIMB
+ Implementation::last_one(limb);
if (li == 0)
break;
--li;
--p;
limb = *p;
}
return C_Integer<unsigned long>::max;
}
|
inline |
Sets the bit in position k.
Definition at line 84 of file Bit_Row.inlines.hh.
References vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_C_poly_hull_assign_if_exact(), Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact(), Parma_Polyhedra_Library::Polyhedron::conversion(), Parma_Polyhedra_Library::Polyhedron::select_H79_constraints(), Parma_Polyhedra_Library::BD_Shape< T >::shortest_path_reduction_assign(), Parma_Polyhedra_Library::Polyhedron::simplify_using_context_assign(), Parma_Polyhedra_Library::Polyhedron::strongly_minimize_constraints(), and Parma_Polyhedra_Library::Polyhedron::strongly_minimize_generators().
{
mpz_setbit(vec, k);
}
| void Parma_Polyhedra_Library::Bit_Row::set_until | ( | unsigned long | k | ) |
Sets bits up to position k (excluded).
Definition at line 155 of file Bit_Row.cc.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_C_poly_hull_assign_if_exact(), and Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact().
{
// FIXME, TODO: this is an inefficient implementation.
while (k-- > 0)
mpz_setbit(vec, k);
}
|
inline |
Returns the total size in bytes of the memory occupied by *this.
Definition at line 126 of file Bit_Row.inlines.hh.
References external_memory_in_bytes().
{
return sizeof(*this) + external_memory_in_bytes();
}
|
inline |
Assigns to *this the set-theoretic union of x and y.
Definition at line 131 of file Bit_Row.inlines.hh.
References PPL_ASSERT, PPL_BITS_PER_GMP_LIMB, union_helper(), and vec.
Referenced by Parma_Polyhedra_Library::Polyhedron::BHZ09_C_poly_hull_assign_if_exact(), Parma_Polyhedra_Library::Polyhedron::BHZ09_NNC_poly_hull_assign_if_exact(), and Parma_Polyhedra_Library::Polyhedron::strongly_minimize_constraints().
{
const mp_size_t x_size = x.vec->_mp_size;
PPL_ASSERT(x_size >= 0);
const mp_size_t y_size = y.vec->_mp_size;
PPL_ASSERT(y_size >= 0);
if (x_size < y_size) {
PPL_ASSERT(static_cast<unsigned long>(y_size)
<= C_Integer<unsigned long>::max / PPL_BITS_PER_GMP_LIMB);
mpz_realloc2(vec, static_cast<unsigned long>(y_size) * PPL_BITS_PER_GMP_LIMB);
union_helper(x, y);
}
else {
PPL_ASSERT(static_cast<unsigned long>(x_size)
<= C_Integer<unsigned long>::max / PPL_BITS_PER_GMP_LIMB);
mpz_realloc2(vec, static_cast<unsigned long>(x_size) * PPL_BITS_PER_GMP_LIMB);
union_helper(y, x);
}
}
|
private |
Assigns to *this the union of y and z.
The size of y must be be less than or equal to the size of z. Upon entry, vec must have allocated enough space to contain the result.
Definition at line 318 of file Bit_Row.cc.
References PPL_ASSERT, and vec.
Referenced by Bit_Row(), and union_assign().
{
mp_size_t y_size = y.vec->_mp_size;
mp_size_t z_size = z.vec->_mp_size;
PPL_ASSERT(y_size <= z_size);
PPL_ASSERT(vec->_mp_alloc >= z_size);
vec->_mp_size = z.vec->_mp_size;
mp_srcptr yp = y.vec->_mp_d;
mp_srcptr zp = z.vec->_mp_d;
mp_ptr p = vec->_mp_d;
z_size -= y_size;
while (y_size > 0) {
*p = *yp | * zp;
++yp;
++zp;
++p;
--y_size;
}
while (z_size > 0) {
*p = *zp;
++zp;
++p;
--z_size;
}
}
The basic comparison function.
Compares x with y starting from the least significant bits. The ordering is total and has the following property: if x and y are two rows seen as sets of naturals, if x is a strict subset of y, then x comes before y.
Returns
x comes before y in the ordering;x and y are equal;x comes after y in the ordering. Definition at line 163 of file Bit_Row.cc.
References PPL_ASSERT, and vec.
{
const mp_size_t x_size = x.vec->_mp_size;
PPL_ASSERT(x_size >= 0);
const mp_size_t y_size = y.vec->_mp_size;
PPL_ASSERT(y_size >= 0);
mp_size_t size = ((x_size > y_size) ? y_size : x_size);
mp_srcptr xp = x.vec->_mp_d;
mp_srcptr yp = y.vec->_mp_d;
while (size > 0) {
const mp_limb_t xl = *xp;
const mp_limb_t yl = *yp;
if (xl != yl) {
// Get the ones where they are different.
const mp_limb_t diff = xl ^ yl;
// First bit that is different.
const mp_limb_t mask = diff & ~(diff-1);
return ((xl & mask) != 0) ? 1 : -1;
}
++xp;
++yp;
--size;
}
return (x_size == y_size) ? 0 : ((x_size > y_size) ? 1 : -1);
}
Swaps objects referred by x and y.
Definition at line 229 of file Bit_Row.inlines.hh.
References Parma_Polyhedra_Library::swap().
{
swap(*x, *y);
}
Returns true if and only if x and y are not equal.
Definition at line 296 of file Bit_Row.cc.
References PPL_ASSERT, and vec.
{
const mp_size_t x_vec_size = x.vec->_mp_size;
PPL_ASSERT(x_vec_size >= 0);
const mp_size_t y_vec_size = y.vec->_mp_size;
PPL_ASSERT(y_vec_size >= 0);
if (x_vec_size != y_vec_size)
return true;
return mpn_cmp(x.vec->_mp_d, y.vec->_mp_d, x_vec_size) != 0;
}
Returns true if and only if x and y are equal.
Definition at line 282 of file Bit_Row.cc.
References PPL_ASSERT, and vec.
{
const mp_size_t x_vec_size = x.vec->_mp_size;
PPL_ASSERT(x_vec_size >= 0);
const mp_size_t y_vec_size = y.vec->_mp_size;
PPL_ASSERT(y_vec_size >= 0);
if (x_vec_size != y_vec_size)
return false;
return mpn_cmp(x.vec->_mp_d, y.vec->_mp_d, x_vec_size) == 0;
}
|
related |
Set-theoretic strict inclusion test.
|
friend |
|
related |
Definition at line 256 of file Bit_Row.cc.
References PPL_ASSERT, and vec.
{
mp_size_t x_size = x.vec->_mp_size;
PPL_ASSERT(x_size >= 0);
mp_size_t y_size = y.vec->_mp_size;
PPL_ASSERT(y_size >= 0);
if (x_size > y_size)
return false;
bool different = (x_size < y_size);
mp_srcptr xp = x.vec->_mp_d;
mp_srcptr yp = y.vec->_mp_d;
while (x_size > 0) {
const mp_limb_t xl = *xp;
const mp_limb_t yl = *yp;
if ((xl & ~yl) != 0)
return false;
if (!different && xl != yl)
different = true;
++xp;
++yp;
--x_size;
}
return different;
}
|
related |
Set-theoretic inclusion test.
|
related |
Set-theoretic inclusion test: sets strict_subset to a Boolean indicating whether the inclusion is strict or not.
|
friend |
|
friend |
|
related |
Definition at line 190 of file Bit_Row.cc.
References PPL_ASSERT, and vec.
{
mp_size_t x_size = x.vec->_mp_size;
PPL_ASSERT(x_size >= 0);
mp_size_t y_size = y.vec->_mp_size;
PPL_ASSERT(y_size >= 0);
if (x_size > y_size)
return false;
mp_srcptr xp = x.vec->_mp_d;
mp_srcptr yp = y.vec->_mp_d;
while (x_size > 0) {
if ((*xp & ~*yp) != 0)
return false;
++xp;
++yp;
--x_size;
}
return true;
}
|
related |
Definition at line 211 of file Bit_Row.cc.
References PPL_ASSERT, and vec.
{
mp_size_t x_size = x.vec->_mp_size;
PPL_ASSERT(x_size >= 0);
mp_size_t y_size = y.vec->_mp_size;
PPL_ASSERT(y_size >= 0);
if (x_size > y_size)
return false;
mp_srcptr xp = x.vec->_mp_d;
mp_srcptr yp = y.vec->_mp_d;
strict_subset = (x_size < y_size);
mp_limb_t xl;
mp_limb_t yl;
if (strict_subset) {
while (x_size > 0) {
xl = *xp;
yl = *yp;
if ((xl & ~yl) != 0)
return false;
strict_subset_next:
++xp;
++yp;
--x_size;
}
}
else {
while (x_size > 0) {
xl = *xp;
yl = *yp;
if (xl != yl) {
if ((xl & ~yl) != 0)
return false;
strict_subset = true;
goto strict_subset_next;
}
++xp;
++yp;
--x_size;
}
}
return true;
}
|
private |
Bit-vector representing the row.
Definition at line 202 of file Bit_Row.defs.hh.
Referenced by Bit_Row(), clear(), clear_from(), compare(), count_ones(), difference_assign(), empty(), external_memory_in_bytes(), first(), intersection_assign(), m_swap(), operator!=(), operator=(), operator==(), set(), strict_subset(), subset_or_equal(), union_assign(), union_helper(), and ~Bit_Row().