ATLAS Offline Software
DVL_algorithms.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // $Id$
16 #ifndef ATHCONTAINERS_TOOLS_DVL_ALGORITHMS_H
17 #define ATHCONTAINERS_TOOLS_DVL_ALGORITHMS_H
18 
19 
21 #include <iterator>
22 #include <algorithm>
23 
24 
26 
27 
28 
29 //===========================================================================
30 // Algorithms requiring @c ForwardIterator.
31 // Usable with @c DataVector and @c DataList.
32 //
33 
34 namespace std {
35 
36 
47 template <class DVL, class T>
51  const T& value)
52 {
53  // Implemented with iter_swap, no extra index manipulation needed.
54  return DataModel_detail::dvl_remove (beg, end, value);
55 }
56 
57 
68 template <class DVL, class Predicate>
72  Predicate pred)
73 {
74  // Implemented with iter_swap, no extra index manipulation needed.
75  return DataModel_detail::dvl_remove_if (beg, end, pred);
76 }
77 
78 
90 template <class DVL, class T>
91 typename std::reverse_iterator<DataModel_detail::iterator<DVL> >
92 remove (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
93  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
94  const T& value)
95 {
96  // Implemented with iter_swap, no extra index manipulation needed.
97  return DataModel_detail::dvl_remove (beg, end, value);
98 }
99 
100 
112 template <class DVL, class Predicate>
113 typename std::reverse_iterator<DataModel_detail::iterator<DVL> >
114 remove_if (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
115  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
116  Predicate pred)
117 {
118  // Implemented with iter_swap, no extra index manipulation needed.
119  return DataModel_detail::dvl_remove_if (beg, end, pred);
120 }
121 
122 
133 template <class DVL>
137 {
138  // Implemented with iter_swap, no extra index manipulation needed.
139  return DataModel_detail::dvl_unique (beg, end);
140 }
141 
142 
153 template <class DVL, class BinaryPredicate>
157  BinaryPredicate pred)
158 {
159  // Implemented with iter_swap, no extra index manipulation needed.
160  return DataModel_detail::dvl_unique (beg, end, pred);
161 }
162 
163 
175 template <class DVL>
176 typename std::reverse_iterator<DataModel_detail::iterator<DVL> >
177 unique (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
178  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end)
179 {
180  // Implemented with iter_swap, no extra index manipulation needed.
181  return DataModel_detail::dvl_unique (beg, end);
182 }
183 
184 
197 template <class DVL, class BinaryPredicate>
198 typename std::reverse_iterator<DataModel_detail::iterator<DVL> >
199 unique (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
200  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
201  BinaryPredicate pred)
202 {
203  // Implemented with iter_swap, no extra index manipulation needed.
204  return DataModel_detail::dvl_unique (beg, end, pred);
205 }
206 
207 
220 template <class DVL>
222  typename DataModel_detail::iterator<DVL> mid,
224 {
225  std::rotate (beg.base(), mid.base(), end.base());
226  DataModel_detail::resortAux (beg, end);
227 }
228 
229 
242 template <class DVL>
243 void
244 rotate (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
245  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > mid,
246  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end)
247 {
248  typedef typename DVL::BaseContainer::reverse_iterator ri;
249  std::rotate (ri(beg.base().base()),
250  ri(mid.base().base()),
251  ri(end.base().base()));
252  DataModel_detail::resortAux (beg, end);
253 }
254 
255 
256 } // namespace std
257 
258 
259 
260 //===========================================================================
261 // Algorithms requiring @c BidirectionalIterator.
262 // Usable with @c DataVector and @c DataList.
263 //
264 
265 namespace std {
266 
267 
279 template <class DVL>
280 void reverse (typename DataModel_detail::iterator<DVL> beg,
282 {
283  std::reverse (beg.base(), end.base());
284  DataModel_detail::resortAux (beg, end);
285 }
286 
287 
299 template <class DVL>
300 void
301 reverse (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
302  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end)
303 {
304  typedef typename DVL::BaseContainer::reverse_iterator ri;
305  std::reverse (ri(beg.base().base()), ri(end.base().base()));
306  DataModel_detail::resortAux (beg, end);
307 }
308 
309 
322 template <class DVL, class Predicate>
326  Predicate pred)
327 {
329  (std::partition (beg.base(), end.base(),
330  DataModel_detail::Predwrapper<DVL, Predicate> (pred)),
331  beg.container());
332  DataModel_detail::resortAux (beg, end);
333  return ret;
334 }
335 
336 
349 template <class DVL, class Predicate>
350 typename std::reverse_iterator<DataModel_detail::iterator<DVL> >
351 partition (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
352  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
353  Predicate pred)
354 {
355  typedef typename DataModel_detail::iterator<DVL> Iterator;
356  typedef typename DVL::BaseContainer::reverse_iterator ri;
357  typedef typename DataModel_detail::Predwrapper<DVL, Predicate> pwrap_t;
358  std::reverse_iterator<Iterator> ret
359  (Iterator (std::partition (ri(beg.base().base()),
360  ri(end.base().base()),
361  pwrap_t (pred)).base(),
362  beg.base().container()));
363  DataModel_detail::resortAux (beg, end);
364  return ret;
365 }
366 
367 
380 template <class DVL, class Predicate>
384  Predicate pred)
385 {
387  (std::stable_partition (beg.base(), end.base(),
388  DataModel_detail::Predwrapper<DVL, Predicate>
389  (pred)),
390  beg.container());
391  DataModel_detail::resortAux (beg, end);
392  return ret;
393 }
394 
395 
408 template <class DVL, class Predicate>
409 typename std::reverse_iterator<DataModel_detail::iterator<DVL> >
411  (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
412  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
413  Predicate pred)
414 {
415  typedef typename DataModel_detail::iterator<DVL> Iterator;
416  typedef typename DVL::BaseContainer::reverse_iterator ri;
417  typedef typename DataModel_detail::Predwrapper<DVL, Predicate> pwrap_t;
418  std::reverse_iterator<Iterator> ret
419  (Iterator (std::stable_partition (ri(beg.base().base()),
420  ri(end.base().base()),
421  pwrap_t (pred)).base(),
422  beg.base().container()));
423  DataModel_detail::resortAux (beg, end);
424  return ret;
425 }
426 
427 
440 template <class DVL>
441 void
443  typename DataModel_detail::iterator<DVL> mid,
445 {
446  std::inplace_merge (beg.base(), mid.base(), end.base());
447  DataModel_detail::resortAux (beg, end);
448 }
449 
450 
464 template <class DVL, class Compare>
465 void
467  typename DataModel_detail::iterator<DVL> mid,
469  Compare comp)
470 {
471  std::inplace_merge (beg.base(), mid.base(), end.base(),
472  typename DataModel_detail::Compwrapper<DVL, Compare>(comp));
473  DataModel_detail::resortAux (beg, end);
474 }
475 
476 
489 template <class DVL>
490 void
491 inplace_merge (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
492  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > mid,
493  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end)
494 {
495  typedef typename DVL::BaseContainer::reverse_iterator ri;
496  std::inplace_merge (ri (beg.base().base()),
497  ri (mid.base().base()),
498  ri (end.base().base()));
499  DataModel_detail::resortAux (beg, end);
500 }
501 
502 
516 template <class DVL, class Compare>
517 void
518 inplace_merge (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
519  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > mid,
520  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
521  Compare comp)
522 {
523  typedef typename DVL::BaseContainer::reverse_iterator ri;
524  std::inplace_merge (ri (beg.base().base()),
525  ri (mid.base().base()),
526  ri (end.base().base()),
527  typename DataModel_detail::Compwrapper<DVL, Compare>(comp));
528  DataModel_detail::resortAux (beg, end);
529 }
530 
531 
532 } // namespace std
533 
534 
535 
536 //===========================================================================
537 // Algorithms requiring @c RandomAccessIterator.
538 // Usable with @c DataVector.
539 //
540 
541 namespace std {
542 
543 
553 template <class DVL>
556 {
557  // Wrap the default comparison object,
558  // in case someone's overridden operator< for pointers.
559  typedef std::less<typename DVL::BaseContainer::value_type> less;
560  std::sort (beg.base(), end.base(),
561  typename DataModel_detail::Compwrapper<DVL, less> (less()));
562  DataModel_detail::resortAux (beg, end);
563 }
564 
565 
576 template <class DVL, class Compare>
579  Compare comp)
580 {
581  std::sort (beg.base(), end.base(),
582  typename DataModel_detail::Compwrapper<DVL, Compare> (comp));
583  DataModel_detail::resortAux (beg, end);
584 }
585 
586 
597 template <class DVL>
598 void sort (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
599  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end)
600 {
601  typedef typename DVL::BaseContainer::reverse_iterator ri;
602  // Wrap the default comparison object,
603  // in case someone's overridden operator< for pointers.
604  typedef std::less<typename DVL::BaseContainer::value_type> less;
605  std::sort (ri (beg.base().base()), ri (end.base().base()),
606  typename DataModel_detail::Compwrapper<DVL, less> (less()));
607  DataModel_detail::resortAux (beg, end);
608 }
609 
610 
622 template <class DVL, class Compare>
623 void sort (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
624  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
625  const Compare& comp)
626 {
627  typedef typename DVL::BaseContainer::reverse_iterator ri;
628  std::sort (ri (beg.base().base()), ri (end.base().base()),
629  typename DataModel_detail::Compwrapper<DVL, Compare> (comp));
630  DataModel_detail::resortAux (beg, end);
631 }
632 
633 
643 template <class DVL>
646 {
647  // Wrap the default comparison object,
648  // in case someone's overridden operator< for pointers.
649  typedef std::less<typename DVL::BaseContainer::value_type> less;
650  std::stable_sort (beg.base(), end.base(),
651  DataModel_detail::Compwrapper<DVL, less> (less()));
652  DataModel_detail::resortAux (beg, end);
653 }
654 
655 
665 template <class DVL, class Compare>
668  Compare comp)
669 {
670  std::stable_sort (beg.base(), end.base(),
671  DataModel_detail::Compwrapper<DVL, Compare> (comp));
672  DataModel_detail::resortAux (beg, end);
673 }
674 
675 
686 template <class DVL>
687 void stable_sort (std::reverse_iterator<DataModel_detail::iterator <DVL> > beg,
688  std::reverse_iterator<DataModel_detail::iterator <DVL> > end)
689 {
690  typedef typename DVL::BaseContainer::reverse_iterator ri;
691  // Wrap the default comparison object,
692  // in case someone's overridden operator< for pointers.
693  typedef std::less<typename DVL::BaseContainer::value_type> less;
694  std::stable_sort (ri (beg.base().base()), ri (end.base().base()),
695  typename DataModel_detail::Compwrapper<DVL, less> (less()));
696  DataModel_detail::resortAux (beg, end);
697 }
698 
699 
710 template <class DVL, class Compare>
711 void stable_sort (std::reverse_iterator<DataModel_detail::iterator <DVL> > beg,
712  std::reverse_iterator<DataModel_detail::iterator <DVL> > end,
713  Compare comp)
714 {
715  typedef typename DVL::BaseContainer::reverse_iterator ri;
716  std::stable_sort (ri (beg.base().base()), ri (end.base().base()),
717  typename DataModel_detail::Compwrapper<DVL, Compare>(comp));
718  DataModel_detail::resortAux (beg, end);
719 }
720 
721 
733 template <class DVL>
737 {
738  // Wrap the default comparison object,
739  // in case someone's overridden operator< for pointers.
740  typedef std::less<typename DVL::BaseContainer::value_type> less;
741  std::partial_sort (beg.base(), mid.base(), end.base(),
742  DataModel_detail::Compwrapper<DVL, less> (less()));
743  DataModel_detail::resortAux (beg, end);
744 }
745 
746 
758 template <class DVL, class Compare>
762  Compare comp)
763 {
764  std::partial_sort (beg.base(), mid.base(), end.base(),
765  DataModel_detail::Compwrapper<DVL, Compare> (comp));
766  DataModel_detail::resortAux (beg, end);
767 }
768 
769 
781 template <class DVL>
782 void partial_sort (std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
783  std::reverse_iterator<DataModel_detail::iterator<DVL> > mid,
784  std::reverse_iterator<DataModel_detail::iterator<DVL> > end)
785 {
786  typedef typename DVL::BaseContainer::reverse_iterator ri;
787  // Wrap the default comparison object,
788  // in case someone's overridden operator< for pointers.
789  typedef std::less<typename DVL::BaseContainer::value_type> less;
790  std::partial_sort (ri (beg.base().base()),
791  ri (mid.base().base()),
792  ri (end.base().base()),
793  typename DataModel_detail::Compwrapper<DVL, less>
794  (less()));
795  DataModel_detail::resortAux (beg, end);
796 }
797 
798 
810 template <class DVL, class Compare>
811 void partial_sort (std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
812  std::reverse_iterator<DataModel_detail::iterator<DVL> > mid,
813  std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
814  Compare comp)
815 {
816  typedef typename DVL::BaseContainer::reverse_iterator ri;
817  std::partial_sort (ri (beg.base().base()),
818  ri (mid.base().base()),
819  ri (end.base().base()),
820  typename DataModel_detail::Compwrapper<DVL, Compare>
821  (comp));
822  DataModel_detail::resortAux (beg, end);
823 }
824 
825 
838 template <class DVL, class UniformRandom>
841  UniformRandom& g)
842 {
843  std::shuffle (beg.base(), end.base(), g);
844  DataModel_detail::resortAux (beg, end);
845 }
846 
847 
860 template <class DVL, class UniformRandom>
861 void
863  (typename std::reverse_iterator<DataModel_detail::iterator<DVL> > beg,
864  typename std::reverse_iterator<DataModel_detail::iterator<DVL> > end,
865  UniformRandom& g)
866 {
867  typedef typename DVL::BaseContainer::reverse_iterator ri;
868  std::shuffle (ri(beg.base().base()),
869  ri(end.base().base()),
870  g);
871  DataModel_detail::resortAux (beg, end);
872 }
873 
874 
875 } // namespace std
876 
877 
878 
879 #endif // not ATHCONTAINERS_TOOLS_DVL_ALGORITHMS_H
plotting.yearwise_luminosity_vs_mu.comp
comp
Definition: yearwise_luminosity_vs_mu.py:23
base
std::string base
Definition: hcg.cxx:78
std::shuffle
void shuffle(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, UniformRandom &g)
Specialization of shuffle for DataVector/List.
Definition: DVL_algorithms.h:863
rotate
void rotate(double angler, GeoTrf::Vector2D &vector)
Definition: TRTDetectorFactory_Full.cxx:63
athena.value
value
Definition: athena.py:124
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:554
std::stable_sort
void stable_sort(std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Compare comp)
Specialization of stable_sort for DataVector/List.
Definition: DVL_algorithms.h:711
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
std::reverse
void reverse(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end)
Specialization of reverse for DataVector/List.
Definition: DVL_algorithms.h:301
std::inplace_merge
void inplace_merge(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > mid, typename DataModel_detail::iterator< DVL > end)
Specialization of inplace_merge for DataVector/List.
Definition: DVL_algorithms.h:442
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
DVL_algorithms.icc
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
std::stable_partition
std::reverse_iterator< DataModel_detail::iterator< DVL > > stable_partition(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Predicate pred)
Specialization of stable_partition for DataVector/List.
Definition: DVL_algorithms.h:411
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
std::partition
std::reverse_iterator< DataModel_detail::iterator< DVL > > partition(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Predicate pred)
Specialization of partition for DataVector/List.
Definition: DVL_algorithms.h:351
CxxUtils::fpcompare::less
bool less(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:166
std::stable_sort
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
Definition: DVL_algorithms.h:644
std::partial_sort
void partial_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > mid, DataModel_detail::iterator< DVL > end)
Specialization of partial_sort for DataVector/List.
Definition: DVL_algorithms.h:734
std::partial_sort
void partial_sort(std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, std::reverse_iterator< DataModel_detail::iterator< DVL > > mid, std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Compare comp)
Specialization of partial_sort for DataVector/List.
Definition: DVL_algorithms.h:811
std::unique
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
Definition: DVL_algorithms.h:135
std::inplace_merge
void inplace_merge(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > mid, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Compare comp)
Specialization of inplace_merge for DataVector/List.
Definition: DVL_algorithms.h:518
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
std::remove_if
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
Definition: DVL_algorithms.h:70
DVLIterator.h
std::shuffle
void shuffle(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, UniformRandom &g)
Specialization of shuffle for DataVector/List.
Definition: DVL_algorithms.h:839
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
std::stable_partition
DataModel_detail::iterator< DVL > stable_partition(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of stable_partition for DataVector/List.
Definition: DVL_algorithms.h:382