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.

Date:
2006/10/23 09:53:54
Revision:
1.2

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 41 of file precomputed_value_sort.h.

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

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

43  {
44 
45  typedef typename Extractor::result_type Scalar;
46  typedef std::pair<RandomAccessIterator,Scalar> SortPair;
47 
48  std::vector<SortPair> tmpvec;
49  tmpvec.reserve(end-begin);
50 
51  // tmpvec holds iterators - does not copy the real objects
52  for (RandomAccessIterator i=begin; i!=end; i++) {
53  tmpvec.push_back(SortPair(i,extr(*i)));
54  }
55 
56  std::sort(tmpvec.begin(), tmpvec.end(),
57  LessPair<RandomAccessIterator,Scalar>());
58 
59  // overwrite the input range with the sorted values
60  // copy of input container not necessary, but tricky to avoid
62  for (unsigned int i=0; i<tmpvec.size(); i++) {
63  *(begin+i) = tmpcopy[tmpvec[i].first - begin];
64  }
65 }
int i
Definition: DBlmapReader.cc:9
double Scalar
Definition: Definitions.h:27
#define end
Definition: vmac.h:38
bool first
Definition: L1TdeRCT.cc:94
Container::value_type value_type
#define begin
Definition: vmac.h:31
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 71 of file precomputed_value_sort.h.

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

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