PPL  0.12.1
Sparse_Matrix.inlines.hh
Go to the documentation of this file.
00001 /* Sparse_Matrix class implementation: inline functions.
00002    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
00003    Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com)
00004 
00005 This file is part of the Parma Polyhedra Library (PPL).
00006 
00007 The PPL is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 The PPL is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software Foundation,
00019 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
00020 
00021 For the most up-to-date information see the Parma Polyhedra Library
00022 site: http://bugseng.com/products/ppl/ . */
00023 
00024 #ifndef PPL_Sparse_Matrix_inlines_hh
00025 #define PPL_Sparse_Matrix_inlines_hh 1
00026 
00027 namespace Parma_Polyhedra_Library {
00028 
00029 inline dimension_type
00030 Sparse_Matrix::max_num_rows() {
00031   return std::vector<Sparse_Row>().max_size();
00032 }
00033 
00034 inline dimension_type
00035 Sparse_Matrix::max_num_columns() {
00036   return Sparse_Row::max_size();
00037 }
00038 
00039 inline void
00040 Sparse_Matrix::m_swap(Sparse_Matrix& x) {
00041   using std::swap;
00042   swap(rows, x.rows);
00043   swap(num_columns_, x.num_columns_);
00044 }
00045 
00046 inline dimension_type
00047 Sparse_Matrix::num_rows() const {
00048   return rows.size();
00049 }
00050 
00051 inline dimension_type
00052 Sparse_Matrix::num_columns() const {
00053   return num_columns_;
00054 }
00055 
00056 inline bool
00057 Sparse_Matrix::has_no_rows() const {
00058   return num_rows() == 0;
00059 }
00060 
00061 inline void
00062 Sparse_Matrix::resize(dimension_type n, Flags row_flags) {
00063   resize(n, n, row_flags);
00064 }
00065 
00066 inline void
00067 Sparse_Matrix::resize_no_copy(dimension_type new_n_rows,
00068                               dimension_type new_n_columns,
00069                               Flags row_flags) {
00070   clear();
00071   resize(new_n_rows, new_n_columns, row_flags);
00072 }
00073 
00074 inline void
00075 Sparse_Matrix::add_zero_rows_and_columns(dimension_type n,
00076                                          dimension_type m,
00077                                          Flags row_flags) {
00078   resize(num_rows() + n, num_columns() + m, row_flags);
00079 }
00080 
00081 inline void
00082 Sparse_Matrix::add_zero_rows(dimension_type n, Flags row_flags) {
00083   resize(num_rows() + n, num_columns(), row_flags);
00084 }
00085 
00086 inline void
00087 Sparse_Matrix::add_row(const Sparse_Row& x) {
00088   Sparse_Row row(x);
00089   add_zero_rows(1, Flags());
00090   // Now x may have been invalidated, if it was a row of this matrix.
00091   rows.back().m_swap(row);
00092   PPL_ASSERT(OK());
00093 }
00094 
00095 inline void
00096 Sparse_Matrix::add_recycled_row(Sparse_Row& x) {
00097   add_zero_rows(1, Flags());
00098   rows.back().m_swap(x);
00099   PPL_ASSERT(OK());
00100 }
00101 
00102 inline void
00103 Sparse_Matrix::remove_trailing_rows(dimension_type n) {
00104   resize(num_rows() - n, num_columns());
00105 }
00106 
00107 inline void
00108 Sparse_Matrix::add_zero_columns(dimension_type n) {
00109   resize(num_rows(), num_columns() + n);
00110 }
00111 
00112 inline void
00113 Sparse_Matrix::remove_trailing_columns(dimension_type n) {
00114   PPL_ASSERT(n <= num_columns());
00115   resize(num_rows(), num_columns() - n);
00116 }
00117 
00118 inline void
00119 Sparse_Matrix::clear() {
00120   resize(0, 0);
00121 }
00122 
00123 inline Sparse_Matrix::iterator
00124 Sparse_Matrix::begin() {
00125   return rows.begin();
00126 }
00127 
00128 inline Sparse_Matrix::iterator
00129 Sparse_Matrix::end() {
00130   return rows.end();
00131 }
00132 
00133 inline Sparse_Matrix::const_iterator
00134 Sparse_Matrix::begin() const {
00135   return rows.begin();
00136 }
00137 
00138 inline Sparse_Matrix::const_iterator
00139 Sparse_Matrix::end() const {
00140   return rows.end();
00141 }
00142 
00143 inline Sparse_Row&
00144 Sparse_Matrix::operator[](dimension_type i) {
00145   PPL_ASSERT(i < rows.size());
00146   return rows[i];
00147 }
00148 
00149 inline const Sparse_Row&
00150 Sparse_Matrix::operator[](dimension_type i) const {
00151   PPL_ASSERT(i < rows.size());
00152   return rows[i];
00153 }
00154 
00155 inline memory_size_type
00156 Sparse_Matrix::total_memory_in_bytes() const {
00157   return sizeof(*this) + external_memory_in_bytes();
00158 }
00159 
00160 inline void
00161 swap(Sparse_Matrix& x, Sparse_Matrix& y) {
00162   x.m_swap(y);
00163 }
00164 
00165 } // namespace Parma_Polyhedra_Library
00166 
00167 #endif // !defined(PPL_Sparse_Matrix_inlines_hh)