ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
algorithms.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/definitions/detail/qualifiers.hpp"
13#include "detray/utils/find_bound.hpp"
14#include "detray/utils/ranges/detail/iterator_functions.hpp"
15#include "detray/utils/sort.hpp"
16
17// System include(s)
18#include <algorithm>
19
20namespace detray {
21
27template <std::random_access_iterator rand_iter_t,
28 std::sentinel_for<rand_iter_t> sentinel_t>
29DETRAY_HOST_DEVICE inline void sequential_sort(rand_iter_t first,
30 sentinel_t last) {
31#if defined(DETRAY_NO_DEVICE)
32 std::ranges::sort(first, last);
33#else
34 detray::detail::selection_sort(first, last);
35#endif
36}
37
46template <std::random_access_iterator rand_iter_t,
47 std::sentinel_for<rand_iter_t> sentinel_t, class Predicate>
48DETRAY_HOST_DEVICE inline auto find_if(rand_iter_t first, sentinel_t last,
49 Predicate&& comp) {
50 for (rand_iter_t i = first; i != last; ++i) {
51 if (std::forward<Predicate>(comp)(*i)) {
52 return i;
53 }
54 }
55
56 return last;
57}
58
67template <std::forward_iterator forw_iter_t,
68 std::sentinel_for<forw_iter_t> sentinel_t, typename Value>
69DETRAY_HOST_DEVICE inline auto lower_bound(forw_iter_t first, sentinel_t last,
70 const Value& value) {
71#if defined(DETRAY_NO_DEVICE)
72 return std::ranges::lower_bound(first, last, value);
73#else
74 return detray::detail::lower_bound(first, last, value);
75#endif
76}
77
86template <std::forward_iterator forw_iter_t,
87 std::sentinel_for<forw_iter_t> sentinel_t, typename Value>
88DETRAY_HOST_DEVICE inline auto upper_bound(forw_iter_t first, sentinel_t last,
89 const Value& value) {
90#if defined(DETRAY_NO_DEVICE)
91 return std::ranges::upper_bound(first, last, value);
92#else
93 return detray::detail::upper_bound(first, last, value);
94#endif
95}
96
97} // namespace detray
Detray include(s).
Definition array_operators.hpp:18
auto upper_bound(forw_iter_t first, sentinel_t last, const Value &value)
upper_bound implementation for host/device
Definition algorithms.hpp:88
void sequential_sort(rand_iter_t first, sentinel_t last)
sequential (single thread) sort function
Definition algorithms.hpp:29
auto find_if(rand_iter_t first, sentinel_t last, Predicate &&comp)
find_if implementation for host/device (single thread)
Definition algorithms.hpp:48
auto lower_bound(forw_iter_t first, sentinel_t last, const Value &value)
lower_bound implementation for host/device
Definition algorithms.hpp:69