]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow sorting of table indices.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 29 Mar 2005 15:38:14 +0000 (15:38 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 29 Mar 2005 15:38:14 +0000 (15:38 +0000)
git-svn-id: https://svn.dealii.org/trunk@10286 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/table.h
deal.II/doc/news/changes.html

index 079f4e249a50ccb5f9f8cd117c5e70a7517b239a..f69558eee8184fe6a5b0f34c0471a670e5678455 100644 (file)
@@ -62,6 +62,14 @@ template <typename T> class Table<6,T>;
                                        * inequality.
                                        */
       bool operator != (const TableIndicesBase<N> &other) const;
+
+                                       /**
+                                        * Sort the indices in ascending
+                                        * order. While this operation is not
+                                        * very useful for Table objects, it is
+                                        * used for the SymmetricTensor class.
+                                        */
+      void sort ();
       
     protected:
                                        /**
@@ -1886,6 +1894,42 @@ TableIndicesBase<N>::operator != (const TableIndicesBase<N> &other) const
 
 
 
+template <>
+inline
+void
+TableIndicesBase<1>::sort ()
+{}
+
+
+
+template <>
+inline
+void
+TableIndicesBase<2>::sort ()
+{
+  if (indices[1] < indices[0])
+    std::swap (indices[0], indices[1]);
+}
+
+
+
+template <>
+inline
+void
+TableIndicesBase<3>::sort ()
+{
+                                   // bubble sort for 3 elements
+  if (indices[1] < indices[0])
+    std::swap (indices[0], indices[1]);
+  if (indices[2] < indices[1])
+    std::swap (indices[1], indices[2]);
+  if (indices[1] < indices[0])
+    std::swap (indices[0], indices[1]);
+}
+
+
+
+
 inline
 TableIndices<1>::TableIndices () 
 {
index f7d9090af543d5a42d2383342b9a680d9352ecda..182038e7ff79fae8aebe0eaca5b30c015a7a2cef 100644 (file)
@@ -151,6 +151,15 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>  
+  <li> <p>
+       New: The new function <code
+       class="member">TableIndicesBase::sort</code> allows to sort the indices
+       in ascending order. This is useful for cases where the order of indices
+       is irrelevant (for example in symmetric tables).
+       <br> 
+       (WB, 2005/03/29)
+       </p>
+
   <li> <p>
        New: There is a new class <code class="class">SymmetricTensor</code>
        that provides storage and operations for symmetric tensors.

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.