Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Index.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Index.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <cstdint>
12 
13 #include <boost/container/flat_map.hpp>
14 
15 namespace ActsExamples {
16 
21 using Index = uint32_t;
22 
28 template <typename value_t>
29 using IndexMultimap = boost::container::flat_multimap<Index, value_t>;
30 
36 template <typename value_t>
37 inline boost::container::flat_multimap<value_t, Index> invertIndexMultimap(
38  const IndexMultimap<value_t>& multimap) {
39  using InverseMultimap = boost::container::flat_multimap<value_t, Index>;
40 
41  // switch key-value without enforcing the new ordering (linear copy)
42  typename InverseMultimap::sequence_type unordered;
43  unordered.reserve(multimap.size());
44  for (auto&& [index, value] : multimap) {
45  // value is now the key and the index is now the value
46  unordered.emplace_back(value, index);
47  }
48 
49  // adopting the unordered sequence will reestablish the correct order
50  InverseMultimap inverse;
51 #if BOOST_VERSION < 107800
52  for (const auto& i : unordered) {
53  inverse.insert(i);
54  }
55 #else
56  inverse.insert(unordered.begin(), unordered.end());
57 #endif
58  return inverse;
59 }
60 
61 } // namespace ActsExamples