PPL  0.12.1
Sparse_Row.inlines.hh
Go to the documentation of this file.
00001 /* Sparse_Row 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_Row_inlines_hh
00025 #define PPL_Sparse_Row_inlines_hh 1
00026 
00027 #include <algorithm>
00028 
00029 namespace Parma_Polyhedra_Library {
00030 
00031 inline
00032 Sparse_Row::Sparse_Row(Flags flags)
00033   : size_(0), flags_(flags) {
00034   PPL_ASSERT(OK());
00035 }
00036 
00037 inline
00038 Sparse_Row::Sparse_Row(dimension_type n, Flags flags)
00039   : size_(n), flags_(flags) {
00040   PPL_ASSERT(OK());
00041 }
00042 
00043 inline
00044 Sparse_Row::Sparse_Row(dimension_type n, dimension_type capacity, Flags flags)
00045   : size_(n), flags_(flags) {
00046   (void)capacity;
00047   PPL_ASSERT(OK());
00048 }
00049 
00050 inline
00051 Sparse_Row::Sparse_Row(const Sparse_Row& y, dimension_type capacity)
00052   : tree(y.tree), size_(y.size_), flags_(y.flags_) {
00053   (void)capacity;
00054 }
00055 
00056 inline
00057 Sparse_Row::Sparse_Row(const Sparse_Row& y, dimension_type sz,
00058                        dimension_type capacity)
00059   : tree(y.tree), size_(sz), flags_(y.flags_) {
00060   PPL_ASSERT(y.size() <= sz);
00061   (void)capacity;
00062 }
00063 
00064 inline void
00065 Sparse_Row::m_swap(Sparse_Row& x) {
00066   using std::swap;
00067   tree.m_swap(x.tree);
00068   swap(size_, x.size_);
00069   swap(flags_, x.flags_);
00070   PPL_ASSERT(OK());
00071   PPL_ASSERT(x.OK());
00072 }
00073 
00074 inline dimension_type
00075 Sparse_Row::size() const {
00076   return size_;
00077 }
00078 
00079 inline void
00080 Sparse_Row::resize(dimension_type n) {
00081   if (n < size_)
00082     reset_after(n);
00083   size_ = n;
00084   PPL_ASSERT(OK());
00085 }
00086 
00087 inline void
00088 Sparse_Row::shrink(dimension_type n) {
00089   PPL_ASSERT(size() >= n);
00090   resize(n);
00091 }
00092 
00093 inline void
00094 Sparse_Row::expand_within_capacity(dimension_type n) {
00095   PPL_ASSERT(size() <= n);
00096   resize(n);
00097 }
00098 
00099 inline void
00100 Sparse_Row::delete_element_and_shift(dimension_type i) {
00101   PPL_ASSERT(i < size_);
00102   tree.erase_element_and_shift_left(i);
00103   --size_;
00104   PPL_ASSERT(OK());
00105 }
00106 
00107 inline void
00108 Sparse_Row::add_zeroes_and_shift(dimension_type n, dimension_type i) {
00109   PPL_ASSERT(i <= size_);
00110   tree.increase_keys_from(i, n);
00111   size_ += n;
00112   PPL_ASSERT(OK());
00113 }
00114 
00115 inline Sparse_Row::iterator
00116 Sparse_Row::begin() {
00117   return tree.begin();
00118 }
00119 
00120 inline const Sparse_Row::iterator&
00121 Sparse_Row::end() {
00122   return tree.end();
00123 }
00124 
00125 inline Sparse_Row::const_iterator
00126 Sparse_Row::begin() const {
00127   return tree.cbegin();
00128 }
00129 
00130 inline const Sparse_Row::const_iterator&
00131 Sparse_Row::end() const {
00132   return tree.cend();
00133 }
00134 
00135 inline Sparse_Row::const_iterator
00136 Sparse_Row::cbegin() const {
00137   return tree.cbegin();
00138 }
00139 
00140 inline const Sparse_Row::const_iterator&
00141 Sparse_Row::cend() const {
00142   return tree.cend();
00143 }
00144 
00145 inline dimension_type
00146 Sparse_Row::max_size() {
00147   return CO_Tree::max_size();
00148 }
00149 
00150 inline const Sparse_Row::Flags
00151 Sparse_Row::flags() const {
00152   return flags_;
00153 }
00154 
00155 inline void
00156 Sparse_Row::set_flags(Sparse_Row::Flags f) {
00157   flags_ = f;
00158 }
00159 
00160 inline void
00161 Sparse_Row::clear() {
00162   tree.clear();
00163 }
00164 
00165 inline Coefficient&
00166 Sparse_Row::operator[](dimension_type i) {
00167   PPL_ASSERT(i < size_);
00168   iterator itr = insert(i);
00169   return *itr;
00170 }
00171 
00172 inline Coefficient_traits::const_reference
00173 Sparse_Row::operator[](dimension_type i) const {
00174   return get(i);
00175 }
00176 
00177 inline Coefficient_traits::const_reference
00178 Sparse_Row::get(dimension_type i) const {
00179   PPL_ASSERT(i < size_);
00180   if (tree.empty())
00181     return Coefficient_zero();
00182   const_iterator itr = find(i);
00183   if (itr != end())
00184     return *itr;
00185   else
00186     return Coefficient_zero();
00187 }
00188 
00189 inline Sparse_Row::iterator
00190 Sparse_Row::find(dimension_type i) {
00191   PPL_ASSERT(i < size());
00192 
00193   iterator itr = tree.bisect(i);
00194 
00195   if (itr != end() && itr.index() == i)
00196     return itr;
00197 
00198   return end();
00199 }
00200 
00201 inline Sparse_Row::iterator
00202 Sparse_Row::find(iterator hint, dimension_type i) {
00203   PPL_ASSERT(i < size());
00204 
00205   iterator itr = tree.bisect_near(hint, i);
00206 
00207   if (itr != end() && itr.index() == i)
00208     return itr;
00209 
00210   return end();
00211 }
00212 
00213 inline Sparse_Row::const_iterator
00214 Sparse_Row::find(dimension_type i) const {
00215   PPL_ASSERT(i < size());
00216 
00217   const_iterator itr = tree.bisect(i);
00218 
00219   if (itr != end() && itr.index() == i)
00220     return itr;
00221 
00222   return end();
00223 }
00224 
00225 inline Sparse_Row::const_iterator
00226 Sparse_Row::find(const_iterator hint, dimension_type i) const {
00227   PPL_ASSERT(i < size());
00228 
00229   const_iterator itr = tree.bisect_near(hint, i);
00230 
00231   if (itr != end() && itr.index() == i)
00232     return itr;
00233 
00234   return end();
00235 }
00236 
00237 inline Sparse_Row::iterator
00238 Sparse_Row::lower_bound(dimension_type i) {
00239   PPL_ASSERT(i <= size());
00240 
00241   iterator itr = tree.bisect(i);
00242 
00243   if (itr == end())
00244     return end();
00245 
00246   if (itr.index() < i)
00247     ++itr;
00248 
00249   PPL_ASSERT(itr == end() || itr.index() >= i);
00250 
00251   return itr;
00252 }
00253 
00254 inline Sparse_Row::iterator
00255 Sparse_Row::lower_bound(iterator hint, dimension_type i) {
00256   PPL_ASSERT(i <= size());
00257 
00258   iterator itr = tree.bisect_near(hint, i);
00259 
00260   if (itr == end())
00261     return end();
00262 
00263   if (itr.index() < i)
00264     ++itr;
00265 
00266   PPL_ASSERT(itr == end() || itr.index() >= i);
00267 
00268   return itr;
00269 }
00270 
00271 inline Sparse_Row::const_iterator
00272 Sparse_Row::lower_bound(dimension_type i) const {
00273   PPL_ASSERT(i <= size());
00274 
00275   const_iterator itr = tree.bisect(i);
00276 
00277   if (itr == end())
00278     return end();
00279 
00280   if (itr.index() < i)
00281     ++itr;
00282 
00283   PPL_ASSERT(itr == end() || itr.index() >= i);
00284 
00285   return itr;
00286 }
00287 
00288 inline Sparse_Row::const_iterator
00289 Sparse_Row::lower_bound(const_iterator hint, dimension_type i) const {
00290   PPL_ASSERT(i <= size());
00291 
00292   const_iterator itr = tree.bisect_near(hint, i);
00293 
00294   if (itr == end())
00295     return end();
00296 
00297   if (itr.index() < i)
00298     ++itr;
00299 
00300   PPL_ASSERT(itr == end() || itr.index() >= i);
00301 
00302   return itr;
00303 }
00304 
00305 inline Sparse_Row::iterator
00306 Sparse_Row::insert(dimension_type i, Coefficient_traits::const_reference x) {
00307   PPL_ASSERT(i < size_);
00308   return tree.insert(i, x);
00309 }
00310 
00311 inline Sparse_Row::iterator
00312 Sparse_Row::insert(iterator itr, dimension_type i,
00313                    Coefficient_traits::const_reference x) {
00314   PPL_ASSERT(i < size_);
00315   return tree.insert(itr, i, x);
00316 }
00317 
00318 inline Sparse_Row::iterator
00319 Sparse_Row::insert(dimension_type i) {
00320   PPL_ASSERT(i < size_);
00321   return tree.insert(i);
00322 }
00323 
00324 inline Sparse_Row::iterator
00325 Sparse_Row::insert(iterator itr, dimension_type i) {
00326   PPL_ASSERT(i < size_);
00327   return tree.insert(itr, i);
00328 }
00329 
00330 inline void
00331 Sparse_Row::m_swap(iterator i, iterator j) {
00332   PPL_ASSERT(i != end());
00333   PPL_ASSERT(j != end());
00334   using std::swap;
00335   swap(*i, *j);
00336   PPL_ASSERT(OK());
00337 }
00338 
00339 inline Sparse_Row::iterator
00340 Sparse_Row::reset(iterator i) {
00341   iterator res = tree.erase(i);
00342   PPL_ASSERT(OK());
00343   return res;
00344 }
00345 
00346 inline void
00347 Sparse_Row::reset(dimension_type i) {
00348   PPL_ASSERT(i < size());
00349 
00350   tree.erase(i);
00351   PPL_ASSERT(OK());
00352 }
00353 
00354 inline memory_size_type
00355 Sparse_Row::external_memory_in_bytes() const {
00356   return tree.external_memory_in_bytes();
00357 }
00358 
00359 inline memory_size_type
00360 Sparse_Row::external_memory_in_bytes(dimension_type /* capacity */) const {
00361   return external_memory_in_bytes();
00362 }
00363 
00364 inline memory_size_type
00365 Sparse_Row::total_memory_in_bytes() const {
00366   return external_memory_in_bytes() + sizeof(*this);
00367 }
00368 
00369 inline memory_size_type
00370 Sparse_Row::total_memory_in_bytes(dimension_type /* capacity */) const {
00371   return total_memory_in_bytes();
00372 }
00373 
00374 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
00375 
00376 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
00377 inline void
00378 swap(Sparse_Row& x, Sparse_Row& y) {
00379   x.m_swap(y);
00380 }
00381 
00382 } // namespace Parma_Polyhedra_Library
00383 
00384 #endif // !defined(PPL_Sparse_Row_inlines_hh)