ATLAS Offline Software
Classes | Functions
LArBadChanImpl Namespace Reference

A helper class that provides iterators over elements in two separate ordered containers as if the elements were merged in a single container and sorted, but without any CPU overhead. More...

Classes

class  combined_ordered_container
 
class  combined_ordered_iterator
 
struct  DummyMerger
 

Functions

template<class C1 , class CMP , class MERGER >
std::vector< typename C1::value_type > mergeDuplicateEntries (const C1 &c1, const CMP &cmp, const MERGER &merger)
 

Detailed Description

A helper class that provides iterators over elements in two separate ordered containers as if the elements were merged in a single container and sorted, but without any CPU overhead.

Merges elements in the container that are equivalent according to the ordering defined by the binary predicate CMP.

An iterator that provides transparant iteration over the elements of two sorted containers, presenting the elements in sorted order, as if the two containers were merged and the result sorted, but without the CPU and memory overheads of merging and sorting.

This implementation is sufficient for forward iteration, but not much else.

The merge operation is provided by the template argument MERGER. The result is returned in a std::vector< C::value_type> where C is the type of the input container. PRECONDITION: the input container is sorted according to CMP. This function is a generalization of the algorithm std::unique

Function Documentation

◆ mergeDuplicateEntries()

template<class C1 , class CMP , class MERGER >
std::vector<typename C1::value_type> LArBadChanImpl::mergeDuplicateEntries ( const C1 &  c1,
const CMP &  cmp,
const MERGER &  merger 
)

Definition at line 22 of file mergeDuplicateEntries.h.

23  {
24  typename C1::const_iterator first = c1.begin();
25  typename C1::const_iterator current = first;
26  typename C1::const_iterator last = c1.end();
27  std::vector<typename C1::value_type> result;
28 
29  // protection against empty container
30  if (first == last) return result;
31 
32  while (++first != last) {
33  if (cmp( *current, *first)) { // elements differ, no need to merge
34  result.push_back(*current);
35  ++current;
36  }
37  else { // elemens are equivalent, need to merge
38  typename C1::value_type merged = merger( *current, *first);
39  while (++first != last && !cmp( *current, *first)) {
40  merged = merger( merged, *first); // keep merging while elements don't differ
41  }
42  result.push_back(merged);
43  if (first == last) return result;
44  current = first; // keep track of the element after the last merged
45  }
46  }
47  result.push_back( *current);
48  return result;
49  }
python.EI_Lib.cmp
def cmp(x, y)
Definition: EI_Lib.py:6
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
get_generator_info.result
result
Definition: get_generator_info.py:21
extractSporadic.c1
c1
Definition: extractSporadic.py:134
DeMoScan.first
bool first
Definition: DeMoScan.py:536