MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
sort_pairs.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_SORT_PAIRS
13#define MFEM_SORT_PAIRS
14
15#include "../config/config.hpp"
16#include <algorithm>
17
18namespace mfem
19{
20
21/// A pair of objects
22template <class A, class B>
23class Pair
24{
25public:
26 A one;
27 B two;
28
29 Pair() = default;
30
31 Pair(const A &one, const B &two) : one(one), two(two) {}
32};
33
34/// @brief Comparison operator for class Pair, based on the first element only.
35template <class A, class B>
36bool operator<(const Pair<A,B> &p, const Pair<A,B> &q)
37{
38 return (p.one < q.one);
39}
40
41/// @brief Equality operator for class Pair, based on the first element only.
42template <class A, class B>
43bool operator==(const Pair<A,B> &p, const Pair<A,B> &q)
44{
45 return (p.one == q.one);
46}
47
48/// Sort an array of Pairs with respect to the first element
49template <class A, class B>
50void SortPairs (Pair<A, B> *pairs, int size)
51{
52 std::sort(pairs, pairs + size);
53}
54
55/// A triple of objects
56template <class A, class B, class C>
57class Triple
58{
59public:
60 A one;
61 B two;
63
64 Triple() = default;
65
66 Triple(const A &one, const B &two, const C &three)
67 : one(one), two(two), three(three) { }
68};
69
70/// @brief Lexicographic comparison operator for class Triple.
71template <class A, class B, class C>
72bool operator<(const Triple<A,B,C> &p, const Triple<A,B,C> &q)
73{
74 return (p.one < q.one ||
75 (!(q.one < p.one) &&
76 (p.two < q.two || (!(q.two < p.two) && p.three < q.three))));
77}
78
79/// @brief Lexicographic sort for arrays of class Triple.
80template <class A, class B, class C>
81void SortTriple (Triple<A, B, C> *triples, int size)
82{
83 std::sort(triples, triples + size);
84}
85
86}
87
88#endif
A pair of objects.
Pair()=default
Pair(const A &one, const B &two)
A triple of objects.
Triple()=default
Triple(const A &one, const B &two, const C &three)
bool operator==(const Array< T > &LHS, const Array< T > &RHS)
Definition array.hpp:342
void SortPairs(Pair< A, B > *pairs, int size)
Sort an array of Pairs with respect to the first element.
void SortTriple(Triple< A, B, C > *triples, int size)
Lexicographic sort for arrays of class Triple.
bool operator<(const Pair< A, B > &p, const Pair< A, B > &q)
Comparison operator for class Pair, based on the first element only.
real_t p(const Vector &x, real_t t)