Skip to content

Commit

Permalink
Making set_intersection conform to C++20
Browse files Browse the repository at this point in the history
- adding range-based overloads
  • Loading branch information
hkaiser committed Sep 19, 2020
1 parent 1f5284d commit 898f51d
Show file tree
Hide file tree
Showing 14 changed files with 1,573 additions and 143 deletions.
2 changes: 1 addition & 1 deletion docs/sphinx/api/public_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Functions
- :cpp:func:`hpx::parallel::v1::search`
- :cpp:func:`hpx::parallel::v1::search_n`
- :cpp:func:`hpx::parallel::v1::set_difference`
- :cpp:func:`hpx::parallel::v1::set_intersection`
- :cpp:func:`hpx::set_intersection`
- :cpp:func:`hpx::parallel::v1::set_symmetric_difference`
- :cpp:func:`hpx::parallel::v1::set_union`
- :cpp:func:`hpx::parallel::v1::sort`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ Parallel algorithms
* Computes the difference between two sets.
* ``<hpx/algorithm.hpp>``
* :cppreference-algorithm:`set_difference`
* * :cpp:func:`hpx::parallel::v1::set_intersection`
* * :cpp:func:`hpx::set_intersection`
* Computes the intersection of two sets.
* ``<hpx/algorithm.hpp>``
* :cppreference-algorithm:`set_intersection`
Expand Down
1 change: 0 additions & 1 deletion libs/full/include/include/hpx/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace hpx {
using hpx::parallel::search;
using hpx::parallel::search_n;
using hpx::parallel::set_difference;
using hpx::parallel::set_intersection;
using hpx::parallel::set_symmetric_difference;
using hpx::parallel::set_union;
using hpx::parallel::sort;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2020 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -11,3 +11,5 @@
#include <hpx/parallel/algorithms/set_intersection.hpp>
#include <hpx/parallel/algorithms/set_symmetric_difference.hpp>
#include <hpx/parallel/algorithms/set_union.hpp>

#include <hpx/parallel/container_algorithms/set_intersection.hpp>
1 change: 1 addition & 0 deletions libs/parallelism/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ set(algorithms_headers
hpx/parallel/container_algorithms/reverse.hpp
hpx/parallel/container_algorithms/rotate.hpp
hpx/parallel/container_algorithms/search.hpp
hpx/parallel/container_algorithms/set_intersection.hpp
hpx/parallel/container_algorithms/sort.hpp
hpx/parallel/container_algorithms/stable_sort.hpp
hpx/parallel/container_algorithms/transform.hpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2020 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -11,6 +11,7 @@

#include <hpx/execution/executors/execution_information.hpp>
#include <hpx/executors/execution_policy.hpp>
#include <hpx/parallel/algorithms/detail/distance.hpp>
#include <hpx/parallel/util/detail/algorithm_result.hpp>
#include <hpx/parallel/util/foreach_partitioner.hpp>
#include <hpx/parallel/util/partitioner.hpp>
Expand All @@ -37,11 +38,11 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail {
class rewritable_ref
{
public:
rewritable_ref()
constexpr rewritable_ref()
: item_(0)
{
}
rewritable_ref(T const& item)
constexpr rewritable_ref(T const& item)
: item_(item)
{
}
Expand All @@ -52,11 +53,13 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail {
return *this;
}

operator T const&() const
// clang-format off
constexpr operator T const&() const
{
HPX_ASSERT(item_ != 0);
return *item_;
}
// clang-format on

private:
T const* item_;
Expand All @@ -69,33 +72,29 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail {

struct set_chunk_data
{
set_chunk_data()
{
start = len = start_index = (std::size_t)(-1);
}
std::size_t start;
std::size_t len;
std::size_t start_index;
std::size_t start = std::size_t(-1);
std::size_t len = std::size_t(-1);
std::size_t start_index = std::size_t(-1);
};

///////////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename RanIter1, typename RanIter2,
typename FwdIter, typename F, typename Combiner, typename SetOp>
typename util::detail::algorithm_result<ExPolicy, FwdIter>::type
set_operation(ExPolicy policy, RanIter1 first1, RanIter1 last1,
RanIter2 first2, RanIter2 last2, FwdIter dest, F&& f,
Combiner&& combiner, SetOp&& setop)
template <typename ExPolicy, typename Iter1, typename Sent1, typename Iter2,
typename Sent2, typename Iter3, typename F, typename Combiner,
typename SetOp>
typename util::detail::algorithm_result<ExPolicy, Iter3>::type
set_operation(ExPolicy policy, Iter1 first1, Sent1 last1, Iter2 first2,
Sent2 last2, Iter3 dest, F&& f, Combiner&& combiner, SetOp&& setop)
{
typedef typename std::iterator_traits<RanIter1>::difference_type
difference_type1;
typedef typename std::iterator_traits<RanIter2>::difference_type
difference_type2;
using difference_type1 =
typename std::iterator_traits<Iter1>::difference_type;
using difference_type2 =
typename std::iterator_traits<Iter2>::difference_type;

// allocate intermediate buffers
difference_type1 len1 = std::distance(first1, last1);
difference_type2 len2 = std::distance(first2, last2);
difference_type1 len1 = detail::distance(first1, last1);
difference_type2 len2 = detail::distance(first2, last2);

typedef typename set_operations_buffer<FwdIter>::type buffer_type;
typedef typename set_operations_buffer<Iter3>::type buffer_type;

std::size_t cores = execution::processing_units_count(
policy.parameters(), policy.executor());
Expand Down Expand Up @@ -174,8 +173,12 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail {
};

// second step, is executed after all partitions are done running

// different versions of clang-format produce different formatting
// clang-format off
auto f2 = [buffer, chunks, cores, dest](
std::vector<future<void>> &&) -> FwdIter {
std::vector<future<void>>&&) -> Iter3 {
// clang-format on
// accumulate real length
set_chunk_data* chunk = chunks.get();
chunk->start_index = 0;
Expand Down Expand Up @@ -208,7 +211,7 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail {
};

// fill the buffer piecewise
return parallel::util::partitioner<ExPolicy, FwdIter, void>::call(
return parallel::util::partitioner<ExPolicy, Iter3, void>::call(
policy, chunks.get(), cores, std::move(f1), std::move(f2));
}

Expand Down
Loading

0 comments on commit 898f51d

Please sign in to comment.