5#ifndef XAODINDETMEASUREMENT_CONTAINERACCESSOR_H
6#define XAODINDETMEASUREMENT_CONTAINERACCESSOR_H
10#include <boost/container/small_vector.hpp>
12#include <unordered_map>
24template <
typename value_t,
typename identifier_t,
size_t inline_size = 10>
30 using Range = std::pair<Iterator, Iterator>;
42 std::function<identifier_t(
const value_t&)> mapper,
size_t max_ids=2000) {
44 std::optional<identifier_t> prev = std::nullopt;
45 Iterator groupStart = values.begin();
46 for (
Iterator it = values.begin(); it != values.end(); ++it) {
47 identifier_t
id = mapper(**it);
48 if (prev && (*prev) !=
id) {
49 m_ranges[*prev].emplace_back(groupStart, it);
55 m_ranges[*prev].emplace_back(groupStart, values.end());
70 boost::container::small_vector<Range, inline_size> rangesForId =
m_ranges.at(identifier);
85 std::vector<identifier_t> ids{};
87 for (
const auto& id_range :
m_ranges)
88 ids.push_back(id_range.first);
93 std::unordered_map<identifier_t, boost::container::small_vector<Range, inline_size>>
m_ranges;
An STL vector of pointers that by default owns its pointed-to elements.
std::unordered_map< identifier_t, boost::container::small_vector< Range, inline_size > > m_ranges
ContainerAccessor(const container_t &values, std::function< identifier_t(const value_t &)> mapper, size_t max_ids=2000)
Constructor.
const boost::container::small_vector< Range, inline_size > rangesForIdentifierDirect(const identifier_t &identifier) const
Function to return the list of ranges corresponding to a given identifier.
std::pair< Iterator, Iterator > Range
typename container_t::const_iterator Iterator
std::vector< identifier_t > allIdentifiers() const
Function to return all available identifier (i.e. keys in the map)
bool isIdentifierPresent(const identifier_t &identifier) const
Function to verify if a given identifier is present in the map, i.e.
ContainerAccessor(const ContainerAccessor &)=delete
Copy constructor, deleted.
DataVector< value_t > container_t
~ContainerAccessor()=default
Default destructor.
ContainerAccessor & operator=(const ContainerAccessor &)=delete
DataModel_detail::const_iterator< DataVector > const_iterator