PPL  1.2
Parma_Polyhedra_Library::Dense_Row Class Reference

A finite sequence of coefficients. More...

#include <Dense_Row_defs.hh>

Collaboration diagram for Parma_Polyhedra_Library::Dense_Row:

Classes

class  const_iterator
 
struct  Impl
 
class  iterator
 

Public Member Functions

 Dense_Row ()
 Constructs an empty row. More...
 
 Dense_Row (const Sparse_Row &row)
 
 Dense_Row (dimension_type sz)
 Tight constructor: resizing may require reallocation. More...
 
 Dense_Row (dimension_type sz, dimension_type capacity)
 Sizing constructor with capacity. More...
 
 Dense_Row (const Dense_Row &y)
 Ordinary copy constructor. More...
 
 Dense_Row (const Dense_Row &y, dimension_type capacity)
 Copy constructor with specified capacity. More...
 
 Dense_Row (const Dense_Row &y, dimension_type sz, dimension_type capacity)
 Copy constructor with specified size and capacity. More...
 
 Dense_Row (const Sparse_Row &y, dimension_type sz, dimension_type capacity)
 Copy constructor with specified size and capacity from a Sparse_Row. More...
 
 ~Dense_Row ()
 Destructor. More...
 
Dense_Rowoperator= (const Dense_Row &y)
 Assignment operator. More...
 
Dense_Rowoperator= (const Sparse_Row &y)
 Assignment operator. More...
 
void m_swap (Dense_Row &y)
 Swaps *this with y. More...
 
void resize (dimension_type sz)
 Resizes the row to sz. More...
 
void resize (dimension_type sz, dimension_type capacity)
 Resizes the row to sz, with capacity capacity. More...
 
void clear ()
 Resets all the elements of this row. More...
 
void add_zeroes_and_shift (dimension_type n, dimension_type i)
 Adds n zeroes before index i. More...
 
void expand_within_capacity (dimension_type new_size)
 Expands the row to size new_size. More...
 
void shrink (dimension_type new_size)
 Shrinks the row by erasing elements at the end. More...
 
dimension_type size () const
 Gives the number of coefficients currently in use. More...
 
void normalize ()
 Normalizes the modulo of coefficients so that they are mutually prime. More...
 
void swap_coefficients (dimension_type i, dimension_type j)
 
void swap_coefficients (iterator i, iterator j)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
void reset (dimension_type i)
 
void reset (dimension_type first, dimension_type last)
 
iterator reset (iterator itr)
 
Coefficient_traits::const_reference get (dimension_type i) const
 
iterator find (dimension_type i)
 Provided for compatibility with Sparse_Row. More...
 
const_iterator find (dimension_type i) const
 Provided for compatibility with Sparse_Row. More...
 
iterator find (iterator itr, dimension_type i)
 Provided for compatibility with Sparse_Row. More...
 
const_iterator find (const_iterator itr, dimension_type i) const
 Provided for compatibility with Sparse_Row. More...
 
iterator lower_bound (dimension_type i)
 Provided for compatibility with Sparse_Row. More...
 
const_iterator lower_bound (dimension_type i) const
 Provided for compatibility with Sparse_Row. More...
 
iterator lower_bound (iterator itr, dimension_type i)
 Provided for compatibility with Sparse_Row. More...
 
const_iterator lower_bound (const_iterator itr, dimension_type i) const
 Provided for compatibility with Sparse_Row. More...
 
iterator insert (dimension_type i, Coefficient_traits::const_reference x)
 Provided for compatibility with Sparse_Row. More...
 
iterator insert (dimension_type i)
 Provided for compatibility with Sparse_Row. More...
 
iterator insert (iterator itr, dimension_type i, Coefficient_traits::const_reference x)
 Provided for compatibility with Sparse_Row. More...
 
iterator insert (iterator itr, dimension_type i)
 Provided for compatibility with Sparse_Row. More...
 
template<typename Func1 , typename Func2 >
void combine_needs_first (const Dense_Row &y, const Func1 &f, const Func2 &g)
 Calls g(x[i],y[i]), for each i. More...
 
template<typename Func1 , typename Func2 >
void combine_needs_second (const Dense_Row &y, const Func1 &g, const Func2 &h)
 Calls g(x[i],y[i]), for each i. More...
 
template<typename Func1 , typename Func2 , typename Func3 >
void combine (const Dense_Row &y, const Func1 &f, const Func2 &g, const Func3 &h)
 Calls g(x[i],y[i]), for each i. More...
 
void linear_combine (const Dense_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2)
 
void linear_combine (const Dense_Row &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end)
 
void ascii_dump () const
 Writes to std::cerr an ASCII representation of *this. More...
 
void ascii_dump (std::ostream &s) const
 Writes to s an ASCII representation of *this. More...
 
void print () const
 Prints *this to std::cerr using operator<<. More...
 
bool ascii_load (std::istream &s)
 Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise. More...
 
memory_size_type total_memory_in_bytes () const
 Returns a lower bound to the total size in bytes of the memory occupied by *this. More...
 
memory_size_type external_memory_in_bytes () const
 Returns a lower bound to the size in bytes of the memory managed by *this. More...
 
memory_size_type total_memory_in_bytes (dimension_type capacity) const
 Returns the total size in bytes of the memory occupied by *this, provided the capacity of *this is given by capacity. More...
 
memory_size_type external_memory_in_bytes (dimension_type capacity) const
 Returns the size in bytes of the memory managed by *this, provided the capacity of *this is given by capacity. More...
 
bool OK () const
 Checks if all the invariants are satisfied. More...
 
bool OK (dimension_type row_size) const
 Checks if all the invariants are satisfied and that the actual size matches the value provided as argument. More...
 
Subscript operators
Coefficientoperator[] (dimension_type k)
 Returns a reference to the element of the row indexed by k. More...
 
Coefficient_traits::const_reference operator[] (dimension_type k) const
 Returns a constant reference to the element of the row indexed by k. More...
 

Static Public Member Functions

static dimension_type max_size ()
 Returns the size() of the largest possible Dense_Row. More...
 

Private Member Functions

void init (const Sparse_Row &row)
 
void destroy ()
 
dimension_type capacity () const
 Returns the capacity of the row. More...
 

Private Attributes

Impl impl
 

Related Functions

(Note that these are not member functions.)

bool operator== (const Dense_Row &x, const Dense_Row &y)
 
void swap (Dense_Row &x, Dense_Row &y)
 Swaps x with y. More...
 
void iter_swap (std::vector< Dense_Row >::iterator x, std::vector< Dense_Row >::iterator y)
 Swaps objects referred by x and y. More...
 
bool operator== (const Dense_Row &x, const Dense_Row &y)
 Returns true if and only if x and y are equal. More...
 
bool operator!= (const Dense_Row &x, const Dense_Row &y)
 Returns true if and only if x and y are different. More...
 
void linear_combine (Dense_Row &x, const Dense_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2)
 
void linear_combine (Dense_Row &x, const Dense_Row &y, Coefficient_traits::const_reference c1, Coefficient_traits::const_reference c2, dimension_type start, dimension_type end)
 
bool operator!= (const Dense_Row &x, const Dense_Row &y)
 
