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
Gwenaël Samain
cython
Commits
b4d4edaa
Commit
b4d4edaa
authored
Jul 30, 2014
by
Lars Buitinck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for C++ stdlib heap operations
parent
2b3e048e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
0 deletions
+43
-0
CHANGES.rst
CHANGES.rst
+2
-0
Cython/Includes/libcpp/algorithm.pxd
Cython/Includes/libcpp/algorithm.pxd
+12
-0
tests/run/libcpp_algo.pyx
tests/run/libcpp_algo.pyx
+29
-0
No files found.
CHANGES.rst
View file @
b4d4edaa
...
...
@@ -47,6 +47,8 @@ Features added
* Defines dynamic_cast et al. in `libcpp.cast`.
* Support for C++ heap data structure operations (from ``<algorithm>``).
Optimizations
-------------
...
...
Cython/Includes/libcpp/algorithm.pxd
0 → 100644
View file @
b4d4edaa
cdef
extern
from
"<algorithm>"
namespace
"std"
nogil
:
void
make_heap
[
Iter
](
Iter
first
,
Iter
last
)
void
make_heap
[
Iter
,
Compare
](
Iter
first
,
Iter
last
,
Compare
comp
)
void
pop_heap
[
Iter
](
Iter
first
,
Iter
last
)
void
pop_heap
[
Iter
,
Compare
](
Iter
first
,
Iter
last
,
Compare
comp
)
void
push_heap
[
Iter
](
Iter
first
,
Iter
last
)
void
push_heap
[
Iter
,
Compare
](
Iter
first
,
Iter
last
,
Compare
comp
)
void
sort_heap
[
Iter
](
Iter
first
,
Iter
last
)
void
sort_heap
[
Iter
,
Compare
](
Iter
first
,
Iter
last
,
Compare
comp
)
tests/run/libcpp_algo.pyx
0 → 100644
View file @
b4d4edaa
# tag: cpp
from
libcpp
cimport
bool
from
libcpp.algorithm
cimport
make_heap
,
sort_heap
from
libcpp.vector
cimport
vector
# XXX should use std::greater, but I don't know how to wrap that.
cdef
inline
bool
greater
(
int
x
,
int
y
):
return
x
>
y
def
heapsort
(
l
,
bool
reverse
=
False
):
"""
>>> heapsort([3, 5, 1, 0, 2, 4])
[0, 1, 2, 3, 4, 5]
>>> heapsort([3, 5, 1, 0, 2, 4], reverse=True)
[5, 4, 3, 2, 1, 0]
"""
cdef
vector
[
int
]
v
=
l
if
reverse
:
make_heap
(
v
.
begin
(),
v
.
end
(),
greater
)
sort_heap
(
v
.
begin
(),
v
.
end
(),
greater
)
else
:
make_heap
(
v
.
begin
(),
v
.
end
())
sort_heap
(
v
.
begin
(),
v
.
end
())
return
v
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