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
cc511a3d
Commit
cc511a3d
authored
Feb 01, 2013
by
Yury V. Zaytsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update code samples to use newer Cython / Python syntax
parent
6d343f58
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
docs/src/tutorial/queue_example/queue.pyx
docs/src/tutorial/queue_example/queue.pyx
+13
-11
No files found.
docs/src/tutorial/queue_example/queue.pyx
View file @
cc511a3d
...
...
@@ -2,11 +2,13 @@ cimport cqueue
cimport
python_exc
cdef
class
Queue
:
cdef
cqueue
.
Queue
*
_c_queue
def
__cinit__
(
self
):
self
.
_c_queue
=
cqueue
.
queue_new
()
if
self
.
_c_queue
is
NULL
:
python_exc
.
PyErr_NoMemory
()
raise
MemoryError
()
def
__dealloc__
(
self
):
if
self
.
_c_queue
is
not
NULL
:
...
...
@@ -14,14 +16,14 @@ cdef class Queue:
cpdef
int
append
(
self
,
int
value
)
except
-
1
:
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
value
):
python_exc
.
PyErr_NoMemory
()
raise
MemoryError
()
return
0
cdef
int
extend
(
self
,
int
*
values
,
Py_ssize_t
count
)
except
-
1
:
cdef
Py_ssize_t
i
for
i
in
x
range
(
count
):
for
i
in
range
(
count
):
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
values
[
i
]):
python_exc
.
PyErr_NoMemory
()
raise
MemoryError
()
return
0
cpdef
int
peek
(
self
)
except
?
0
:
...
...
@@ -42,7 +44,7 @@ cdef class Queue:
raise
IndexError
(
"Queue is empty"
)
return
value
def
__
nonzero
__
(
self
):
def
__
bool
__
(
self
):
return
not
cqueue
.
queue_is_empty
(
self
.
_c_queue
)
DEF
repeat_count
=
10000
...
...
@@ -50,9 +52,9 @@ DEF repeat_count=10000
def
test_cy
():
cdef
int
i
cdef
Queue
q
=
Queue
()
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
append
(
i
)
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
peek
()
while
q
:
q
.
pop
()
...
...
@@ -60,9 +62,9 @@ def test_cy():
def
test_py
():
cdef
int
i
q
=
Queue
()
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
append
(
i
)
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
peek
()
while
q
:
q
.
pop
()
...
...
@@ -72,9 +74,9 @@ from collections import deque
def
test_deque
():
cdef
int
i
q
=
deque
()
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
appendleft
(
i
)
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
[
-
1
]
while
q
:
q
.
pop
()
...
...
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