![]() |
|
|||
File indexing completed on 2024-06-26 07:06:33
0001 // This file is part of the Acts project. 0002 // 0003 // Copyright (C) 2019-2020 CERN for the benefit of the Acts project 0004 // 0005 // This Source Code Form is subject to the terms of the Mozilla Public 0006 // License, v. 2.0. If a copy of the MPL was not distributed with this 0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 0008 0009 #pragma once 0010 0011 #include <cstdint> 0012 0013 #include <boost/container/flat_map.hpp> 0014 0015 namespace Jug { 0016 0017 /// Index type to reference elements in a container. 0018 /// 0019 /// We do not expect to have more than 2^32 elements in any given container so a 0020 /// fixed sized integer type is sufficient. 0021 using Index = uint32_t; 0022 0023 /// Store elements that are identified by an index, e.g. in another container. 0024 /// 0025 /// Each index can have zero or more associated elements. A typical case could 0026 /// be to store all generating particles for a hit where the hit is identified 0027 /// by its index in the hit container. 0028 template <typename value_t> 0029 using IndexMultimap = boost::container::flat_multimap<Index, value_t>; 0030 0031 /// Invert the multimap, i.e. from a -> {b...} to b -> {a...}. 0032 /// 0033 /// @note This assumes that the value in the initial multimap is itself a 0034 /// sortable index-like object, as would be the case when mapping e.g. 0035 /// hit ids to particle ids/ barcodes. 0036 template <typename value_t> 0037 inline boost::container::flat_multimap<value_t, Index> invertIndexMultimap( 0038 const IndexMultimap<value_t>& multimap) { 0039 using InverseMultimap = boost::container::flat_multimap<value_t, Index>; 0040 0041 // switch key-value without enforcing the new ordering (linear copy) 0042 typename InverseMultimap::sequence_type unordered; 0043 unordered.reserve(multimap.size()); 0044 for (auto&& [index, value] : multimap) { 0045 // value is now the key and the index is now the value 0046 unordered.emplace_back(value, index); 0047 } 0048 0049 // adopting the unordered sequence will reestablish the correct order 0050 InverseMultimap inverse; 0051 inverse.adopt_sequence(std::move(unordered)); 0052 return inverse; 0053 } 0054 0055 } // namespace ActsExamples
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.5 LXR engine. The LXR team |
![]() ![]() |