[PPL-devel] [GIT] ppl/ppl(sparse_matrices): Unlimited_Sparse_Row: 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: 289da761a94ccf596815acf3e7bd489421415321
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=289da761a94ccf596815acf3e7bd489421415321

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

Unlimited_Sparse_Row: add assign() and assign_if_nonzero() methods.

---

 src/Unlimited_Sparse_Row.defs.hh    |    9 +++++++++
 src/Unlimited_Sparse_Row.inlines.hh |   14 ++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/Unlimited_Sparse_Row.defs.hh b/src/Unlimited_Sparse_Row.defs.hh
index d263411..5d7f49d 100644
--- a/src/Unlimited_Sparse_Row.defs.hh
+++ b/src/Unlimited_Sparse_Row.defs.hh
@@ -243,6 +243,15 @@ public:
   */
   void normalize();
 
+  //! 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);
+
   //! For read-only access it's better to use get(), that avoids allocating
   //! space for zeroes. Both methods are O(n).
   //! If i was not previously stored, or reset(i) was called, this operation
diff --git a/src/Unlimited_Sparse_Row.inlines.hh b/src/Unlimited_Sparse_Row.inlines.hh
index 08a09b1..b860435 100644
--- a/src/Unlimited_Sparse_Row.inlines.hh
+++ b/src/Unlimited_Sparse_Row.inlines.hh
@@ -123,6 +123,20 @@ Unlimited_Sparse_Row::reset_after(dimension_type i) {
   PPL_ASSERT(OK());
 }
 
+inline void
+Unlimited_Sparse_Row::assign(dimension_type i, const Coefficient& x) {
+  dangerous_iterator itr = lower_bound_dangerous(i);
+  if (x != 0 || (itr != end_dangerous() && (*itr).first == i))
+    find_create(i, x, itr);
+}
+
+inline void
+Unlimited_Sparse_Row
+::assign_if_nonzero(dimension_type i, const Coefficient& x) {
+  if (x != 0)
+    find_create(i, x);
+}
+
 inline Coefficient&
 Unlimited_Sparse_Row::operator[](const dimension_type i) {
   dangerous_iterator itr = lower_bound_dangerous(i);




More information about the PPL-devel mailing list