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
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
...
@@ -2,11 +2,13 @@ cimport cqueue
cimport
python_exc
cimport
python_exc
cdef
class
Queue
:
cdef
class
Queue
:
cdef
cqueue
.
Queue
*
_c_queue
cdef
cqueue
.
Queue
*
_c_queue
def
__cinit__
(
self
):
def
__cinit__
(
self
):
self
.
_c_queue
=
cqueue
.
queue_new
()
self
.
_c_queue
=
cqueue
.
queue_new
()
if
self
.
_c_queue
is
NULL
:
if
self
.
_c_queue
is
NULL
:
python_exc
.
PyErr_NoMemory
()
raise
MemoryError
()
def
__dealloc__
(
self
):
def
__dealloc__
(
self
):
if
self
.
_c_queue
is
not
NULL
:
if
self
.
_c_queue
is
not
NULL
:
...
@@ -14,14 +16,14 @@ cdef class Queue:
...
@@ -14,14 +16,14 @@ cdef class Queue:
cpdef
int
append
(
self
,
int
value
)
except
-
1
:
cpdef
int
append
(
self
,
int
value
)
except
-
1
:
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
value
):
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
value
):
python_exc
.
PyErr_NoMemory
()
raise
MemoryError
()
return
0
return
0
cdef
int
extend
(
self
,
int
*
values
,
Py_ssize_t
count
)
except
-
1
:
cdef
int
extend
(
self
,
int
*
values
,
Py_ssize_t
count
)
except
-
1
:
cdef
Py_ssize_t
i
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
]):
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
values
[
i
]):
python_exc
.
PyErr_NoMemory
()
raise
MemoryError
()
return
0
return
0
cpdef
int
peek
(
self
)
except
?
0
:
cpdef
int
peek
(
self
)
except
?
0
:
...
@@ -42,7 +44,7 @@ cdef class Queue:
...
@@ -42,7 +44,7 @@ cdef class Queue:
raise
IndexError
(
"Queue is empty"
)
raise
IndexError
(
"Queue is empty"
)
return
value
return
value
def
__
nonzero
__
(
self
):
def
__
bool
__
(
self
):
return
not
cqueue
.
queue_is_empty
(
self
.
_c_queue
)
return
not
cqueue
.
queue_is_empty
(
self
.
_c_queue
)
DEF
repeat_count
=
10000
DEF
repeat_count
=
10000
...
@@ -50,9 +52,9 @@ DEF repeat_count=10000
...
@@ -50,9 +52,9 @@ DEF repeat_count=10000
def
test_cy
():
def
test_cy
():
cdef
int
i
cdef
int
i
cdef
Queue
q
=
Queue
()
cdef
Queue
q
=
Queue
()
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
append
(
i
)
q
.
append
(
i
)
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
peek
()
q
.
peek
()
while
q
:
while
q
:
q
.
pop
()
q
.
pop
()
...
@@ -60,9 +62,9 @@ def test_cy():
...
@@ -60,9 +62,9 @@ def test_cy():
def
test_py
():
def
test_py
():
cdef
int
i
cdef
int
i
q
=
Queue
()
q
=
Queue
()
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
append
(
i
)
q
.
append
(
i
)
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
peek
()
q
.
peek
()
while
q
:
while
q
:
q
.
pop
()
q
.
pop
()
...
@@ -72,9 +74,9 @@ from collections import deque
...
@@ -72,9 +74,9 @@ from collections import deque
def
test_deque
():
def
test_deque
():
cdef
int
i
cdef
int
i
q
=
deque
()
q
=
deque
()
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
.
appendleft
(
i
)
q
.
appendleft
(
i
)
for
i
in
x
range
(
repeat_count
):
for
i
in
range
(
repeat_count
):
q
[
-
1
]
q
[
-
1
]
while
q
:
while
q
:
q
.
pop
()
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