]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
add CellID::operator<
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 14 Dec 2013 11:08:01 +0000 (11:08 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 14 Dec 2013 11:08:01 +0000 (11:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@32005 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/grid/cell_id.h

index 588a7f04affb20e70ca5196708dc4fb0c597c6c5..2d671ea4d3dbab1927c8a4707d1308db92b579fb 100644 (file)
@@ -64,6 +64,10 @@ public:
    */
   bool operator!= (const CellId &other) const;
 
+  /**
+   * compare two CellIds
+   */
+  bool operator<(const CellId &other) const;
 
   friend std::istream &operator>> (std::istream &is, CellId &cid);
   friend std::ostream &operator<< (std::ostream &os, const CellId &cid);
@@ -120,15 +124,35 @@ CellId::operator== (const CellId &other) const
   return id == other.id;
 }
 
-/**
- *
- */
 inline bool
 CellId::operator!= (const CellId &other) const
 {
   return !(*this == other);
 }
 
+inline
+bool CellId::operator<(const CellId &other) const
+{
+  if (this->coarse_cell_id != other.coarse_cell_id)
+    return this->coarse_cell_id < other.coarse_cell_id;
+
+  unsigned int idx = 0;
+  while (idx < id.size())
+    {
+      if (idx>=other.id.size())
+        return false;
+
+      if (id[idx] != other.id[idx])
+        return id[idx] < other.id[idx];
+
+      ++idx;
+    }
+
+  if (id.size() == other.id.size())
+    return false;
+  return true; // other.id is longer
+}
+
 DEAL_II_NAMESPACE_CLOSE
 
 #endif

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.