CMS 3D CMS Logo

Functions

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Utilities/General/interface/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.

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(), MuonDTDetLayerGeometryBuilder::buildLayers(), MagGeoBuilderFromDDD::eLayer::eLayer(), MagGeoBuilderFromDDD::eSector::eSector(), DetRodOneR::initialize(), ForwardDetRingOneZ::initialize(), MuonRPCDetLayerGeometryBuilder::makeBarrelLayers(), MuonRPCDetLayerGeometryBuilder::makeBarrelRods(), MuonCSCDetLayerGeometryBuilder::makeDetRing(), MuRodBarrelLayer::MuRodBarrelLayer(), PhiBorderFinder::PhiBorderFinder(), RBorderFinder::RBorderFinder(), MuonDetLayerGeometry::sortLayers(), OutInConversionTrackFinder::tracks(), and InOutConversionTrackFinder::tracks().

                                                   {

  typedef typename Extractor::result_type        Scalar;
  typedef std::pair<RandomAccessIterator,Scalar> SortPair;

  std::vector<SortPair> tmpvec; 
  tmpvec.reserve(end-begin);

  // tmpvec holds iterators - does not copy the real objects
  for (RandomAccessIterator i=begin; i!=end; i++) {
    tmpvec.push_back(SortPair(i,extr(*i)));
  }
  
  std::sort(tmpvec.begin(), tmpvec.end(),
            LessPair<RandomAccessIterator,Scalar>());    

  // overwrite the input range with the sorted values
  // copy of input container not necessary, but tricky to avoid
  std::vector<typename std::iterator_traits<RandomAccessIterator>::value_type> tmpcopy(begin,end);
  for (unsigned int i=0; i<tmpvec.size(); i++) {
    *(begin+i) = tmpcopy[tmpvec[i].first - begin];
  }
}
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().

                                                          {

  typedef typename Extractor::result_type        Scalar;
  typedef std::pair<RandomAccessIterator,Scalar> SortPair;

  std::vector<SortPair> tmpvec; 
  tmpvec.reserve(end-begin);

  // tmpvec holds iterators - does not copy the real objects
  for (RandomAccessIterator i=begin; i!=end; i++) {
    tmpvec.push_back(SortPair(i,extr(*i)));
  }
  
  std::sort(tmpvec.begin(), tmpvec.end(),
            ComparePair< RandomAccessIterator,Scalar,BinaryPredicate>(pred));

  // overwrite the input range with the sorted values
  // copy of input container not necessary, but tricky to avoid
  std::vector<typename std::iterator_traits<RandomAccessIterator>::value_type> tmpcopy(begin,end);
  for (unsigned int i=0; i<tmpvec.size(); i++) {
    *(begin+i) = tmpcopy[tmpvec[i].first - begin];
  }

}