-
-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6497 from Zak-K-Abdi/contains/contains_subrange
Contains and contains_subrange parallel algorithm implementation GSOC 2024
- Loading branch information
Showing
8 changed files
with
1,238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
libs/core/algorithms/include/hpx/parallel/algorithms/detail/contains.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024 Zakaria Abdi | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#pragma once | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/functional/detail/tag_fallback_invoke.hpp> | ||
#include <hpx/functional/invoke.hpp> | ||
#include <hpx/parallel/util/loop.hpp> | ||
|
||
#include <algorithm> | ||
#include <cstddef> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
namespace hpx::parallel::detail { | ||
|
||
template <typename ExPolicy> | ||
struct sequential_contains_t final | ||
: hpx::functional::detail::tag_fallback<sequential_contains_t<ExPolicy>> | ||
{ | ||
private: | ||
template <typename Iterator, typename Sentinel, typename T, | ||
typename Proj> | ||
friend constexpr bool tag_fallback_invoke(sequential_contains_t, | ||
Iterator first, Sentinel last, const T& val, Proj&& proj) | ||
{ | ||
using difference_type = | ||
typename std::iterator_traits<Iterator>::difference_type; | ||
difference_type distance = detail::distance(first, last); | ||
if (distance <= 0) | ||
return false; | ||
|
||
const auto itr = | ||
util::loop_pred<std::decay_t<hpx::execution::sequenced_policy>>( | ||
first, last, [&val, &proj](const auto& cur) { | ||
return HPX_INVOKE(proj, *cur) == val; | ||
}); | ||
|
||
return itr != last; | ||
} | ||
|
||
template <typename Iterator, typename T, typename Token, typename Proj> | ||
friend constexpr void tag_fallback_invoke(sequential_contains_t, | ||
Iterator first, T const& val, std::size_t count, Token& tok, | ||
Proj&& proj) | ||
{ | ||
util::loop_n<ExPolicy>( | ||
first, count, tok, [&val, &tok, &proj](const auto& cur) { | ||
if (HPX_INVOKE(proj, *cur) == val) | ||
{ | ||
tok.cancel(); | ||
return; | ||
} | ||
}); | ||
} | ||
}; | ||
template <typename ExPolicy> | ||
inline constexpr sequential_contains_t<ExPolicy> sequential_contains = | ||
sequential_contains_t<ExPolicy>{}; | ||
} //namespace hpx::parallel::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.