Main Page
Namespaces
Classes
Package Documentation
Utilities
General
interface
precomputed_value_sort.h
Go to the documentation of this file.
1
#ifndef precomputed_value_sort_H
2
#define precomputed_value_sort_H
3
12
#include <vector>
13
#include <algorithm>
14
#include <functional>
15
16
template
<
class
RandomAccessIterator,
class
Extractor,
class
Compare>
17
void
precomputed_value_sort
( RandomAccessIterator
begin
, RandomAccessIterator
end
,
18
const
Extractor& extr,
const
Compare&
comp
)
19
{
20
using
Value
=
typename
std::iterator_traits<RandomAccessIterator>::value_type
;
21
using
Scalar
= decltype(extr(*begin));
22
23
std::vector<std::pair<RandomAccessIterator,Scalar>> tmpvec;
24
tmpvec.reserve(end-begin);
25
26
// tmpvec holds iterators - does not copy the real objects
27
for
(RandomAccessIterator
i
=begin;
i
!=
end
;
i
++) tmpvec.emplace_back(
i
,extr(*
i
));
28
29
std::sort
(tmpvec.begin(), tmpvec.end(),[&
comp
](
auto
const
&
a
,
auto
const
&
b
){
30
return
comp
(
a
.second,
b
.second);
31
});
32
33
// overwrite the input range with the sorted values
34
// copy of input container not necessary, but tricky to avoid
35
std::vector<Value> tmpcopy(begin,end);
36
for
(
unsigned
int
i
=0;
i
< tmpvec.size();
i
++) {
37
*(begin+
i
) =
std::move
(tmpcopy[tmpvec[
i
].
first
- begin]);
38
}
39
}
40
41
template
<
class
RandomAccessIterator,
class
Extractor>
42
void
precomputed_value_sort
( RandomAccessIterator
begin
, RandomAccessIterator
end
,
43
const
Extractor& extr )
44
{
45
using
Scalar
= decltype(extr(*begin));
46
precomputed_value_sort
(begin, end, extr, std::less<Scalar>());
47
}
48
49
#endif
jetUpdater_cfi.sort
sort
Definition:
jetUpdater_cfi.py:29
mps_fire.i
i
Definition:
mps_fire.py:338
align::Scalar
double Scalar
Definition:
Definitions.h:27
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
reco::JetExtendedAssociation::Value
reco::JetExtendedAssociation::JetExtendedData Value
Definition:
JetExtendedAssociation.h:27
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:249
end
#define end
Definition:
vmac.h:39
precomputed_value_sort
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
Definition:
precomputed_value_sort.h:17
b
double b
Definition:
hdecay.h:120
plotBeamSpotDB.first
first
Definition:
plotBeamSpotDB.py:381
begin
#define begin
Definition:
vmac.h:32
a
double a
Definition:
hdecay.h:121
eostools.move
def move(src, dest)
Definition:
eostools.py:511
Generated for CMSSW Reference Manual by
1.8.11