void swap (Dense_Row &x, Dense_Row &y)
 
void iter_swap (std::vector< Dense_Row >::iterator x, std::vector< Dense_Row >::iterator y)
 

Detailed Description

A finite sequence of coefficients.

Definition at line 42 of file Dense_Row_defs.hh.

Constructor & Destructor Documentation

Parma_Polyhedra_Library::Dense_Row::Dense_Row ( )
inline

Constructs an empty row.

Definition at line 64 of file Dense_Row_inlines.hh.

References OK().

65  : impl() {
66 
67  PPL_ASSERT(OK());
68 }
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
Parma_Polyhedra_Library::Dense_Row::Dense_Row ( const Sparse_Row row)
explicit

Definition at line 240 of file Dense_Row.cc.

References init(), OK(), Parma_Polyhedra_Library::Sparse_Row::size(), and size().

241  : impl() {
242 
243  init(row);
244 
245  PPL_ASSERT(size() == row.size());
246  PPL_ASSERT(OK());
247 }
dimension_type size() const
Gives the number of coefficients currently in use.
void init(const Sparse_Row &row)
Definition: Dense_Row.cc:250
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
Parma_Polyhedra_Library::Dense_Row::Dense_Row ( dimension_type  sz)
inline

Tight constructor: resizing may require reallocation.

Constructs a row with size and capacity sz.

Definition at line 83 of file Dense_Row_inlines.hh.

References OK(), resize(), and size().

84  : impl() {
85 
86  resize(sz);
87 
88  PPL_ASSERT(size() == sz);
89  PPL_ASSERT(OK());
90 }
dimension_type size() const
Gives the number of coefficients currently in use.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
void resize(dimension_type sz)
Resizes the row to sz.
Definition: Dense_Row.cc:45
Parma_Polyhedra_Library::Dense_Row::Dense_Row ( dimension_type  sz,
dimension_type  capacity 
)
inline

Sizing constructor with capacity.

Parameters
szThe size of the row that will be constructed;
capacityThe capacity of the row that will be constructed;

The row that is constructed has storage for capacity elements, sz of which are default-constructed now.

Definition at line 71 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, impl, OK(), resize(), and size().

73  : impl() {
74 
75  resize(sz, capacity);
76 
77  PPL_ASSERT(size() == sz);
78  PPL_ASSERT(impl.capacity == capacity);
79  PPL_ASSERT(OK());
80 }
dimension_type size() const
Gives the number of coefficients currently in use.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
void resize(dimension_type sz)
Resizes the row to sz.
Definition: Dense_Row.cc:45
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
Parma_Polyhedra_Library::Dense_Row::Dense_Row ( const Dense_Row y)
inline

Ordinary copy constructor.

Definition at line 93 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, capacity(), Parma_Polyhedra_Library::Dense_Row::Impl::coeff_allocator, impl, OK(), size(), Parma_Polyhedra_Library::Dense_Row::Impl::size, and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

94  : impl() {
95  impl.coeff_allocator = y.impl.coeff_allocator;
96  if (y.impl.vec != 0) {
97  impl.capacity = y.capacity();
99  while (impl.size != y.size()) {
100  new(&impl.vec[impl.size]) Coefficient(y[impl.size]);
101  ++impl.size;
102  }
103  }
104  PPL_ASSERT(size() == y.size());
105  PPL_ASSERT(capacity() == y.capacity());
106  PPL_ASSERT(OK());
107 }
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
Parma_Polyhedra_Library::Dense_Row::Dense_Row ( const Dense_Row y,
dimension_type  capacity 
)
inline

Copy constructor with specified capacity.

It is assumed that capacity is greater than or equal to the size of y.

Definition at line 110 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, capacity(), Parma_Polyhedra_Library::Dense_Row::Impl::coeff_allocator, impl, max_size(), OK(), size(), Parma_Polyhedra_Library::Dense_Row::Impl::size, and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

112  : impl() {
113  PPL_ASSERT(y.size() <= capacity);
114  PPL_ASSERT(capacity <= max_size());
115 
117  impl.coeff_allocator = y.impl.coeff_allocator;
119 
120  if (y.impl.vec != 0) {
121  while (impl.size != y.size()) {
122  new(&impl.vec[impl.size]) Coefficient(y[impl.size]);
123  ++impl.size;
124  }
125  }
126 
127  PPL_ASSERT(size() == y.size());
128  PPL_ASSERT(impl.capacity == capacity);
129  PPL_ASSERT(OK());
130 }
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
static dimension_type max_size()
Returns the size() of the largest possible Dense_Row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
Parma_Polyhedra_Library::Dense_Row::Dense_Row ( const Dense_Row y,
dimension_type  sz,
dimension_type  capacity 
)
inline

Copy constructor with specified size and capacity.

It is assumed that sz is less than or equal to capacity.

Definition at line 133 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, capacity(), Parma_Polyhedra_Library::Dense_Row::Impl::coeff_allocator, impl, max_size(), OK(), size(), Parma_Polyhedra_Library::Dense_Row::Impl::size, and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

