[GIT] ppl/ppl(master): New constructor Bit_Row::Bit_Row(const Bit_Row& y, const Bit_Row& z).

Module: ppl/ppl Branch: master Commit: 03552e3fe4336c7c194c8b8decd092794e0977c8 URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=03552e3fe4336...
Author: Roberto Bagnara bagnara@cs.unipr.it Date: Mon Apr 20 14:43:58 2009 +0200
New constructor Bit_Row::Bit_Row(const Bit_Row& y, const Bit_Row& z). Constructs an object containing the set-union of y and z.
---
src/Bit_Row.cc | 26 ++++++++++++++++++++++++++ src/Bit_Row.defs.hh | 13 +++++++++++++ src/Bit_Row.inlines.hh | 14 ++++++++++++++ 3 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/Bit_Row.cc b/src/Bit_Row.cc index eee1cbf..e1d2e0f 100644 --- a/src/Bit_Row.cc +++ b/src/Bit_Row.cc @@ -376,3 +376,29 @@ PPL::Bit_Row::OK() const { && vec_alloc >= vec_size && (vec_size == 0 || mpz_getlimbn(vec, vec_size-1) != 0); } + +void +PPL::Bit_Row::union_helper(const Bit_Row& y, const Bit_Row& z) { + mp_size_t y_size = y.vec->_mp_size; + mp_size_t z_size = z.vec->_mp_size; + assert(y_size <= z.size); + assert(vec->_mp_alloc >= z.size); + vec->_mp_size = z_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; + } +} diff --git a/src/Bit_Row.defs.hh b/src/Bit_Row.defs.hh index 613046e..ce278c9 100644 --- a/src/Bit_Row.defs.hh +++ b/src/Bit_Row.defs.hh @@ -116,6 +116,12 @@ public: //! Copy-constructor. Bit_Row(const Bit_Row& y);
+ //! Set-union constructor. + /*! + Constructs an object containing the set-union of \p y and \p z. + */ + Bit_Row(const Bit_Row& y, const Bit_Row& z); + //! Destructor. ~Bit_Row();
@@ -191,6 +197,13 @@ private: //! Bit-vector representing the row. mpz_t vec;
+ //! Assigns to \p *this the union of \p y and \p z. + /*! + The size of \p y must be be less than or equal to the size of \p z. + Upon entry, \p vec must have allocated enough space to contain the result. + */ + void union_helper(const Bit_Row& x, const Bit_Row& y); + //! Assuming \p w is nonzero, returns the index of the first set bit in \p w. static unsigned int first_one(mp_limb_t w);
diff --git a/src/Bit_Row.inlines.hh b/src/Bit_Row.inlines.hh index 6fc36f7..5321f41 100644 --- a/src/Bit_Row.inlines.hh +++ b/src/Bit_Row.inlines.hh @@ -46,6 +46,20 @@ Bit_Row::Bit_Row(const Bit_Row& y) { }
inline +Bit_Row::Bit_Row(const Bit_Row& y, const Bit_Row& z) { + const mp_size_t y_size = y.vec->_mp_size; + const mp_size_t z_size = z.vec->_mp_size; + if (y_size < z_size) { + mpz_init2(vec, z_size); + union_helper(y, z); + } + else { + mpz_init2(vec, y_size); + union_helper(z, y); + } +} + +inline Bit_Row::~Bit_Row() { mpz_clear(vec); }
participants (1)
-
Roberto Bagnara