PPL  1.2
Sparse_Row_defs.hh
Go to the documentation of this file.
1 /* Sparse_Row class declaration.
2  Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3  Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Sparse_Row_defs_hh
25 #define PPL_Sparse_Row_defs_hh 1
26 
27 #include "Sparse_Row_types.hh"
28 
29 #include "CO_Tree_defs.hh"
30 #include "Coefficient_defs.hh"
31 #include "Dense_Row_types.hh"
32 
33 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
34 
57 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
59 
60 public:
61 
63 
68 
70 
75 
77 
85  explicit Sparse_Row(dimension_type n = 0);
86 
88 
100 
102 
106  Sparse_Row(const Sparse_Row& y, dimension_type capacity);
107 
109 
112  Sparse_Row(const Sparse_Row& y, dimension_type sz, dimension_type capacity);
113 
115 
122  explicit Sparse_Row(const Dense_Row& row);
123 
125 
128  Sparse_Row(const Dense_Row& y, dimension_type sz, dimension_type capacity);
129 
130  Sparse_Row& operator=(const Dense_Row& row);
131 
133 
139  void m_swap(Sparse_Row& x);
140 
142 
145  dimension_type size() const;
146 
148 
154 
156 
164  void resize(dimension_type n);
165 
167 
177 
179 
189  void shrink(dimension_type n);
190 
206 
208 
227 
229 
232  iterator begin();
233 
235 
243  const iterator& end();
244 
246  const_iterator begin() const;
247 
249  const const_iterator& end() const;
250 
252 
255  const_iterator cbegin() const;
256 
258 
266  const const_iterator& cend() const;
267 
269  static dimension_type max_size();
270 
272 
275  void clear();
276 
278 
294 
296 
299  Coefficient_traits::const_reference operator[](dimension_type i) const;
300 
302 
311  Coefficient_traits::const_reference get(dimension_type i) const;
312 
314 
323  iterator find(dimension_type i);
324 
326 
341  iterator find(iterator itr, dimension_type i);
342 
344 
353  const_iterator find(dimension_type i) const;
354 
356 
371  const_iterator find(const_iterator itr, dimension_type i) const;
372 
374 
387  iterator lower_bound(dimension_type i);
388 
390 
409  iterator lower_bound(iterator itr, dimension_type i);
410 
412 
426  const_iterator lower_bound(dimension_type i) const;
427 
429 
448  const_iterator lower_bound(const_iterator itr, dimension_type i) const;
449 
451 
465  iterator insert(dimension_type i, Coefficient_traits::const_reference x);
466 
468 
488  iterator insert(iterator itr, dimension_type i,
489  Coefficient_traits::const_reference x);
490 
492 
503  iterator insert(dimension_type i);
504 
506 
523  iterator insert(iterator itr, dimension_type i);
524 
526 
538 
541 
547  void fast_swap(dimension_type i, iterator itr);
548 
550 
559  void swap_coefficients(iterator i, iterator j);
560 
562 
574  iterator reset(iterator i);
575 
577 
592  iterator reset(iterator first, iterator last);
593 
595 
606  void reset(dimension_type i);
607 
609 
621  void reset_after(dimension_type i);
622 
624 
630  void normalize();
631 
633 
655  template <typename Func1, typename Func2>
656  void combine_needs_first(const Sparse_Row& y,
657  const Func1& f, const Func2& g);
658 
660 
683  template <typename Func1, typename Func2>
684  void combine_needs_second(const Sparse_Row& y,
685  const Func1& g, const Func2& h);
686 
688 
715  template <typename Func1, typename Func2, typename Func3>
716  void combine(const Sparse_Row& y,
717  const Func1& f, const Func2& g, const Func3& h);
718 
721 
744  void linear_combine(const Sparse_Row& y,
745  Coefficient_traits::const_reference coeff1,
746  Coefficient_traits::const_reference coeff2);
747 
750 
754  void linear_combine(const Sparse_Row& y,
755  Coefficient_traits::const_reference c1,
756  Coefficient_traits::const_reference c2,
758 
760 
762 
766  bool ascii_load(std::istream& s);
767 
769 
773 
775 
784 
786 
790 
792 
801 
803  bool OK() const;
804 
806 
812  bool OK(dimension_type capacity) const;
813 
814 private:
817 
819 
823 };
824 
825 
826 namespace Parma_Polyhedra_Library {
827 
828 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
829 
831 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
834 
837 
840 
841 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
842 
844 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
845 bool operator==(const Sparse_Row& x, const Sparse_Row& y);
846 
847 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
848 
850 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
851 bool operator!=(const Sparse_Row& x, const Sparse_Row& y);
852 
853 bool operator==(const Dense_Row& x, const Sparse_Row& y);
854 bool operator!=(const Dense_Row& x, const Sparse_Row& y);
855 
856 bool operator==(const Sparse_Row& x, const Dense_Row& y);
857 bool operator!=(const Sparse_Row& x, const Dense_Row& y);
858 
859 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
860 
863 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
864 void linear_combine(Sparse_Row& x, const Dense_Row& y,
865  Coefficient_traits::const_reference coeff1,
866  Coefficient_traits::const_reference coeff2);
867 
868 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
869 
875 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
876 void linear_combine(Sparse_Row& x, const Dense_Row& y,
877  Coefficient_traits::const_reference c1,
878  Coefficient_traits::const_reference c2,
879  dimension_type start, dimension_type end);
880 
881 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
882 
885 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
886 void linear_combine(Dense_Row& x, const Sparse_Row& y,
887  Coefficient_traits::const_reference coeff1,
888  Coefficient_traits::const_reference coeff2);
889 
890 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
891 
897 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
898 void linear_combine(Dense_Row& x, const Sparse_Row& y,
899  Coefficient_traits::const_reference c1,
900  Coefficient_traits::const_reference c2,
901  dimension_type start, dimension_type end);
902 
903 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
904 
907 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
908 void linear_combine(Sparse_Row& x, const Sparse_Row& y,
909  Coefficient_traits::const_reference coeff1,
910  Coefficient_traits::const_reference coeff2);
911 
912 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
913 
919 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
920 void linear_combine(Sparse_Row& x, const Sparse_Row& y,
921  Coefficient_traits::const_reference c1,
922  Coefficient_traits::const_reference c2,
923  dimension_type start, dimension_type end);
924 
925 } // namespace Parma_Polyhedra_Library
926 
927 #include "Sparse_Row_inlines.hh"
928 #include "Sparse_Row_templates.hh"
929 
930 #endif // !defined(PPL_Sparse_Row_defs_hh)
void normalize()
Normalizes the modulo of coefficients so that they are mutually prime.
Definition: Sparse_Row.cc:210
iterator find(dimension_type i)
Looks for an element with index i.
void combine_needs_first(const Sparse_Row &y, const Func1 &f, const Func2 &g)
Calls g(x[i],y[i]), for each i.
void delete_element_and_shift(dimension_type i)
Deletes the i-th element from the row, shifting the next elements to the left.
bool operator!=(const Box< ITV > &x, const Box< ITV > &y)
Definition: Box_inlines.hh:264
void reset_after(dimension_type i)
Resets to zero the elements with index greater than or equal to i.
Definition: Sparse_Row.cc:193
void swap(CO_Tree &x, CO_Tree &y)
void linear_combine(const Sparse_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2)
Definition: Sparse_Row.cc:370
A finite sequence of coefficients.
size_t dimension_type
An unsigned integral type for representing space dimensions.
void combine_needs_second(const Sparse_Row &y, const Func1 &g, const Func2 &h)
Calls g(x[i],y[i]), for each i.
dimension_type size() const
Returns the size of the row.
void linear_combine(Dense_Row &x, const Dense_Row &y, Coefficient_traits::const_reference coeff1, Coefficient_traits::const_reference coeff2)
void m_swap(Sparse_Row &x)
Swaps *this and x.
void resize(dimension_type n)
Resizes the row to the specified size.
bool ascii_load(std::istream &s)
Loads the row from an ASCII representation generated using ascii_dump().
Definition: Sparse_Row.cc:701
iterator reset(iterator i)
Resets to zero the value pointed to by i.
CO_Tree::iterator iterator
An iterator on the row elements.
A finite sparse sequence of coefficients.
An iterator on the tree elements, ordered by key.
Sparse_Row(dimension_type n=0)
Constructs a row with the specified size.
const iterator & end()
Returns an iterator that points after the last stored element.
#define PPL_OUTPUT_DECLARATIONS
void expand_within_capacity(dimension_type n)
Resizes the row to size n.
Coefficient & operator[](dimension_type i)
Gets a reference to the i-th element.
void clear()
Resets all the elements of this row.
A cache-oblivious binary search tree of pairs.
void shrink(dimension_type n)
Resizes the row to size n.
void fast_swap(dimension_type i, iterator itr)
PPL_COEFFICIENT_TYPE Coefficient
An alias for easily naming the type of PPL coefficients.
memory_size_type total_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
CO_Tree tree
The tree used to store the elements.
iterator insert(dimension_type i, Coefficient_traits::const_reference x)
Equivalent to (*this)[i] = x; find(i), but faster.
The entire library is confined to this namespace.
Definition: version.hh:61
memory_size_type external_memory_in_bytes() const
Returns the size in bytes of the memory managed by *this.
A const iterator on the tree elements, ordered by key.
iterator lower_bound(dimension_type i)
Lower bound of index i.
void swap_coefficients(dimension_type i, dimension_type j)
Swaps the i-th element with the j-th element.
Definition: Sparse_Row.cc:127
dimension_type size_
The size of the row.
dimension_type num_stored_elements() const
Returns the number of elements explicitly stored in the row.
iterator begin()
Returns an iterator that points at the first stored element.
const const_iterator & cend() const
Returns an iterator that points after the last element.
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.
void add_zeroes_and_shift(dimension_type n, dimension_type i)
Adds n zeroes before index i.
static dimension_type max_size()
Returns the size() of the largest possible Sparse_Row.
void combine(const Sparse_Row &y, const Func1 &f, const Func2 &g, const Func3 &h)
Calls g(x[i],y[i]), for each i.
Sparse_Row & operator=(const Dense_Row &row)
Definition: Sparse_Row.cc:118
CO_Tree::const_iterator const_iterator
A const iterator on the row elements.
const_iterator cbegin() const
Returns an iterator that points at the first element.
bool OK() const
Checks the invariant.
Definition: Sparse_Row.cc:742