From: heister Date: Sat, 14 Dec 2013 11:08:01 +0000 (+0000) Subject: add CellID::operator< X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=527fe1caf0a25372a911373b7315d8d185f132c7;p=dealii-svn.git add CellID::operator< git-svn-id: https://svn.dealii.org/trunk@32005 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/grid/cell_id.h b/deal.II/include/deal.II/grid/cell_id.h index 588a7f04af..2d671ea4d3 100644 --- a/deal.II/include/deal.II/grid/cell_id.h +++ b/deal.II/include/deal.II/grid/cell_id.h @@ -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