Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_Sort.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Zoltan2: A package of combinatorial algorithms for scientific computing
4
//
5
// Copyright 2012 NTESS and the Zoltan2 contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef _ZOLTAN2_SORT_HPP_
11
#define _ZOLTAN2_SORT_HPP_
12
13
#include <Teuchos_Array.hpp>
14
#include <algorithm>
15
16
21
22
// TODO: This is a generic utility class; should move this source file.
23
// We could perhaps use Sort2 from Tpetra, but that uses a custom sort not std::sort
24
25
namespace
Zoltan2
{
26
27
namespace
Details
{
28
29
// These helper functions can't be class members, so put in Details namespace.
30
template
<
class
KeyType,
class
ValueType>
31
bool
SortInc
(
const
std::pair<KeyType, ValueType>& a,
const
std::pair<KeyType, ValueType>& b)
32
{
33
return
a.second < b.second;
34
}
35
36
template
<
class
KeyType,
class
ValueType>
37
bool
SortDec
(
const
std::pair<KeyType, ValueType>& a,
const
std::pair<KeyType, ValueType>& b)
38
{
39
return
a.second > b.second;
40
}
41
42
}
// namespace Details
43
44
template
<
typename
key_t,
typename
value_t>
45
class
SortPairs
46
{
47
public
:
48
SortPairs
()
49
{
50
}
51
52
public
:
53
void
sort
(Teuchos::Array<std::pair<key_t,value_t> > &listofPairs,
bool
inc=
true
)
54
{
55
// Sort in increasing (default) or decreasing order of value
56
if
(inc)
57
std::stable_sort (listofPairs.begin(), listofPairs.end(),
Details::SortInc<key_t, value_t>
);
58
else
59
std::stable_sort (listofPairs.begin(), listofPairs.end(),
Details::SortDec<key_t, value_t>
);
60
}
61
62
};
63
}
64
#endif
Zoltan2::SortPairs::sort
void sort(Teuchos::Array< std::pair< key_t, value_t > > &listofPairs, bool inc=true)
Definition
Zoltan2_Sort.hpp:53
Zoltan2::SortPairs::SortPairs
SortPairs()
Definition
Zoltan2_Sort.hpp:48
Zoltan2::Details
Definition
Zoltan2_Sort.hpp:27
Zoltan2::Details::SortDec
bool SortDec(const std::pair< KeyType, ValueType > &a, const std::pair< KeyType, ValueType > &b)
Definition
Zoltan2_Sort.hpp:37
Zoltan2::Details::SortInc
bool SortInc(const std::pair< KeyType, ValueType > &a, const std::pair< KeyType, ValueType > &b)
Definition
Zoltan2_Sort.hpp:31
Zoltan2
Created by mbenlioglu on Aug 31, 2020.
Definition
Zoltan2_AlgHybrid2GL.hpp:47
core
src
algorithms
order
Zoltan2_Sort.hpp
Generated by
1.17.0