MFEM v2.0
sort_pairs.cpp
Go to the documentation of this file.
00001 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
00002 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
00003 // reserved. See file COPYRIGHT for details.
00004 //
00005 // This file is part of the MFEM library. For more information and source code
00006 // availability see http://mfem.googlecode.com.
00007 //
00008 // MFEM is free software; you can redistribute it and/or modify it under the
00009 // terms of the GNU Lesser General Public License (as published by the Free
00010 // Software Foundation) version 2.1 dated February 1999.
00011 
00012 
00013 #include <stdlib.h>
00014 #include "sort_pairs.hpp"
00015 
00016 
00017 template <class A, class B>
00018 int ComparePairs (const void *_p, const void *_q)
00019 {
00020    Pair<A, B> *p, *q;
00021 
00022    p = (Pair<A, B> *)_p;
00023    q = (Pair<A, B> *)_q;
00024 
00025    if (p -> one < q -> one)  return -1;
00026    if (q -> one < p -> one)  return +1;
00027    return 0;
00028 }
00029 
00030 template <class A, class B>
00031 void SortPairs (Pair<A, B> *pairs, int size)
00032 {
00033    if (size > 0)
00034       qsort (pairs, size, sizeof(Pair<A, B>), ComparePairs<A, B>);
00035 }
00036 
00037 
00038 // Instantiate int-int and double-int pairs
00039 template int ComparePairs<int, int> (const void *, const void *);
00040 template int ComparePairs<double, int> (const void *, const void *);
00041 template void SortPairs<int, int> (Pair<int, int> *, int );
00042 template void SortPairs<double, int> (Pair<double, int> *, int );
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines