[PPL-devel] [GIT] ppl/ppl(sparse_matrices): Improved documentation for {Dense, Sparse}_Row::add_zeroes_and_shift().

Enea Zaffanella zaffanella at cs.unipr.it
Sat Mar 24 09:27:08 CET 2012


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

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Sat Mar 24 09:21:26 2012 +0100

Improved documentation for {Dense,Sparse}_Row::add_zeroes_and_shift().
Prefer using `coeff_allocator' rather than operator new.

---

 src/Dense_Row.cc       |   11 +++--------
 src/Dense_Row.defs.hh  |    8 ++++----
 src/Sparse_Row.defs.hh |   18 +++++++++---------
 3 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/Dense_Row.cc b/src/Dense_Row.cc
index 1f5d618..3884c1e 100644
--- a/src/Dense_Row.cc
+++ b/src/Dense_Row.cc
@@ -136,13 +136,9 @@ PPL::Dense_Row::add_zeroes_and_shift(dimension_type n, dimension_type i) {
   const dimension_type new_size = size() + n;
   if (new_size > capacity()) {
     Dense_Row new_row;
-    
     const dimension_type new_capacity = compute_capacity(new_size, max_size());
-    
     // This may throw.
-    new_row.impl.vec
-      = static_cast<Coefficient*>(operator new(sizeof(Coefficient)
-                                               * new_capacity));
+    new_row.impl.vec = new_row.impl.coeff_allocator.allocate(new_capacity);
     new_row.impl.capacity = new_capacity;
 
     dimension_type j = i;
@@ -157,7 +153,6 @@ PPL::Dense_Row::add_zeroes_and_shift(dimension_type n, dimension_type i) {
         --j;
         new_row.impl.vec[j].~Coefficient();
       }
-      
       // The new_row's destructor will de-allocate the memory.
       throw;
     }
@@ -170,7 +165,7 @@ PPL::Dense_Row::add_zeroes_and_shift(dimension_type n, dimension_type i) {
     using std::swap;
     swap(impl.vec, new_row.impl.vec);
     swap(impl.capacity, new_row.impl.capacity);
-    
+
     // *this now owns all coefficients, including the newly-added zeroes.
     impl.size = new_size;
 
@@ -201,7 +196,7 @@ PPL::Dense_Row::add_zeroes_and_shift(dimension_type n, dimension_type i) {
       throw;
     }
   }
-  
+
   PPL_ASSERT(OK());
 }
 
diff --git a/src/Dense_Row.defs.hh b/src/Dense_Row.defs.hh
index 614e5b3..2627978 100644
--- a/src/Dense_Row.defs.hh
+++ b/src/Dense_Row.defs.hh
@@ -106,11 +106,11 @@ public:
 
   //! Resizes the row to \p sz, with capacity \p capacity.
   void resize(dimension_type sz, dimension_type capacity);
-  
+
   //! Resets all the elements of this row.
   void clear();
 
-  //! Adds \p n zeroes before index i.
+  //! Adds \p n zeroes before index \p i.
   /*!
     \param n
     The number of zeroes that will be added to the row.
@@ -118,8 +118,8 @@ public:
     \param i
     The index of the element before which the zeroes will be added.
 
-    Existing elements with index greater than or equal to i are shifted to
-    the right by n positions. The size is increased by \p n.
+    Existing elements with index greater than or equal to \p i are shifted
+    to the right by \p n positions. The size is increased by \p n.
 
     Existing iterators are invalidated.
   */
diff --git a/src/Sparse_Row.defs.hh b/src/Sparse_Row.defs.hh
index 6e963e3..17ecf7a 100644
--- a/src/Sparse_Row.defs.hh
+++ b/src/Sparse_Row.defs.hh
@@ -206,7 +206,7 @@ public:
   */
   void delete_element_and_shift(dimension_type i);
 
-  //! Adds \p n zeroes before index i.
+  //! Adds \p n zeroes before index \p i.
   /*!
     \param n
     The number of non-stored zeroes that will be added to the row.
@@ -214,16 +214,16 @@ public:
     \param i
     The index of the element before which the zeroes will be added.
 
-    Existing elements with index greater than or equal to i are shifted to
-    the right by n positions. The size is increased by \p n.
+    Existing elements with index greater than or equal to \p i are shifted to
+    the right by \p n positions. The size is increased by \p n.
 
-    Existing iterators are not invalidated, but are shifted to the right by n
-    if they pointed at or after index i (i.e. they point to the same,
-    possibly shifted, values as before).
+    Existing iterators are not invalidated, but are shifted to the right
+    by \p n if they pointed at or after index \p i (i.e., they point to
+    the same, possibly shifted, values as before).
 
-    This method takes \f$O(k+\log n)\f$ expected time, where k is the number
-    of elements with index greater than or equal to i and n the number of
-    stored elements (not the parameter to this method).
+    This method takes \f$O(k + \log m)\f$ expected time, where \f$k\f$ is
+    the number of elements with index greater than or equal to \p i and
+    \f$m\f$ the number of stored elements.
   */
   void add_zeroes_and_shift(dimension_type n, dimension_type i);
 




More information about the PPL-devel mailing list