Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:04

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s).
0012 #include "detray/definitions/algorithms.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/definitions/indexing.hpp"
0015 #include "detray/utils/invalid_values.hpp"
0016 
0017 namespace detray {
0018 
0019 /// A replace populator that overrides whatever current content is in the bin
0020 /// with a new entry.
0021 ///
0022 /// @tparam kSORT sort the entries in the bin
0023 ///
0024 /// @note entry type and bin content type may not be identical for all bin
0025 /// types
0026 template <bool kSORT = false>
0027 struct replace {
0028   /// Replace the bin content with a new entry - forwarding
0029   ///
0030   /// @param bin the bin for which to replace the content
0031   /// @param content new content to be added
0032   template <typename bin_t, typename content_t>
0033   DETRAY_HOST_DEVICE void operator()(bin_t &&bin, content_t &&entry) const {
0034     std::forward<bin_t>(bin).init(std::forward<content_t>(entry));
0035 
0036     // Optionally sort the bin content
0037     if constexpr (kSORT) {
0038       detray::sequential_sort(std::forward<bin_t>(bin).begin(),
0039                               std::forward<bin_t>(bin).end());
0040     }
0041   }
0042 };
0043 
0044 /// An attach populator that adds a new entry to a given bin.
0045 ///
0046 /// @tparam kSORT sort the entries in the bin
0047 template <bool kSORT = false>
0048 struct attach {
0049   /// Append a new entry to the bin - forwarding
0050   ///
0051   /// @param bin the bin for which to replace the content
0052   /// @param content new content to be added
0053   template <typename bin_t, typename entry_t>
0054   DETRAY_HOST_DEVICE void operator()(bin_t &&bin, entry_t &&entry) const {
0055     std::forward<bin_t>(bin).push_back(std::forward<entry_t>(entry));
0056 
0057     // Optionally sort the bin content
0058     if constexpr (kSORT) {
0059       detray::sequential_sort(std::forward<bin_t>(bin).begin(),
0060                               std::forward<bin_t>(bin).end());
0061     }
0062   }
0063 };
0064 
0065 /// A complete populator that adds entries to a bin which contains an
0066 /// array of entries until it is completed - ignored afterwards.
0067 ///
0068 /// @tparam kSORT sort the entries in the bin content
0069 template <bool kSORT = false>
0070 struct complete {
0071   /// Complete the bin content with a new entry - forwarding
0072   ///
0073   /// @param bin the bin for which to replace the content
0074   /// @param content new content to be added
0075   template <typename bin_t, typename entry_t>
0076   DETRAY_HOST_DEVICE void operator()(bin_t &&bin, entry_t &&entry) const {
0077     for (dindex i{std::forward<bin_t>(bin).size()};
0078          i < std::forward<bin_t>(bin).capacity(); ++i) {
0079       std::forward<bin_t>(bin).push_back(std::forward<entry_t>(entry));
0080     }
0081 
0082     // Optionally sort the bin content
0083     if constexpr (kSORT) {
0084       detray::sequential_sort(std::forward<bin_t>(bin).begin(),
0085                               std::forward<bin_t>(bin).end());
0086     }
0087   }
0088 };
0089 
0090 }  // namespace detray