CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
precomputed_value_sort.h File Reference
#include <utility>
#include <vector>
#include <algorithm>

Go to the source code of this file.

Functions

template<class RandomAccessIterator , class Extractor >
void precomputed_value_sort (RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
 
template<class RandomAccessIterator , class Extractor , class BinaryPredicate >
void precomputed_value_sort (RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const BinaryPredicate &pred)
 Sort using a BinaryPredicate. More...
 

Detailed Description

Sort using precomputed values.

precomputed_value_sort behaves like std::sort, but pre-computes the values used in the sorting using an Extractor, so that the computation is performed only once per element.

Definition in file precomputed_value_sort.h.

Function Documentation

template<class RandomAccessIterator , class Extractor >
void precomputed_value_sort ( RandomAccessIterator  begin,
RandomAccessIterator  end,
const Extractor &  extr 
)

Definition at line 39 of file precomputed_value_sort.h.

References end, plotBeamSpotDB::first, i, and python.multivaluedict::sort().

Referenced by MagGeoBuilderFromDDD::bLayer::bLayer(), MagGeoBuilderFromDDD::bRod::bRod(), MagGeoBuilderFromDDD::bSector::bSector(), MagGeoBuilderFromDDD::bSlab::bSlab(), MagGeoBuilderFromDDD::build(), MuonGEMDetLayerGeometryBuilder::buildLayer(), MuonRPCDetLayerGeometryBuilder::buildLayer(), MuonDTDetLayerGeometryBuilder::buildLayers(), MagGeoBuilderFromDDD::eLayer::eLayer(), MagGeoBuilderFromDDD::eSector::eSector(), ForwardDetRingOneZ::initialize(), DetRodOneR::initialize(), MuonRPCDetLayerGeometryBuilder::makeBarrelLayers(), MuonRPCDetLayerGeometryBuilder::makeBarrelRods(), MuonCSCDetLayerGeometryBuilder::makeDetRing(), MuonGEMDetLayerGeometryBuilder::makeDetRing(), MuRodBarrelLayer::MuRodBarrelLayer(), PhiBorderFinder::PhiBorderFinder(), RBorderFinder::RBorderFinder(), MuonDetLayerGeometry::sortLayers(), InOutConversionTrackFinder::tracks(), and OutInConversionTrackFinder::tracks().

41  {
42 
43  typedef typename Extractor::result_type Scalar;
44  typedef std::pair<RandomAccessIterator,Scalar> SortPair;
45 
46  std::vector<SortPair> tmpvec;
47  tmpvec.reserve(end-begin);
48 
49  // tmpvec holds iterators - does not copy the real objects
50  for (RandomAccessIterator i=begin; i!=end; i++) {
51  tmpvec.push_back(SortPair(i,extr(*i)));
52  }
53 
54  std::sort(tmpvec.begin(), tmpvec.end(),
55  LessPair<RandomAccessIterator,Scalar>());
56 
57  // overwrite the input range with the sorted values
58  // copy of input container not necessary, but tricky to avoid
60  for (unsigned int i=0; i<tmpvec.size(); i++) {
61  *(begin+i) = tmpcopy[tmpvec[i].first - begin];
62  }
63 }
int i
Definition: DBlmapReader.cc:9
double Scalar
Definition: Definitions.h:27
#define end
Definition: vmac.h:37
Container::value_type value_type
#define begin
Definition: vmac.h:30
template<class RandomAccessIterator , class Extractor , class BinaryPredicate >
void precomputed_value_sort ( RandomAccessIterator  begin,
RandomAccessIterator  end,
const Extractor &  extr,
const BinaryPredicate &  pred 
)

Sort using a BinaryPredicate.

Definition at line 69 of file precomputed_value_sort.h.

References end, plotBeamSpotDB::first, i, and python.multivaluedict::sort().

72  {
73 
74  typedef typename Extractor::result_type Scalar;
75  typedef std::pair<RandomAccessIterator,Scalar> SortPair;
76 
77  std::vector<SortPair> tmpvec;
78  tmpvec.reserve(end-begin);
79 
80  // tmpvec holds iterators - does not copy the real objects
81  for (RandomAccessIterator i=begin; i!=end; i++) {
82  tmpvec.push_back(SortPair(i,extr(*i)));
83  }
84 
85  std::sort(tmpvec.begin(), tmpvec.end(),
86  ComparePair< RandomAccessIterator,Scalar,BinaryPredicate>(pred));
87 
88  // overwrite the input range with the sorted values
89  // copy of input container not necessary, but tricky to avoid
91  for (unsigned int i=0; i<tmpvec.size(); i++) {
92  *(begin+i) = tmpcopy[tmpvec[i].first - begin];
93  }
94 
95 }
int i
Definition: DBlmapReader.cc:9
double Scalar
Definition: Definitions.h:27
#define end
Definition: vmac.h:37
Container::value_type value_type
#define begin
Definition: vmac.h:30