Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[oneDPL] Sort By Key APIs #564

Merged
merged 23 commits into from
Sep 4, 2024
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4c2ae27
[oneDPL] Sort By Key APIs
dmitriy-sobolev Aug 14, 2024
21dcdfc
[oneDPL] Sort By Key APIs
dmitriy-sobolev Aug 14, 2024
8c689b0
Minor improvements
dmitriy-sobolev Aug 15, 2024
7b8211f
Minor improvements
dmitriy-sobolev Aug 15, 2024
6ee3677
Change :code: with double backquotes
dmitriy-sobolev Aug 17, 2024
ef9f079
Clarify the assosition between keys and values
dmitriy-sobolev Sep 2, 2024
b607ceb
Describe comparator
dmitriy-sobolev Sep 2, 2024
898d626
Improve the summaries of sort functions
dmitriy-sobolev Sep 2, 2024
11f0755
Refer to C++ standard sort for comp objects
dmitriy-sobolev Sep 2, 2024
70b4635
Clarify sort stability
dmitriy-sobolev Sep 2, 2024
bb18eed
Improve the algorithm signatures
dmitriy-sobolev Sep 2, 2024
e12dea9
Return a sentence with std::less, minor fixes
dmitriy-sobolev Sep 2, 2024
aab5a3b
Minor correction
dmitriy-sobolev Sep 2, 2024
a422221
Align std::less construction with the rest algorithms
dmitriy-sobolev Sep 2, 2024
f08b420
Add ValueSwappable requirement
dmitriy-sobolev Sep 2, 2024
e71236c
Use double back quotes
dmitriy-sobolev Sep 2, 2024
2084732
Apply suggestions: reorganize the wording
dmitriy-sobolev Sep 3, 2024
060ca50
InputKeyIt -> KeyIt, InputValueIt -> ValueIt
dmitriy-sobolev Sep 3, 2024
fcd1561
Addition sentence for key-value pairs association during sort
dmitriy-sobolev Sep 3, 2024
a21e7e2
InputIt -> KeyIt
dmitriy-sobolev Sep 3, 2024
13dbb96
Remove unnecessary commas
dmitriy-sobolev Sep 3, 2024
1beadb7
Merge branch 'main' into dpl-sort-by-key
dmitriy-sobolev Sep 4, 2024
159ff01
Remove extra line
dmitriy-sobolev Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions source/elements/oneDPL/source/parallel_api.rst
danhoeflinger marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -688,5 +688,57 @@ than an element in the range being searched.

The elements e of [start, end) must be partitioned with respect to the comparator used.

.. code:: cpp

template<typename Policy, typename KeyIt, typename ValueIt,
typename Comparator = std::less<typename std::iterator_traits<InputIt>::value_type>>
void
sort_by_key(Policy&& policy, KeyIt keys_first, KeyIt keys_last,
ValueIt values_first,
Comparator comp = std::less<typename std::iterator_traits<InputIt>::value_type>());
danhoeflinger marked this conversation as resolved.
Show resolved Hide resolved

``oneapi::dpl::sort_by_key`` sorts the sequence of keys ``[keys_first, keys_last)``
and simultaneously permutes associated values at the same positions in the range
``[values_first, values_first + std::distance(keys_first, keys_last))``
to match the order of the sorted keys.
dmitriy-sobolev marked this conversation as resolved.
Show resolved Hide resolved

Keys are sorted with respect to the provided comparator object ``comp``. That means, for any
two iterators ``i`` and ``j`` to the sorted sequence of keys such that ``i`` precedes ``j``,
``comp(*j, *i) == false``.
If no ``comp`` object is provided, keys are sorted with respect to ``std::less``.

Sorting is unstable. That means, keys, which do not precede one another with respect to the given
comparator, and their associated values might be ordered arbitrarily relative to each other.

``KeyIt`` and ``ValueIt`` must satisfy the requirements of ``ValueSwappable``,
and ``Comparator`` must satisfy the requirements for the ``Compare`` parameter of ``std::sort``,
as defined by the `C++ Standard`_.

.. code:: cpp

template<typename Policy, typename KeyIt, typename ValueIt,
typename Comparator = std::less<typename std::iterator_traits<InputIt>::value_type>>
void
stable_sort_by_key(Policy&& policy, KeyIt keys_first, KeyIt keys_last,
ValueIt values_first,
Comparator comp = std::less<typename std::iterator_traits<InputIt>::value_type>());

``oneapi::dpl::stable_sort_by_key`` sorts the sequence of keys ``[keys_first, keys_last)``
and simultaneously permutes associated values at the same positions in the range
``[values_first, values_first + std::distance(keys_first, keys_last))``
to match the order of the sorted keys.
dmitriy-sobolev marked this conversation as resolved.
Show resolved Hide resolved

Keys are sorted with respect to the provided comparator object ``comp``. That means, for any
two iterators ``i`` and ``j`` to the sorted sequence of keys such that ``i`` precedes ``j``,
``comp(*j, *i) == false``.
If no ``comp`` object is provided, keys are sorted with respect to ``std::less``.

Sorting is stable. That means, keys, which do not precede one another with respect to the given
comparator, and their associated values maintain the relative order as in the original sequences.

``KeyIt`` and ``ValueIt`` must satisfy the requirements of ``ValueSwappable``,
and ``Comparator`` must satisfy the requirements for the ``Compare`` parameter of ``std::sort``,
as defined by the `C++ Standard`_.

.. _`C++ Standard`: https://isocpp.org/std/the-standard
.. _`SYCL`: https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html