[PPL-devel] [GIT] ppl/ppl(sparse_matrices): Sparse_Row, Sparse_Row_Reference: add assign() and assign_if_nonzero() methods.

Marco Poletti poletti.marco at gmail.com
Fri Mar 19 20:22:52 CET 2010


Module: ppl/ppl
Branch: sparse_matrices
Commit: 1654fd3c804e0f72c0e34b00a88673ad5c44e593
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=1654fd3c804e0f72c0e34b00a88673ad5c44e593

Author: Marco Poletti <poletti.marco at gmail.com>
Date:   Fri Mar 19 20:22:55 2010 +0100

Sparse_Row, Sparse_Row_Reference: add assign() and assign_if_nonzero() methods.

---

 src/Sparse_Row.defs.hh    |   18 ++++++++++++++++++
 src/Sparse_Row.inlines.hh |   25 +++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/Sparse_Row.defs.hh b/src/Sparse_Row.defs.hh
index 9b85c68..2dbfd9b 100644
--- a/src/Sparse_Row.defs.hh
+++ b/src/Sparse_Row.defs.hh
@@ -140,6 +140,15 @@ public:
   //! lower_bound(i).
   Coefficient& operator[](const dimension_type i);
 
+  //! After this call, get(i) == x.
+  //! This is slower than <CODE>if (x != 0) find_create(i,x);</CODE> because
+  //! it needs to check whether the element with index i is zero.
+  void assign(dimension_type i, const Coefficient& x);
+
+  //! Equivalent to <CODE>if (x != 0) find_create(i, x);</CODE>, provided
+  //! for convenience. This is faster than assign(i, x).
+  void assign_if_nonzero(dimension_type i, const Coefficient& x);
+
   //! Equivalent to get(), provided for convenience.
   const Coefficient& operator[](const dimension_type i) const;
 
@@ -299,6 +308,15 @@ public:
   //! lower_bound(i).
   Coefficient& operator[](const dimension_type i);
 
+  //! After this call, get(i) == x.
+  //! This is slower than <CODE>if (x != 0) find_create(i,x);</CODE> because
+  //! it needs to check whether the element with index i is zero.
+  void assign(dimension_type i, const Coefficient& x);
+
+  //! Equivalent to <CODE>if (x != 0) find_create(i, x);</CODE>, provided
+  //! for convenience. This is faster than assign(i, x).
+  void assign_if_nonzero(dimension_type i, const Coefficient& x);
+
   //! Equivalent to get(), provided for convenience.
   const Coefficient& operator[](const dimension_type i) const;
 
diff --git a/src/Sparse_Row.inlines.hh b/src/Sparse_Row.inlines.hh
index 5323e04..12adf4d 100644
--- a/src/Sparse_Row.inlines.hh
+++ b/src/Sparse_Row.inlines.hh
@@ -154,6 +154,18 @@ Sparse_Row::operator[](const dimension_type i) {
   return row[i];
 }
 
+inline void
+Sparse_Row::assign(dimension_type i, const Coefficient& x) {
+  PPL_ASSERT(i < size_);
+  row.assign(i,x);
+}
+
+inline void
+Sparse_Row::assign_if_nonzero(dimension_type i, const Coefficient& x) {
+  PPL_ASSERT(i < size_);
+  row.assign_if_nonzero(i,x);
+}
+
 inline const Coefficient&
 Sparse_Row::operator[](const dimension_type i) const {
   return get(i);
@@ -446,6 +458,19 @@ Sparse_Row_Reference::operator[](const dimension_type i) {
   return row[i];
 }
 
+inline void
+Sparse_Row_Reference::assign(dimension_type i, const Coefficient& x) {
+  PPL_ASSERT(i < size_);
+  row.assign(i,x);
+}
+
+inline void
+Sparse_Row_Reference::assign_if_nonzero(dimension_type i,
+                                        const Coefficient& x) {
+  PPL_ASSERT(i < size_);
+  row.assign_if_nonzero(i,x);
+}
+
 inline const Coefficient&
 Sparse_Row_Reference::operator[](const dimension_type i) const {
   return get(i);




More information about the PPL-devel mailing list