MFEM  v3.4
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sort_pairs.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_SORT_PAIRS
13 #define MFEM_SORT_PAIRS
14 
15 #include "../config/config.hpp"
16 #include <algorithm>
17 
18 namespace mfem
19 {
20 
21 /// A pair of objects
22 template <class A, class B>
23 class Pair
24 {
25 public:
26  A one;
27  B two;
28 
29  Pair(const A &one, const B &two) : one(one), two(two) {}
30 };
31 
32 /// @brief Comparison operator for class Pair, based on the first element only.
33 template <class A, class B>
34 bool operator<(const Pair<A,B> &p, const Pair<A,B> &q)
35 {
36  return (p.one < q.one);
37 }
38 
39 /// @brief Equality operator for class Pair, based on the first element only.
40 template <class A, class B>
41 bool operator==(const Pair<A,B> &p, const Pair<A,B> &q)
42 {
43  return (p.one == q.one);
44 }
45 
46 /// Sort an array of Pairs with respect to the first element
47 template <class A, class B>
48 void SortPairs (Pair<A, B> *pairs, int size)
49 {
50  std::sort(pairs, pairs + size);
51 }
52 
53 
54 template <class A, class B, class C>
55 class Triple
56 {
57 public:
58  A one;
59  B two;
60  C three;
61 };
62 
63 /// @brief Lexicographic comparison operator for class Triple.
64 template <class A, class B, class C>
65 bool operator<(const Triple<A,B,C> &p, const Triple<A,B,C> &q)
66 {
67  return (p.one < q.one ||
68  (!(q.one < p.one) &&
69  (p.two < q.two || (!(q.two < p.two) && p.three < q.three))));
70 }
71 
72 /// @brief Lexicographic sort for arrays of class Triple.
73 template <class A, class B, class C>
74 void SortTriple (Triple<A, B, C> *triples, int size)
75 {
76  std::sort(triples, triples + size);
77 }
78 
79 }
80 
81 #endif
Pair(const A &one, const B &two)
Definition: sort_pairs.hpp:29
A pair of objects.
Definition: sort_pairs.hpp:23
bool operator==(const Array< T > &LHS, const Array< T > &RHS)
Definition: array.hpp:273
void SortTriple(Triple< A, B, C > *triples, int size)
Lexicographic sort for arrays of class Triple.
Definition: sort_pairs.hpp:74
void SortPairs(Pair< A, B > *pairs, int size)
Sort an array of Pairs with respect to the first element.
Definition: sort_pairs.hpp:48