diff options
Diffstat (limited to 'docs/examples/tutorial/clibraries/queue3.pyx')
-rw-r--r-- | docs/examples/tutorial/clibraries/queue3.pyx | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/docs/examples/tutorial/clibraries/queue3.pyx b/docs/examples/tutorial/clibraries/queue3.pyx index cc84cf172..c15c48e15 100644 --- a/docs/examples/tutorial/clibraries/queue3.pyx +++ b/docs/examples/tutorial/clibraries/queue3.pyx @@ -1,7 +1,7 @@ -# queue.pyx - cimport cqueue + + cdef class Queue: """A queue class for C integer values. @@ -22,6 +22,7 @@ cdef class Queue: if self._c_queue is not NULL: cqueue.queue_free(self._c_queue) + cpdef append(self, int value): if not cqueue.queue_push_tail(self._c_queue, <void*> <Py_ssize_t> value): @@ -33,15 +34,19 @@ cdef class Queue: # the C-ish "extend()" method to e.g. "extend_ints()", and write # a new "extend()" method that provides a suitable Python interface by # accepting an arbitrary Python iterable. + cpdef extend(self, values): for value in values: self.append(value) + cdef extend_ints(self, int* values, size_t count): cdef int value for value in values[:count]: # Slicing pointer to limit the iteration boundaries. self.append(value) + + cpdef int peek(self) except? -1: cdef int value = <Py_ssize_t> cqueue.queue_peek_head(self._c_queue) @@ -52,6 +57,8 @@ cdef class Queue: raise IndexError("Queue is empty") return value + + cpdef int pop(self) except? -1: if cqueue.queue_is_empty(self._c_queue): raise IndexError("Queue is empty") |