24 #include "ppl-config.h"
27 #include "assertions.hh"
39 (*this)[i.index()] = *i;
46 if (new_size <= size()) {
50 if (new_size > capacity()) {
55 Coefficient*
const new_vec = impl.coeff_allocator.allocate(new_capacity);
58 memcpy(new_vec, impl.vec,
sizeof(
Coefficient) * impl.size);
59 impl.coeff_allocator.deallocate(impl.vec, impl.capacity);
63 impl.capacity = new_capacity;
65 PPL_ASSERT(new_size <= impl.capacity);
67 while (impl.size != new_size) {
72 PPL_ASSERT(size() == new_size);
78 PPL_ASSERT(new_size <= new_capacity);
80 if (new_capacity == 0) {
86 PPL_ASSERT(size() == new_size);
87 PPL_ASSERT(capacity() == new_capacity);
93 if (new_capacity < capacity()) {
97 PPL_ASSERT(impl.size == new_size);
99 Coefficient*
const new_vec = impl.coeff_allocator.allocate(new_capacity);
101 PPL_ASSERT(impl.vec != 0);
103 memcpy(new_vec, impl.vec,
sizeof(
Coefficient) * impl.size);
105 impl.coeff_allocator.deallocate(impl.vec, impl.capacity);
108 impl.capacity = new_capacity;
111 if (new_capacity > capacity()) {
113 Coefficient*
const new_vec = impl.coeff_allocator.allocate(new_capacity);
116 memcpy(new_vec, impl.vec,
sizeof(
Coefficient) * impl.size);
117 impl.coeff_allocator.deallocate(impl.vec, impl.capacity);
121 impl.capacity = new_capacity;
127 PPL_ASSERT(size() == new_size);
128 PPL_ASSERT(capacity() == new_capacity);
134 for (
iterator i = begin(), i_end = end(); i != i_end; ++i) {
141 PPL_ASSERT(i <= size());
143 if (new_size > capacity()) {
154 for ( ; j < i + n; ++j) {
161 new_row.
impl.
vec[j].~Coefficient();
169 memcpy(&(new_row.
impl.
vec[i + n]), &impl.vec[i],
177 impl.size = new_size;
183 memmove(&impl.vec[n + i], &impl.vec[i],
sizeof(
Coefficient)
187 PPL_ASSERT(target_size == i + n);
190 while (impl.size != target_size) {
194 impl.size = new_size;
202 impl.vec[j].~Coefficient();
214 PPL_ASSERT(new_size <= impl.capacity);
215 PPL_ASSERT(size() <= new_size && new_size <= max_size());
216 while (impl.size != new_size) {
220 PPL_ASSERT(size() == new_size);
226 PPL_ASSERT(new_size <= size());
231 while (impl.size != new_size) {
233 impl.vec[impl.size].~Coefficient();
236 PPL_ASSERT(size() == new_size);
251 impl.capacity = row.
size();
252 impl.vec = impl.coeff_allocator.allocate(impl.capacity);
255 while (impl.size != impl.capacity) {
257 if (itr != itr_end && itr.
index() == impl.size) {
266 PPL_ASSERT(size() == row.
size());
272 if (size() > row.
size()) {
280 if (itr != itr_end && itr.
index() == i) {
281 impl.vec[impl.size] = *itr;
290 if (capacity() >= row.
size()) {
296 if (itr != itr_end && itr.
index() == impl.size) {
305 for ( ; impl.size != row.
size(); ++impl.size) {
307 if (itr != itr_end && itr.
index() == impl.size) {
322 PPL_ASSERT(size() == row.
size());
336 Coefficient_traits::const_reference x_i = x[--i];
337 if (
const int x_i_sign =
sgn(x_i)) {
353 Coefficient_traits::const_reference x_i = x[--i];
381 PPL_ASSERT(first <= last);
382 PPL_ASSERT(last <= size());
390 Coefficient_traits::const_reference coeff1,
391 Coefficient_traits::const_reference coeff2) {
400 Coefficient_traits::const_reference coeff1,
401 Coefficient_traits::const_reference coeff2,
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);
437 Coefficient_traits::const_reference y_i = y[i];
471 Coefficient_traits::const_reference y_i = y[i];
482 s <<
"size " << x_size <<
" ";
494 if (!(s >> str) || str !=
"size") {
498 if (!(s >> new_size)) {
505 if (!(s >> (*
this)[col])) {
534 bool is_broken =
false;
536 if (impl.capacity > max_size()) {
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() <<
"."
546 if (size() > max_size()) {
548 cerr <<
"Dense_Row size exceeds the maximum allowed size:" << endl
550 <<
", should be less than or equal to " << max_size() <<
"." << endl;
555 if (impl.capacity < size()) {
557 cerr <<
"Dense_Row is completely broken: capacity is " << impl.capacity
558 <<
", size is " << size() <<
"." << endl;
563 if (capacity() == 0) {
584 bool is_broken = !OK();
587 if (size() != row_size) {
589 cerr <<
"Dense_Row size mismatch: is " << size()
590 <<
", should be " << row_size <<
"." << endl;
603 if (x_size != y_size) {
dimension_type index() const
Returns the index of the element pointed to by *this.
void swap(CO_Tree &x, CO_Tree &y)
A finite sequence of coefficients.
memory_size_type external_memory_in_bytes() const
Returns a lower bound to the size in bytes of the memory managed by *this.
Dense_Row & operator=(const Dense_Row &y)
Assignment operator.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void normalize()
Normalizes the modulo of coefficients so that they are mutually prime.
dimension_type size() const
Returns the size of the row.
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
Declare a local variable named id, of type Coefficient, and containing an unknown initial value...
std::allocator< Coefficient > coeff_allocator
The allocator used to allocate/deallocate vec.
void add_mul_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
void linear_combine(const Dense_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2)
Dense_Row()
Constructs an empty row.
A finite sparse sequence of coefficients.
The standard C++ namespace.
const iterator & end()
Returns an iterator that points after the last stored element.
void exact_div_assign(Checked_Number< T, Policy > &x, const Checked_Number< T, Policy > &y, const Checked_Number< T, Policy > &z)
void ascii_dump() const
Writes to std::cerr an ASCII representation of *this.
void reset(dimension_type i)
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.
void add_zeroes_and_shift(dimension_type n, dimension_type i)
Adds n zeroes before index i.
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...
#define PPL_OUTPUT_DEFINITIONS_ASCII_ONLY(class_name)
void clear()
Resets all the elements of this row.
Enable_If< Is_Native_Or_Checked< T >::value, bool >::type ascii_load(std::istream &s, T &t)
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
void expand_within_capacity(dimension_type new_size)
Expands the row to size new_size.
void init(const Sparse_Row &row)
void shrink(dimension_type new_size)
Shrinks the row by erasing elements at the end.
bool OK() const
Checks if all the invariants are satisfied.
void neg_assign(GMP_Integer &x)
Coefficient_traits::const_reference Coefficient_zero()
Returns a const reference to a Coefficient with value 0.
The entire library is confined to this namespace.
A const iterator on the tree elements, ordered by key.
iterator lower_bound(dimension_type i)
Lower bound of index i.
iterator begin()
Returns an iterator that points at the first stored element.
void resize(dimension_type sz)
Resizes the row to sz.
void gcd_assign(GMP_Integer &x, const GMP_Integer &y, const GMP_Integer &z)
dimension_type capacity
The capacity of the row.
int sgn(Boundary_Type type, const T &x, const Info &info)
bool operator==(const Box< ITV > &x, const Box< ITV > &y)
size_t memory_size_type
An unsigned integral type for representing memory size in bytes.