// Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced // at the Lawrence Livermore National Laboratory. All Rights reserved. See files // LICENSE and NOTICE for details. LLNL-CODE-806117. // // This file is part of the MFEM library. For more information and source code // availability visit https://mfem.org. // // MFEM is free software; you can redistribute it and/or modify it under the // terms of the BSD-3 license. We welcome feedback and contributions, see file // CONTRIBUTING.md for details. #ifndef MFEM_SORT_PAIRS #define MFEM_SORT_PAIRS #include "../config/config.hpp" #include namespace mfem { /// A pair of objects template class Pair { public: A one; B two; Pair() = default; Pair(const A &one, const B &two) : one(one), two(two) {} }; /// @brief Comparison operator for class Pair, based on the first element only. template bool operator<(const Pair &p, const Pair &q) { return (p.one < q.one); } /// @brief Equality operator for class Pair, based on the first element only. template bool operator==(const Pair &p, const Pair &q) { return (p.one == q.one); } /// Sort an array of Pairs with respect to the first element template void SortPairs (Pair *pairs, int size) { std::sort(pairs, pairs + size); } /// A triple of objects template class Triple { public: A one; B two; C three; Triple() = default; Triple(const A &one, const B &two, const C &three) : one(one), two(two), three(three) { } }; /// @brief Lexicographic comparison operator for class Triple. template bool operator<(const Triple &p, const Triple &q) { return (p.one < q.one || (!(q.one < p.one) && (p.two < q.two || (!(q.two < p.two) && p.three < q.three)))); } /// @brief Lexicographic sort for arrays of class Triple. template void SortTriple (Triple *triples, int size) { std::sort(triples, triples + size); } } #endif