Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
78886392
Commit
78886392
authored
Jul 18, 2021
by
da-woods
Committed by
GitHub
Jul 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing "max_element()" in libcpp.algorithms (GH-4271)
parent
47850c40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
Cython/Includes/libcpp/algorithm.pxd
Cython/Includes/libcpp/algorithm.pxd
+2
-0
tests/run/cpp_stl_algo_modifying_sequence_ops.pyx
tests/run/cpp_stl_algo_modifying_sequence_ops.pyx
+6
-4
No files found.
Cython/Includes/libcpp/algorithm.pxd
View file @
78886392
...
...
@@ -245,6 +245,8 @@ cdef extern from "<algorithm>" namespace "std" nogil:
# Minimum/maximum operations
Iter
min_element
[
Iter
](
Iter
first
,
Iter
last
)
except
+
Iter
min_element
[
ExecutionPolicy
,
Iter
](
ExecutionPolicy
&&
policy
,
Iter
first
,
Iter
last
)
except
+
Iter
max_element
[
Iter
](
Iter
first
,
Iter
last
)
except
+
Iter
max_element
[
ExecutionPolicy
,
Iter
](
ExecutionPolicy
&&
policy
,
Iter
first
,
Iter
last
)
except
+
# Comparison operations
...
...
tests/run/cpp_stl_algo_modifying_sequence_ops.pyx
View file @
78886392
...
...
@@ -10,7 +10,7 @@ from libcpp.algorithm cimport copy, copy_if, copy_n, copy_backward, move, move_b
from
libcpp.algorithm
cimport
generate
,
generate_n
,
remove
,
remove_if
,
remove_copy
,
remove_copy_if
,
replace
,
replace_if
from
libcpp.algorithm
cimport
replace_copy
,
replace_copy_if
,
swap
,
swap_ranges
,
iter_swap
,
reverse
,
reverse_copy
from
libcpp.algorithm
cimport
rotate
,
rotate_copy
,
unique
,
unique_copy
from
libcpp.algorithm
cimport
sort
,
upper_bound
,
min_element
from
libcpp.algorithm
cimport
sort
,
upper_bound
,
min_element
,
max_element
from
libcpp.iterator
cimport
back_inserter
from
libcpp.string
cimport
string
from
libcpp.vector
cimport
vector
...
...
@@ -316,17 +316,19 @@ def test_swap_ranges():
print
(
a
,
b
)
def
selection_sort
(
vector
[
int
]
values
):
def
selection_sort
(
vector
[
int
]
values
,
reversed
=
False
):
"""
Test iter_swap using cppreference example.
Test iter_swap using cppreference example.
Extra "reversed argument tests max_element
>>> selection_sort([-7, 6, 2, 4, -1, 6, -9, -1, 2, -5, 10, -9, -5, -3, -5, -3, 6, 6, 1, 8])
[-9, -9, -7, -5, -5, -5, -3, -3, -1, -1, 1, 2, 2, 4, 6, 6, 6, 6, 8, 10]
>>> selection_sort([-7, 6, 2, 4, -1, 6, -9, -1, 2, -5, 10, -9, -5, -3, -5, -3, 6, 6, 1, 8], reversed=True)
[10, 8, 6, 6, 6, 6, 4, 2, 2, 1, -1, -1, -3, -3, -5, -5, -5, -7, -9, -9]
"""
i
=
values
.
begin
()
end
=
values
.
end
()
while
i
<
end
:
iter_swap
(
i
,
min_element
(
i
,
end
))
iter_swap
(
i
,
min_element
(
i
,
end
)
if
not
reversed
else
max_element
(
i
,
end
)
)
preincrement
(
i
)
return
values
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment