MFEM  v3.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sort_pairs.cpp
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 
13 #include "sort_pairs.hpp"
14 
15 #ifdef MFEM_USE_MPI
16 #include <HYPRE_utilities.h>
17 #endif
18 
19 namespace mfem
20 {
21 
22 template <class A, class B>
23 int ComparePairs (const void *_p, const void *_q)
24 {
25  Pair<A, B> *p, *q;
26 
27  p = (Pair<A, B> *)_p;
28  q = (Pair<A, B> *)_q;
29 
30  if (p -> one < q -> one) { return -1; }
31  if (q -> one < p -> one) { return +1; }
32  return 0;
33 }
34 
35 template <class A, class B>
36 void SortPairs (Pair<A, B> *pairs, int size)
37 {
38  if (size > 0)
39  {
40  qsort (pairs, size, sizeof(Pair<A, B>), ComparePairs<A, B>);
41  }
42 }
43 
44 
45 // Instantiate int-int, double-int, int-double pairs
46 template int ComparePairs<int, int> (const void *, const void *);
47 template int ComparePairs<double, int> (const void *, const void *);
48 template int ComparePairs<int, double> (const void *, const void *);
49 template void SortPairs<int, int> (Pair<int, int> *, int );
50 template void SortPairs<double, int> (Pair<double, int> *, int );
51 template void SortPairs<int, double> (Pair<int, double> *, int );
52 #ifdef HYPRE_BIGINT
53 template int ComparePairs<HYPRE_Int, int> (const void *, const void *);
54 template void SortPairs<HYPRE_Int, int> (Pair<HYPRE_Int, int> *, int );
55 #endif
56 
57 }
int ComparePairs(const void *_p, const void *_q)
Compare the first element of the pairs.
Definition: sort_pairs.cpp:23
template void SortPairs< HYPRE_Int, int >(Pair< HYPRE_Int, int > *, int)
template void SortPairs< double, int >(Pair< double, int > *, int)
template void SortPairs< int, double >(Pair< int, double > *, int)
template void SortPairs< int, int >(Pair< int, int > *, int)
template int ComparePairs< double, int >(const void *, const void *)
A pair of objects.
Definition: sort_pairs.hpp:23
template int ComparePairs< int, int >(const void *, const void *)
template int ComparePairs< HYPRE_Int, int >(const void *, const void *)
void SortPairs(Pair< A, B > *pairs, int size)
Sort with respect to the first element.
Definition: sort_pairs.cpp:36
template int ComparePairs< int, double >(const void *, const void *)