]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Make sure begin() doesn't return an iterator into an empty row.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 30 Mar 2004 14:33:04 +0000 (14:33 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 30 Mar 2004 14:33:04 +0000 (14:33 +0000)
git-svn-id: https://svn.dealii.org/trunk@8915 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix.h

index 329fbc98ed29a68829bf8474d76d59d9ed8380de..8e85d868844bca07684468b1a352c08b9f72dd07 100644 (file)
@@ -2020,7 +2020,16 @@ inline
 typename SparseMatrix<number>::const_iterator
 SparseMatrix<number>::begin () const
 {
-  return const_iterator(this, 0, 0);
+                                   // search for the first line with a nonzero
+                                   // number of entries
+  for (unsigned int r=0; r<n(); ++r)
+    if (cols->row_length(r) > 0)
+      return const_iterator(this, r, 0);
+
+                                   // alright, this matrix is completely
+                                   // empty. that's strange but ok. simply
+                                   // return the end() iterator
+  return end();
 }
 
 
@@ -2038,7 +2047,16 @@ inline
 typename SparseMatrix<number>::iterator
 SparseMatrix<number>::begin ()
 {
-  return iterator(this, 0, 0);
+                                   // search for the first line with a nonzero
+                                   // number of entries
+  for (unsigned int r=0; r<n(); ++r)
+    if (cols->row_length(r) > 0)
+      return iterator(this, r, 0);
+
+                                   // alright, this matrix is completely
+                                   // empty. that's strange but ok. simply
+                                   // return the end() iterator
+  return end();
 }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.