EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndexContainers.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file IndexContainers.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 <cstddef>
12 #include <utility>
13 
14 #include <boost/container/flat_map.hpp>
15 
16 namespace ActsExamples {
17 
23 template <typename Value, typename Key = std::size_t>
24 using IndexMultimap = boost::container::flat_multimap<Key, Value>;
25 
31 template <typename Value, typename Key>
33  const IndexMultimap<Value, Key>& multimap) {
34  // switch key-value without enforcing the new ordering (linear copy)
36  unordered.reserve(multimap.size());
37  for (const auto& keyValue : multimap) {
38  // value is now the key and the key is now the value
39  unordered.emplace_back(keyValue.second, keyValue.first);
40  }
41  // adopting the unordered sequence will reestablish the correct order
43  inverse.adopt_sequence(std::move(unordered));
44  return inverse;
45 }
46 
47 } // namespace ActsExamples