136  : impl() {
137  PPL_ASSERT(sz <= capacity);
138  PPL_ASSERT(capacity <= max_size());
139  PPL_ASSERT(capacity != 0);
140 
142  impl.coeff_allocator = y.impl.coeff_allocator;
144 
145  const dimension_type n = std::min(sz, y.size());
146  while (impl.size != n) {
147  new(&impl.vec[impl.size]) Coefficient(y[impl.size]);
148  ++impl.size;
149  }
150  while (impl.size != sz) {
151  new(&impl.vec[impl.size]) Coefficient();
152  ++impl.size;
153  }
154 
155  PPL_ASSERT(size() == sz);
156  PPL_ASSERT(impl.capacity == capacity);
157  PPL_ASSERT(OK());
158 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
static dimension_type max_size()
Returns the size() of the largest possible Dense_Row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
Parma_Polyhedra_Library::Dense_Row::Dense_Row ( const Sparse_Row y,
dimension_type  sz,
dimension_type  capacity 
)

Copy constructor with specified size and capacity from a Sparse_Row.

It is assumed that sz is less than or equal to capacity.

Definition at line 34 of file Dense_Row.cc.

References Parma_Polyhedra_Library::Sparse_Row::begin(), Parma_Polyhedra_Library::Sparse_Row::lower_bound(), OK(), resize(), and Parma_Polyhedra_Library::Sparse_Row::size().

35  {
36  resize(sz, capacity);
37  for (Sparse_Row::const_iterator i = y.begin(),
38  i_end = y.lower_bound(std::min(y.size(), sz)); i != i_end; ++i) {
39  (*this)[i.index()] = *i;
40  }
41  PPL_ASSERT(OK());
42 }
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
void resize(dimension_type sz)
Resizes the row to sz.
Definition: Dense_Row.cc:45
dimension_type capacity() const
Returns the capacity of the row.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
Parma_Polyhedra_Library::Dense_Row::~Dense_Row ( )
inline

Destructor.

Definition at line 161 of file Dense_Row_inlines.hh.

161  {
162  // The `impl' field will be destroyed automatically.
163 }

Member Function Documentation

void Parma_Polyhedra_Library::Dense_Row::add_zeroes_and_shift ( dimension_type  n,
dimension_type  i 
)

Adds n zeroes before index i.

Parameters
nThe number of zeroes that will be added to the row.
iThe index of the element before which the zeroes will be added.

Existing elements with index greater than or equal to i are shifted to the right by n positions. The size is increased by n.

Existing iterators are invalidated.

Definition at line 140 of file Dense_Row.cc.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, Parma_Polyhedra_Library::Dense_Row::Impl::coeff_allocator, Parma_Polyhedra_Library::compute_capacity(), impl, Parma_Polyhedra_Library::swap(), and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

140  {
141  PPL_ASSERT(i <= size());
142  const dimension_type new_size = size() + n;
143  if (new_size > capacity()) {
144  Dense_Row new_row;
145  const dimension_type new_capacity = compute_capacity(new_size, max_size());
146  // This may throw.
147  new_row.impl.vec = new_row.impl.coeff_allocator.allocate(new_capacity);
148  new_row.impl.capacity = new_capacity;
149 
150  dimension_type j = i;
151  try {
152  // Construct coefficients with value 0 in
153  // new_row.impl.vec[i ... i + n - 1]
154  for ( ; j < i + n; ++j) {
155  new(&(new_row.impl.vec[j])) Coefficient(0);
156  }
157  } catch (...) {
158  // Destroy the zeroes constructed so far.
159  while (j != i) {
160  --j;
161  new_row.impl.vec[j].~Coefficient();
162  }
163  // The new_row's destructor will de-allocate the memory.
164  throw;
165  }
166 
167  // Raw-copy the coefficients.
168  memcpy(new_row.impl.vec, impl.vec, sizeof(Coefficient) * i);
169  memcpy(&(new_row.impl.vec[i + n]), &impl.vec[i],
170  sizeof(Coefficient) * (impl.size - i));
171 
172  using std::swap;
173  swap(impl.vec, new_row.impl.vec);
174  swap(impl.capacity, new_row.impl.capacity);
175 
176  // *this now owns all coefficients, including the newly-added zeroes.
177  impl.size = new_size;
178 
179  // The old vec will be de-allocated at the end of this block.
180 
181  }
182  else {
183  memmove(&impl.vec[n + i], &impl.vec[i], sizeof(Coefficient)
184  * (impl.size - i));
185  impl.size = i;
186  const dimension_type target_size = impl.size + n;
187  PPL_ASSERT(target_size == i + n);
188  try {
189  // Construct n zeroes where the moved elements resided.
190  while (impl.size != target_size) {
191  new(&impl.vec[impl.size]) Coefficient(0);
192  ++impl.size;
193  }
194  impl.size = new_size;
195  } catch (...) {
196  // impl.vec[impl.size]..impl.vec[target_size-1] are still unconstructed,
197  // but impl.vec[target_size]..impl.vec[new_size] are constructed,
198  // because the memmove() moved already-constructed objects.
199 
200  // NOTE: This loop can't throw, because destructors must not throw.
201  for (dimension_type j = target_size; j < new_size; ++j) {
202  impl.vec[j].~Coefficient();
203  }
204 
205  throw;
206  }
207  }
208 
209  PPL_ASSERT(OK());
210 }
void swap(CO_Tree &x, CO_Tree &y)
void swap(Dense_Row &x, Dense_Row &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Dense_Row()
Constructs an empty row.
dimension_type compute_capacity(dimension_type requested_size, dimension_type maximum_size)
Speculative allocation function.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
static dimension_type max_size()
Returns the size() of the largest possible Dense_Row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
void Parma_Polyhedra_Library::Dense_Row::ascii_dump ( ) const

Writes to std::cerr an ASCII representation of *this.

void Parma_Polyhedra_Library::Dense_Row::ascii_dump ( std::ostream &  s) const

Writes to s an ASCII representation of *this.

Definition at line 479 of file Dense_Row.cc.

References size().

479  {
480  const Dense_Row& x = *this;
481  const dimension_type x_size = x.size();
482  s << "size " << x_size << " ";
483  for (dimension_type i = 0; i < x_size; ++i) {
484  s << x[i] << ' ';
485  }
486  s << "\n";
487 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
Dense_Row()
Constructs an empty row.
bool Parma_Polyhedra_Library::Dense_Row::ascii_load ( std::istream &  s)

Loads from s an ASCII representation (as produced by ascii_dump(std::ostream&) const) and sets *this accordingly. Returns true if successful, false otherwise.

Definition at line 492 of file Dense_Row.cc.

492  {
493  std::string str;
494  if (!(s >> str) || str != "size") {
495  return false;
496  }
497  dimension_type new_size;
498  if (!(s >> new_size)) {
499  return false;
500  }
501 
502  resize(new_size);
503 
504  for (dimension_type col = 0; col < new_size; ++col) {
505  if (!(s >> (*this)[col])) {
506  return false;
507  }
508  }
509 
510  return true;
511 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void resize(dimension_type sz)
Resizes the row to sz.
Definition: Dense_Row.cc:45
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::begin ( )
inline

Definition at line 238 of file Dense_Row_inlines.hh.

238  {
239  return iterator(*this, 0);
240 }
Dense_Row::const_iterator Parma_Polyhedra_Library::Dense_Row::begin ( ) const
inline

Definition at line 243 of file Dense_Row_inlines.hh.

243  {
244  return const_iterator(*this, 0);
245 }
dimension_type Parma_Polyhedra_Library::Dense_Row::capacity ( ) const
inlineprivate

Returns the capacity of the row.

Definition at line 59 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, and impl.

Referenced by Dense_Row(), and Parma_Polyhedra_Library::Dense_Row::Impl::~Impl().

59  {
60  return impl.capacity;
61 }
dimension_type capacity
The capacity of the row.
void Parma_Polyhedra_Library::Dense_Row::clear ( )

Resets all the elements of this row.

Definition at line 133 of file Dense_Row.cc.

133  {
134  for (iterator i = begin(), i_end = end(); i != i_end; ++i) {
135  *i = 0;
136  }
137 }
template<typename Func1 , typename Func2 , typename Func3 >
void Parma_Polyhedra_Library::Dense_Row::combine ( const Dense_Row y,
const Func1 &  f,
const Func2 &  g,
const Func3 &  h 
)

Calls g(x[i],y[i]), for each i.

Parameters
yThe row that will be combined with *this.
fA functor that should take a Coefficient&. f(c1) must be equivalent to g(c1, 0).
gA functor that should take a Coefficient& and a Coefficient_traits::const_reference. g(c1, c2) must do nothing when both c1 and c2 are zero.
hA functor that should take a Coefficient& and a Coefficient_traits::const_reference. h(c1, c2) must be equivalent to g(c1, c2) when c1 is zero.

This method takes $O(n)$ time.

Note
The functors will only be called when necessary, assuming the requested properties hold.
See also
combine_needs_first
combine_needs_second

Definition at line 50 of file Dense_Row_templates.hh.

References size().

51  {
52  for (dimension_type i = size(); i-- > 0; ) {
53  g((*this)[i], y[i]);
54  }
55 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type size() const
Gives the number of coefficients currently in use.
template<typename Func1 , typename Func2 >
void Parma_Polyhedra_Library::Dense_Row::combine_needs_first ( const Dense_Row y,
const Func1 &  f,
const Func2 &  g 
)

Calls g(x[i],y[i]), for each i.

Parameters
yThe row that will be combined with *this.
fA functor that should take a Coefficient&. f(c1) must be equivalent to g(c1, 0).
gA functor that should take a Coefficient& and a Coefficient_traits::const_reference. g(c1, c2) must do nothing when c1 is zero.

This method takes $O(n)$ time.

Note
The functors will only be called when necessary, assuming the requested properties hold.
See also
combine_needs_second
combine

Definition at line 32 of file Dense_Row_templates.hh.

References size().

33  {
34  for (dimension_type i = size(); i-- > 0; ) {
35  g((*this)[i], y[i]);
36  }
37 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type size() const
Gives the number of coefficients currently in use.
template<typename Func1 , typename Func2 >
void Parma_Polyhedra_Library::Dense_Row::combine_needs_second ( const Dense_Row y,
const Func1 &  g,
const Func2 &  h 
)

Calls g(x[i],y[i]), for each i.

Parameters
yThe row that will be combined with *this.
gA functor that should take a Coefficient& and a Coefficient_traits::const_reference. g(c1, 0) must do nothing, for every c1.
hA functor that should take a Coefficient& and a Coefficient_traits::const_reference. h(c1, c2) must be equivalent to g(c1, c2) when c1 is zero.

This method takes $O(n)$ time.

Note
The functors will only be called when necessary, assuming the requested properties hold.
See also
combine_needs_first
combine

Definition at line 41 of file Dense_Row_templates.hh.

References size().

42  {
43  for (dimension_type i = size(); i-- > 0; ) {
44  g((*this)[i], y[i]);
45  }
46 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type size() const
Gives the number of coefficients currently in use.
void Parma_Polyhedra_Library::Dense_Row::destroy ( )
inlineprivate

Definition at line 166 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, Parma_Polyhedra_Library::Dense_Row::Impl::coeff_allocator, impl, resize(), and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

166  {
167  resize(0);
168  impl.coeff_allocator.deallocate(impl.vec, impl.capacity);
169 }
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
void resize(dimension_type sz)
Resizes the row to sz.
Definition: Dense_Row.cc:45
dimension_type capacity
The capacity of the row.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::end ( )
inline

Definition at line 248 of file Dense_Row_inlines.hh.

References size().

248  {
249  return iterator(*this, size());
250 }
dimension_type size() const
Gives the number of coefficients currently in use.
Dense_Row::const_iterator Parma_Polyhedra_Library::Dense_Row::end ( ) const
inline

Definition at line 253 of file Dense_Row_inlines.hh.

References size().

253  {
254  return const_iterator(*this, size());
255 }
dimension_type size() const
Gives the number of coefficients currently in use.
void Parma_Polyhedra_Library::Dense_Row::expand_within_capacity ( dimension_type  new_size)

Expands the row to size new_size.

Adds new positions to the implementation of the row obtaining a new row with size new_size. It is assumed that new_size is between the current size and capacity of the row.

Definition at line 213 of file Dense_Row.cc.

213  {
214  PPL_ASSERT(new_size <= impl.capacity);
215  PPL_ASSERT(size() <= new_size && new_size <= max_size());
216  while (impl.size != new_size) {
217  new(&impl.vec[impl.size]) Coefficient();
218  ++impl.size;
219  }
220  PPL_ASSERT(size() == new_size);
221  PPL_ASSERT(OK());
222 }
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
static dimension_type max_size()
Returns the size() of the largest possible Dense_Row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
PPL::memory_size_type Parma_Polyhedra_Library::Dense_Row::external_memory_in_bytes ( ) const

Returns a lower bound to the size in bytes of the memory managed by *this.

Definition at line 519 of file Dense_Row.cc.

References Parma_Polyhedra_Library::external_memory_in_bytes().

Referenced by total_memory_in_bytes().

519  {
521  for (dimension_type i = size(); i-- > 0; ) {
523  }
524  return n;
525 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type size() const
Gives the number of coefficients currently in use.
Enable_If< Is_Native< T >::value, memory_size_type >::type external_memory_in_bytes(const T &)
For native types, returns the size in bytes of the memory managed by the type of the (unused) paramet...
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
dimension_type capacity
The capacity of the row.
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.
PPL::memory_size_type Parma_Polyhedra_Library::Dense_Row::external_memory_in_bytes ( dimension_type  capacity) const

Returns the size in bytes of the memory managed by *this, provided the capacity of *this is given by capacity.

Definition at line 514 of file Dense_Row.cc.

References Parma_Polyhedra_Library::external_memory_in_bytes().

514  {
515  return external_memory_in_bytes();
516 }
memory_size_type external_memory_in_bytes() const
Returns a lower bound to the size in bytes of the memory managed by *this.
Definition: Dense_Row.cc:519
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::find ( dimension_type  i)
inline

Provided for compatibility with Sparse_Row.

Definition at line 263 of file Dense_Row_inlines.hh.

Referenced by insert(), and lower_bound().

263  {
264  return iterator(*this, i);
265 }
Dense_Row::const_iterator Parma_Polyhedra_Library::Dense_Row::find ( dimension_type  i) const
inline

Provided for compatibility with Sparse_Row.

Definition at line 268 of file Dense_Row_inlines.hh.

268  {
269  return const_iterator(*this, i);
270 }
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::find ( iterator  itr,
dimension_type  i 
)
inline

Provided for compatibility with Sparse_Row.

Definition at line 273 of file Dense_Row_inlines.hh.

273  {
274  (void)itr;
275  return iterator(*this, i);
276 }
Dense_Row::const_iterator Parma_Polyhedra_Library::Dense_Row::find ( const_iterator  itr,
dimension_type  i 
) const
inline

Provided for compatibility with Sparse_Row.

Definition at line 279 of file Dense_Row_inlines.hh.

279  {
280  (void)itr;
281  return const_iterator(*this, i);
282 }
Coefficient_traits::const_reference Parma_Polyhedra_Library::Dense_Row::get ( dimension_type  i) const
inline

Gets the i-th element. Provided for compatibility with Sparse_Row.

Definition at line 258 of file Dense_Row_inlines.hh.

Referenced by Parma_Polyhedra_Library::MIP_Problem::linear_combine().

258  {
259  return (*this)[i];
260 }
void Parma_Polyhedra_Library::Dense_Row::init ( const Sparse_Row row)
private

Definition at line 250 of file Dense_Row.cc.

References Parma_Polyhedra_Library::Sparse_Row::begin(), Parma_Polyhedra_Library::Sparse_Row::end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), and Parma_Polyhedra_Library::Sparse_Row::size().

Referenced by Dense_Row().

250  {
251  impl.capacity = row.size();
253  Sparse_Row::const_iterator itr = row.begin();
254  Sparse_Row::const_iterator itr_end = row.end();
255  while (impl.size != impl.capacity) {
256  // Constructs (*this)[impl.size] with row[impl.size].
257  if (itr != itr_end && itr.index() == impl.size) {
258  new(&impl.vec[impl.size]) Coefficient(*itr);
259  ++itr;
260  }
261  else {
262  new(&impl.vec[impl.size]) Coefficient();
263  }
264  ++impl.size;
265  }
266  PPL_ASSERT(size() == row.size());
267  PPL_ASSERT(OK());
268 }
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::insert ( dimension_type  i,
Coefficient_traits::const_reference  x 
)
inline

Provided for compatibility with Sparse_Row.

Definition at line 305 of file Dense_Row_inlines.hh.

References find().

306  {
307  (*this)[i] = x;
308  return find(i);
309 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::insert ( dimension_type  i)
inline

Provided for compatibility with Sparse_Row.

Definition at line 312 of file Dense_Row_inlines.hh.

References find().

312  {
313  return find(i);
314 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::insert ( iterator  itr,
dimension_type  i,
Coefficient_traits::const_reference  x 
)
inline

Provided for compatibility with Sparse_Row.

Definition at line 317 of file Dense_Row_inlines.hh.

References find().

318  {
319  (void)itr;
320  (*this)[i] = x;
321  return find(i);
322 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::insert ( iterator  itr,
dimension_type  i 
)
inline

Provided for compatibility with Sparse_Row.

Definition at line 325 of file Dense_Row_inlines.hh.

References find().

325  {
326  (void)itr;
327  return find(i);
328 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
void Parma_Polyhedra_Library::Dense_Row::linear_combine ( const Dense_Row y,
Coefficient_traits::const_reference  coeff1,
Coefficient_traits::const_reference  coeff2 
)

Executes (*this)[i] = (*this)[i]*coeff1 + y[i]*coeff2, for each i.

Parameters
yThe row that will be combined with *this.
coeff1The coefficient used for elements of *this. It must not be 0.
coeff2The coefficient used for elements of y. It must not be 0.

This method takes $O(n)$ time.

See also
combine_needs_first
combine_needs_second
combine

Definition at line 389 of file Dense_Row.cc.

References linear_combine(), and size().

Referenced by linear_combine(), and Parma_Polyhedra_Library::linear_combine().

391  {
392  Dense_Row& x = *this;
393  PPL_ASSERT(x.size() == y.size());
394 
395  x.linear_combine(y, coeff1, coeff2, 0, x.size());
396 }
Dense_Row()
Constructs an empty row.
void Parma_Polyhedra_Library::Dense_Row::linear_combine ( const Dense_Row y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
)

Equivalent to (*this)[i] = (*this)[i] * c1 + y[i] * c2, for each i in [start, end).

This method detects when coeff1==1 and/or coeff2==1 or coeff2==-1 in order to save some work.

coeff1 and coeff2 must not be 0.

Definition at line 399 of file Dense_Row.cc.

References Parma_Polyhedra_Library::add_mul_assign(), and size().

402  {
403  Dense_Row& x = *this;
404  PPL_ASSERT(start <= end);
405  PPL_ASSERT(end <= x.size());
406  PPL_ASSERT(end <= y.size());
407  PPL_ASSERT(coeff1 != 0);
408  PPL_ASSERT(coeff2 != 0);
409 
410  // If coeff1 is 1 and/or coeff2 is 1 or -1, we use an optimized
411  // implementation.
412 
413  if (coeff1 == 1) {
414  if (coeff2 == 1) {
415  // Optimized implementation for coeff1==1, coeff2==1.
416  for (dimension_type i = start; i < end; ++i) {
417  if (y[i] != 0) {
418  x[i] += y[i];
419  }
420  }
421  return;
422  }
423  if (coeff2 == -1) {
424  // Optimized implementation for coeff1==1, coeff2==-1.
425  for (dimension_type i = start; i < end; ++i) {
426  if (y[i] != 0) {
427  x[i] -= y[i];
428  }
429  }
430  return;
431  }
432  // Optimized implementation for coeff1==1.
433  for (dimension_type i = start; i < end; ++i) {
434  Coefficient& x_i = x[i];
435  // The test against 0 gives rise to a consistent speed up: see
436  // http://www.cs.unipr.it/pipermail/ppl-devel/2009-February/014000.html
437  Coefficient_traits::const_reference y_i = y[i];
438  if (y_i != 0) {
439  add_mul_assign(x_i, y_i, coeff2);
440  }
441  }
442  return;
443  }
444 
445  if (coeff2 == 1) {
446  // Optimized implementation for coeff2==1.
447  for (dimension_type i = start; i < end; ++i) {
448  x[i] *= coeff1;
449  if (y[i] != 0) {
450  x[i] += y[i];
451  }
452  }
453  return;
454  }
455  if (coeff2 == -1) {
456  // Optimized implementation for coeff2==-1.
457  for (dimension_type i = start; i < end; ++i) {
458  x[i] *= coeff1;
459  if (y[i] != 0) {
460  x[i] -= y[i];
461  }
462  }
463  return;
464  }
465  // General case.
466  for (dimension_type i = start; i < end; ++i) {
467  Coefficient& x_i = x[i];
468  x[i] *= coeff1;
469  // The test against 0 gives rise to a consistent speed up: see
470  // http://www.cs.unipr.it/pipermail/ppl-devel/2009-February/014000.html
471  Coefficient_traits::const_reference y_i = y[i];
472  if (y_i != 0) {
473  add_mul_assign(x_i, y_i, coeff2);
474  }
475  }
476 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void add_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
Dense_Row()
Constructs an empty row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::lower_bound ( dimension_type  i)
inline

Provided for compatibility with Sparse_Row.

Definition at line 285 of file Dense_Row_inlines.hh.

References find().

285  {
286  return find(i);
287 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
Dense_Row::const_iterator Parma_Polyhedra_Library::Dense_Row::lower_bound ( dimension_type  i) const
inline

Provided for compatibility with Sparse_Row.

Definition at line 290 of file Dense_Row_inlines.hh.

References find().

290  {
291  return find(i);
292 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::lower_bound ( iterator  itr,
dimension_type  i 
)
inline

Provided for compatibility with Sparse_Row.

Definition at line 295 of file Dense_Row_inlines.hh.

References find().

295  {
296  return find(itr, i);
297 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
Dense_Row::const_iterator Parma_Polyhedra_Library::Dense_Row::lower_bound ( const_iterator  itr,
dimension_type  i 
) const
inline

Provided for compatibility with Sparse_Row.

Definition at line 300 of file Dense_Row_inlines.hh.

References find().

300  {
301  return find(itr, i);
302 }
iterator find(dimension_type i)
Provided for compatibility with Sparse_Row.
void Parma_Polyhedra_Library::Dense_Row::m_swap ( Dense_Row y)
inline

Swaps *this with y.

Definition at line 172 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::Dense_Row::Impl::capacity, Parma_Polyhedra_Library::Dense_Row::Impl::coeff_allocator, impl, OK(), Parma_Polyhedra_Library::Dense_Row::Impl::size, swap(), Parma_Polyhedra_Library::swap(), and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

Referenced by swap().

172  {
173  using std::swap;
174  swap(impl.size, y.impl.size);
175  swap(impl.capacity, y.impl.capacity);
176  swap(impl.coeff_allocator, y.impl.coeff_allocator);
177  swap(impl.vec, y.impl.vec);
178  PPL_ASSERT(OK());
179  PPL_ASSERT(y.OK());
180 }
void swap(CO_Tree &x, CO_Tree &y)
void swap(Dense_Row &x, Dense_Row &y)
Swaps x with y.
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
dimension_type size
The number of coefficients in the row.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
dimension_type Parma_Polyhedra_Library::Dense_Row::max_size ( )
inlinestatic

Returns the size() of the largest possible Dense_Row.

Definition at line 49 of file Dense_Row_inlines.hh.

Referenced by Dense_Row(), and Parma_Polyhedra_Library::Linear_Expression::max_space_dimension().

49  {
50  return std::numeric_limits<size_t>::max() / sizeof(Coefficient);
51 }
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void Parma_Polyhedra_Library::Dense_Row::normalize ( )

Normalizes the modulo of coefficients so that they are mutually prime.

Computes the Greatest Common Divisor (GCD) among the elements of the row and normalizes them by the GCD itself.

Definition at line 329 of file Dense_Row.cc.

References Parma_Polyhedra_Library::exact_div_assign(), Parma_Polyhedra_Library::gcd_assign(), Parma_Polyhedra_Library::neg_assign(), PPL_DIRTY_TEMP_COEFFICIENT, and Parma_Polyhedra_Library::Boundary_NS::sgn().

Referenced by Parma_Polyhedra_Library::MIP_Problem::linear_combine().

329  {
330  Dense_Row& x = *this;
331  // Compute the GCD of all the coefficients.
332  const dimension_type sz = size();
333  dimension_type i = sz;
335  while (i > 0) {
336  Coefficient_traits::const_reference x_i = x[--i];
337  if (const int x_i_sign = sgn(x_i)) {
338  gcd = x_i;
339  if (x_i_sign < 0) {
340  neg_assign(gcd);
341  }
342  goto compute_gcd;
343  }
344  }
345  // We reach this point only if all the coefficients were zero.
346  return;
347 
348 compute_gcd:
349  if (gcd == 1) {
350  return;
351  }
352  while (i > 0) {
353  Coefficient_traits::const_reference x_i = x[--i];
354  if (x_i != 0) {
355  // Note: we use the ternary version instead of a more concise
356  // gcd_assign(gcd, x_i) to take advantage of the fact that
357  // `gcd' will decrease very rapidly (see D. Knuth, The Art of
358  // Computer Programming, second edition, Section 4.5.2,
359  // Algorithm C, and the discussion following it). Our
360  // implementation of gcd_assign(x, y, z) for checked numbers is
361  // optimized for the case where `z' is smaller than `y', so that
362  // on checked numbers we gain. On the other hand, for the
363  // implementation of gcd_assign(x, y, z) on GMP's unbounded
364  // integers we cannot make any assumption, so here we draw.
365  // Overall, we win.
366  gcd_assign(gcd, x_i, gcd);
367  if (gcd == 1) {
368  return;
369  }
370  }
371  }
372  // Divide the coefficients by the GCD.
373  for (dimension_type j = sz; j-- > 0; ) {
374  Coefficient& x_j = x[j];
375  exact_div_assign(x_j, x_j, gcd);
376  }
377 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
Dense_Row()
Constructs an empty row.
void exact_div_assign(Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
dimension_type size() const
Gives the number of coefficients currently in use.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void neg_assign(GMP_Integer &x)
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
int sgn(Boundary_Type type, const T &x, const Info &info)
bool Parma_Polyhedra_Library::Dense_Row::OK ( ) const

Checks if all the invariants are satisfied.

Definition at line 528 of file Dense_Row.cc.

Referenced by Dense_Row(), m_swap(), Parma_Polyhedra_Library::Dense_Row::iterator::operator++(), Parma_Polyhedra_Library::Dense_Row::const_iterator::operator++(), Parma_Polyhedra_Library::Dense_Row::iterator::operator--(), and Parma_Polyhedra_Library::Dense_Row::const_iterator::operator--().

528  {
529 #ifndef NDEBUG
530  using std::endl;
531  using std::cerr;
532 #endif
533 
534  bool is_broken = false;
535 
536  if (impl.capacity > max_size()) {
537 #ifndef NDEBUG
538  cerr << "Dense_Row capacity exceeds the maximum allowed size:" << endl
539  << "is " << impl.capacity
540  << ", should be less than or equal to " << max_size() << "."
541  << endl;
542 #endif
543  is_broken = true;
544  }
545 
546  if (size() > max_size()) {
547 #ifndef NDEBUG
548  cerr << "Dense_Row size exceeds the maximum allowed size:" << endl
549  << "is " << size()
550  << ", should be less than or equal to " << max_size() << "." << endl;
551 #endif
552  is_broken = true;
553  }
554 
555  if (impl.capacity < size()) {
556 #ifndef NDEBUG
557  cerr << "Dense_Row is completely broken: capacity is " << impl.capacity
558  << ", size is " << size() << "." << endl;
559 #endif
560  is_broken = true;
561  }
562 
563  if (capacity() == 0) {
564  if (impl.vec != 0) {
565  is_broken = true;
566  }
567  }
568  else {
569  if (impl.vec == 0) {
570  is_broken = true;
571  }
572  }
573 
574  return !is_broken;
575 }
dimension_type size() const
Gives the number of coefficients currently in use.
static dimension_type max_size()
Returns the size() of the largest possible Dense_Row.
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
bool Parma_Polyhedra_Library::Dense_Row::OK ( dimension_type  row_size) const

Checks if all the invariants are satisfied and that the actual size matches the value provided as argument.

Definition at line 578 of file Dense_Row.cc.

578  {
579 #ifndef NDEBUG
580  using std::endl;
581  using std::cerr;
582 #endif
583 
584  bool is_broken = !OK();
585 
586  // Check the declared size.
587  if (size() != row_size) {
588 #ifndef NDEBUG
589  cerr << "Dense_Row size mismatch: is " << size()
590  << ", should be " << row_size << "." << endl;
591 #endif
592  is_broken = true;
593  }
594  return !is_broken;
595 }
dimension_type size() const
Gives the number of coefficients currently in use.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
Dense_Row & Parma_Polyhedra_Library::Dense_Row::operator= ( const Dense_Row y)
inline

Assignment operator.

Definition at line 183 of file Dense_Row_inlines.hh.

References size(), and swap().

183  {
184 
185  if (this != &y && size() == y.size()) {
186  // Avoid reallocation.
187 
188  for (dimension_type i = size(); i-- > 0; ) {
189  (*this)[i] = y[i];
190  }
191 
192  return *this;
193  }
194 
195  Dense_Row x(y);
196  swap(*this, x);
197 
198  return *this;
199 }
void swap(Dense_Row &x, Dense_Row &y)
Swaps x with y.
size_t dimension_type
An unsigned integral type for representing space dimensions.
Dense_Row()
Constructs an empty row.
dimension_type size() const
Gives the number of coefficients currently in use.
PPL::Dense_Row & Parma_Polyhedra_Library::Dense_Row::operator= ( const Sparse_Row y)

Assignment operator.

Definition at line 271 of file Dense_Row.cc.

References Parma_Polyhedra_Library::Sparse_Row::begin(), Parma_Polyhedra_Library::Coefficient_zero(), Parma_Polyhedra_Library::Sparse_Row::end(), Parma_Polyhedra_Library::CO_Tree::const_iterator::index(), and Parma_Polyhedra_Library::Sparse_Row::size().

271  {
272  if (size() > row.size()) {
273  // TODO: If the shrink() is modified to reallocate a smaller chunk,
274  // this can be optimized.
275  shrink(row.size());
276  Sparse_Row::const_iterator itr = row.begin();
277  Sparse_Row::const_iterator itr_end = row.end();
278  for (dimension_type i = 0; i < impl.size; ++i) {
279  // Computes (*this)[impl.size] = row[impl.size].
280  if (itr != itr_end && itr.index() == i) {
281  impl.vec[impl.size] = *itr;
282  ++itr;
283  }
284  else {
286  }
287  }
288  }
289  else {
290  if (capacity() >= row.size()) {
291  // size() <= row.size() <= capacity().
292  Sparse_Row::const_iterator itr = row.begin();
293  Sparse_Row::const_iterator itr_end = row.end();
294  for (dimension_type i = 0; i < impl.size; ++i) {
295  // The following code is equivalent to (*this)[i] = row[i].
296  if (itr != itr_end && itr.index() == impl.size) {
297  new(&impl.vec[impl.size]) Coefficient(*itr);
298  ++itr;
299  }
300  else {
301  new(&impl.vec[impl.size]) Coefficient();
302  }
303  }
304  // Construct the additional elements.
305  for ( ; impl.size != row.size(); ++impl.size) {
306  // Constructs (*this)[impl.size] with row[impl.size].
307  if (itr != itr_end && itr.index() == impl.size) {
308  new(&impl.vec[impl.size]) Coefficient(*itr);
309  ++itr;
310  }
311  else {
312  new(&impl.vec[impl.size]) Coefficient();
313  }
314  }
315  }
316  else {
317  // Reallocation is required.
318  destroy();
319  init(row);
320  }
321  }
322  PPL_ASSERT(size() == row.size());
323  PPL_ASSERT(OK());
324 
325  return *this;
326 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void init(const Sparse_Row &row)
Definition: Dense_Row.cc:250
void shrink(dimension_type new_size)
Shrinks the row by erasing elements at the end.
Definition: Dense_Row.cc:225
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
Coefficient_traits::const_reference Coefficient_zero()
Returns a const reference to a Coefficient with value 0.
dimension_type capacity() const
Returns the capacity of the row.
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
Coefficient & Parma_Polyhedra_Library::Dense_Row::operator[] ( dimension_type  k)
inline

Returns a reference to the element of the row indexed by k.

Definition at line 202 of file Dense_Row_inlines.hh.

References impl, size(), and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

202  {
203  PPL_ASSERT(impl.vec != 0);
204  PPL_ASSERT(k < size());
205  return impl.vec[k];
206 }
dimension_type size() const
Gives the number of coefficients currently in use.
Coefficient_traits::const_reference Parma_Polyhedra_Library::Dense_Row::operator[] ( dimension_type  k) const
inline

Returns a constant reference to the element of the row indexed by k.

Definition at line 209 of file Dense_Row_inlines.hh.

References impl, size(), and Parma_Polyhedra_Library::Dense_Row::Impl::vec.

209  {
210  PPL_ASSERT(impl.vec != 0);
211  PPL_ASSERT(k < size());
212  return impl.vec[k];
213 }
dimension_type size() const
Gives the number of coefficients currently in use.
void Parma_Polyhedra_Library::Dense_Row::print ( ) const

Prints *this to std::cerr using operator<<.

void Parma_Polyhedra_Library::Dense_Row::reset ( dimension_type  i)
inline

Resets the i-th element to 0. Provided for compatibility with Sparse_Row

Definition at line 226 of file Dense_Row_inlines.hh.

Referenced by Parma_Polyhedra_Library::Expression_Hide_Inhomo< T >::get_row().

226  {
227  (*this)[i] = 0;
228 }
void Parma_Polyhedra_Library::Dense_Row::reset ( dimension_type  first,
dimension_type  last 
)

Resets the elements [first,last) to 0. Provided for compatibility with Sparse_Row

Definition at line 380 of file Dense_Row.cc.

380  {
381  PPL_ASSERT(first <= last);
382  PPL_ASSERT(last <= size());
383  for (dimension_type i = first; i < last; ++i) {
384  (*this)[i] = 0;
385  }
386 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
dimension_type size() const
Gives the number of coefficients currently in use.
Dense_Row::iterator Parma_Polyhedra_Library::Dense_Row::reset ( iterator  itr)
inline

Resets the element pointed to by itr to 0. Provided for compatibility with Sparse_Row.

Definition at line 231 of file Dense_Row_inlines.hh.

231  {
232  *itr = 0;
233  ++itr;
234  return itr;
235 }
void Parma_Polyhedra_Library::Dense_Row::resize ( dimension_type  sz)

Resizes the row to sz.

Definition at line 45 of file Dense_Row.cc.

Referenced by Dense_Row(), destroy(), and Parma_Polyhedra_Library::Expression_Hide_Last< T >::get_row().

45  {
46  if (new_size <= size()) {
47  shrink(new_size);
48  }
49  else {
50  if (new_size > capacity()) {
51  // Reallocation is required.
52  // TODO: Consider using realloc() here.
53  // TODO: Consider using a smarter allocation strategy.
54  const dimension_type new_capacity = new_size;
55  Coefficient* const new_vec = impl.coeff_allocator.allocate(new_capacity);
56 
57  if (impl.vec != 0) {
58  memcpy(new_vec, impl.vec, sizeof(Coefficient) * impl.size);
60  }
61 
62  impl.vec = new_vec;
63  impl.capacity = new_capacity;
64  }
65  PPL_ASSERT(new_size <= impl.capacity);
66  // Construct the additional elements.
67  while (impl.size != new_size) {
68  new(&impl.vec[impl.size]) Coefficient();
69  ++impl.size;
70  }
71  }
72  PPL_ASSERT(size() == new_size);
73  PPL_ASSERT(OK());
74 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void shrink(dimension_type new_size)
Shrinks the row by erasing elements at the end.
Definition: Dense_Row.cc:225
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
void Parma_Polyhedra_Library::Dense_Row::resize ( dimension_type  sz,
dimension_type  capacity 
)

Resizes the row to sz, with capacity capacity.

Definition at line 77 of file Dense_Row.cc.

77  {
78  PPL_ASSERT(new_size <= new_capacity);
79 
80  if (new_capacity == 0) {
81  destroy();
82  impl.vec = 0;
83  impl.size = 0;
84  impl.capacity = 0;
85 
86  PPL_ASSERT(size() == new_size);
87  PPL_ASSERT(capacity() == new_capacity);
88  PPL_ASSERT(OK());
89 
90  return;
91  }
92 
93  if (new_capacity < capacity()) {
94 
95  shrink(new_size);
96 
97  PPL_ASSERT(impl.size == new_size);
98 
99  Coefficient* const new_vec = impl.coeff_allocator.allocate(new_capacity);
100 
101  PPL_ASSERT(impl.vec != 0);
102 
103  memcpy(new_vec, impl.vec, sizeof(Coefficient) * impl.size);
104 
105  impl.coeff_allocator.deallocate(impl.vec, impl.capacity);
106 
107  impl.vec = new_vec;
108  impl.capacity = new_capacity;
109  }
110  else {
111  if (new_capacity > capacity()) {
112 
113  Coefficient* const new_vec = impl.coeff_allocator.allocate(new_capacity);
114 
115  if (impl.vec != 0) {
116  memcpy(new_vec, impl.vec, sizeof(Coefficient) * impl.size);
117  impl.coeff_allocator.deallocate(impl.vec, impl.capacity);
118  }
119 
120  impl.vec = new_vec;
121  impl.capacity = new_capacity;
122 
123  resize(new_size);
124  }
125  }
126 
127  PPL_ASSERT(size() == new_size);
128  PPL_ASSERT(capacity() == new_capacity);
129  PPL_ASSERT(OK());
130 }
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void shrink(dimension_type new_size)
Shrinks the row by erasing elements at the end.
Definition: Dense_Row.cc:225
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
void resize(dimension_type sz)
Resizes the row to sz.
Definition: Dense_Row.cc:45
dimension_type capacity
The capacity of the row.
dimension_type capacity() const
Returns the capacity of the row.
void Parma_Polyhedra_Library::Dense_Row::shrink ( dimension_type  new_size)

Shrinks the row by erasing elements at the end.

Destroys elements of the row implementation from position new_size to the end. It is assumed that new_size is not greater than the current size.

Definition at line 225 of file Dense_Row.cc.

225  {
226  PPL_ASSERT(new_size <= size());
227  // Since ~Coefficient() does not throw exceptions, nothing here does.
228 
229  // We assume construction was done "forward".
230  // We thus perform destruction "backward".
231  while (impl.size != new_size) {
232  --impl.size;
233  impl.vec[impl.size].~Coefficient();
234  }
235 
236  PPL_ASSERT(size() == new_size);
237  PPL_ASSERT(OK());
238 }
dimension_type size() const
Gives the number of coefficients currently in use.
dimension_type size
The number of coefficients in the row.
bool OK() const
Checks if all the invariants are satisfied.
Definition: Dense_Row.cc:528
void Parma_Polyhedra_Library::Dense_Row::swap_coefficients ( dimension_type  i,
dimension_type  j 
)
inline

Swaps the i-th element with the j-th element. Provided for compatibility with Sparse_Row

Definition at line 216 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::swap().

216  {
217  std::swap((*this)[i], (*this)[j]);
218 }
void swap(CO_Tree &x, CO_Tree &y)
void Parma_Polyhedra_Library::Dense_Row::swap_coefficients ( iterator  i,
iterator  j 
)
inline

Swaps the element pointed to by i with the element pointed to by j. Provided for compatibility with Sparse_Row

Definition at line 221 of file Dense_Row_inlines.hh.

References Parma_Polyhedra_Library::swap().

221  {
222  std::swap(*i, *j);
223 }
void swap(CO_Tree &x, CO_Tree &y)
memory_size_type Parma_Polyhedra_Library::Dense_Row::total_memory_in_bytes ( ) const
inline

Returns a lower bound to the total size in bytes of the memory occupied by *this.

Definition at line 331 of file Dense_Row_inlines.hh.

References external_memory_in_bytes().

331  {
332  return sizeof(*this) + external_memory_in_bytes();
333 }
memory_size_type external_memory_in_bytes() const
Returns a lower bound to the size in bytes of the memory managed by *this.
Definition: Dense_Row.cc:519
memory_size_type Parma_Polyhedra_Library::Dense_Row::total_memory_in_bytes ( dimension_type  capacity) const
inline

Returns the total size in bytes of the memory occupied by *this, provided the capacity of *this is given by capacity.

Definition at line 336 of file Dense_Row_inlines.hh.

References external_memory_in_bytes().

336  {
337  return sizeof(*this) + external_memory_in_bytes(capacity);
338 }
memory_size_type external_memory_in_bytes() const
Returns a lower bound to the size in bytes of the memory managed by *this.
Definition: Dense_Row.cc:519
dimension_type capacity() const
Returns the capacity of the row.

Friends And Related Function Documentation

void iter_swap ( std::vector< Dense_Row >::iterator  x,
std::vector< Dense_Row >::iterator  y 
)
related

Swaps objects referred by x and y.

void iter_swap ( std::vector< Dense_Row >::iterator  x,
std::vector< Dense_Row >::iterator  y 
)
related

Definition at line 527 of file Dense_Row_inlines.hh.

References swap().

528  {
529  swap(*x, *y);
530 }
void swap(Dense_Row &x, Dense_Row &y)
Swaps x with y.
void linear_combine ( Dense_Row x,
const Dense_Row y,
Coefficient_traits::const_reference  coeff1,
Coefficient_traits::const_reference  coeff2 
)
related

Definition at line 505 of file Dense_Row_inlines.hh.

507  {
508  x.linear_combine(y, coeff1, coeff2);
509 }
void linear_combine ( Dense_Row x,
const Dense_Row y,
Coefficient_traits::const_reference  c1,
Coefficient_traits::const_reference  c2,
dimension_type  start,
dimension_type  end 
)
related

Equivalent to x[i] = x[i] * c1 + y[i] * c2, for each i in [start, end).

Definition at line 512 of file Dense_Row_inlines.hh.

515  {
516  x.linear_combine(y, c1, c2, start, end);
517 }
bool operator!= ( const Dense_Row x,
const Dense_Row y 
)
related

Definition at line 342 of file Dense_Row_inlines.hh.

342  {
343  return !(x == y);
344 }
bool operator!= ( const Dense_Row x,
const Dense_Row y 
)
related

Returns true if and only if x and y are different.

bool operator== ( const Dense_Row x,
const Dense_Row y 
)
related

Returns true if and only if x and y are equal.

bool operator== ( const Dense_Row x,
const Dense_Row y 
)
related

Definition at line 599 of file Dense_Row.cc.

References size().

599  {
600  const dimension_type x_size = x.size();
601  const dimension_type y_size = y.size();
602 
603  if (x_size != y_size) {
604  return false;
605  }
606 
607  for (dimension_type i = x_size; i-- > 0; ) {
608  if (x[i] != y[i]) {
609  return false;
610  }
611  }
612 
613  return true;
614 }
size_t dimension_type
An unsigned integral type for representing space dimensions.
void swap ( Dense_Row x,
Dense_Row y 
)
related

Swaps x with y.

Referenced by iter_swap(), m_swap(), and operator=().

void swap ( Dense_Row x,
Dense_Row y 
)
related

Definition at line 521 of file Dense_Row_inlines.hh.

References m_swap().

521  {
522  x.m_swap(y);
523 }

Member Data Documentation

Impl Parma_Polyhedra_Library::Dense_Row::impl
private

The documentation for this class was generated from the following files: