MFEM  v3.2
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 
22 template <class A, class B>
23 class Pair
24 {
25 public:
26  A one;
27  B two;
28 };
29 
31 template <class A, class B>
32 bool operator<(const Pair<A,B> &p, const Pair<A,B> &q)
33 {
34  return (p.one < q.one);
35 }
36 
38 template <class A, class B>
39 void SortPairs (Pair<A, B> *pairs, int size)
40 {
41  std::sort(pairs, pairs + size);
42 }
43 
44 
45 template <class A, class B, class C>
46 class Triple
47 {
48 public:
49  A one;
50  B two;
51  C three;
52 };
53 
55 template <class A, class B, class C>
56 bool operator<(const Triple<A,B,C> &p, const Triple<A,B,C> &q)
57 {
58  return (p.one < q.one ||
59  (!(q.one < p.one) &&
60  (p.two < q.two || (!(q.two < p.two) && p.three < q.three))));
61 }
62 
64 template <class A, class B, class C>
65 void SortTriple (Triple<A, B, C> *triples, int size)
66 {
67  std::sort(triples, triples + size);
68 }
69 
70 }
71 
72 #endif
A pair of objects.
Definition: sort_pairs.hpp:23
void SortTriple(Triple< A, B, C > *triples, int size)
Lexicographic sort for arrays of class Triple.
Definition: sort_pairs.hpp:65
void SortPairs(Pair< A, B > *pairs, int size)
Sort an array of Pairs with respect to the first element.
Definition: sort_pairs.hpp:39