MFEM  v3.0
 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.googlecode.com.
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 <cstdlib>
14 #include "sort_pairs.hpp"
15 
16 namespace mfem
17 {
18 
19 template <class A, class B>
20 int ComparePairs (const void *_p, const void *_q)
21 {
22  Pair<A, B> *p, *q;
23 
24  p = (Pair<A, B> *)_p;
25  q = (Pair<A, B> *)_q;
26 
27  if (p -> one < q -> one) return -1;
28  if (q -> one < p -> one) return +1;
29  return 0;
30 }
31 
32 template <class A, class B>
33 void SortPairs (Pair<A, B> *pairs, int size)
34 {
35  if (size > 0)
36  qsort (pairs, size, sizeof(Pair<A, B>), ComparePairs<A, B>);
37 }
38 
39 
40 // Instantiate int-int, double-int pairs, and int-double pairs
41 template int ComparePairs<int, int> (const void *, const void *);
42 template int ComparePairs<double, int> (const void *, const void *);
43 template int ComparePairs<int, double> (const void *, const void *);
44 template void SortPairs<int, int> (Pair<int, int> *, int );
45 template void SortPairs<double, int> (Pair<double, int> *, int );
46 template void SortPairs<int, double> (Pair<int, double> *, int );
47 
48 }
int ComparePairs(const void *_p, const void *_q)
Compare the first element of the pairs.
Definition: sort_pairs.cpp:20
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:22
template int ComparePairs< 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:33
template int ComparePairs< int, double >(const void *, const void *)