8 #ifndef LARDATA_UTILITIES_MAKEINDEX_H 9 #define LARDATA_UTILITIES_MAKEINDEX_H 42 template <
typename Coll,
typename KeyOf>
43 std::vector<size_t>
MakeIndex(Coll
const&
data, KeyOf key_of = KeyOf()) {
53 for (
auto const& datum: data) {
54 size_t key = size_t(key_of(datum));
55 if (key >= min_size) min_size = key + 1;
66 Index.resize(min_size);
98 template <
typename Coll,
typename KeyOf>
99 auto MakeMap(Coll
const& data, KeyOf key_of = KeyOf())
100 ->
std::vector<decltype(key_of(*(data.begin())))
const*>
102 using Mapped_t = decltype(key_of(*(data.begin())));
103 using Ptr_t = Mapped_t
const*;
104 using Map_t = std::vector<Ptr_t>;
109 Map_t
Index(data.size(),
nullptr);
113 for (
auto const& datum: data) {
114 size_t key = size_t(key_of(datum));
115 if (key >= min_size) min_size = key + 1;
122 Index.resize(min_size);
129 #endif // LARDATA_UTILITIES_MAKEINDEX_H Namespace for general, non-LArSoft-specific utilities.
std::vector< size_t > MakeIndex(Coll const &data, KeyOf key_of=KeyOf())
Creates a map of indices from an existing collection.
static int max(int a, int b)
auto MakeMap(Coll const &data, KeyOf key_of=KeyOf()) -> std::vector< decltype(key_of(*(data.begin()))) const * >
Creates a map of objects from an existing collection.