| 1 |
# distutils: language = c++ |
| 2 |
# distutils: sources = heap.cpp |
| 3 |
|
| 4 |
from libcpp cimport bool |
| 5 |
|
| 6 |
cdef extern from "heap.h": |
| 7 |
cdef cppclass heap: |
| 8 |
heap(int, bool) except + |
| 9 |
int push(int, double) except + |
| 10 |
void pop(int *, double *) except + |
| 11 |
void set(int, double) except + |
| 12 |
bool empty() |
| 13 |
double peek() except + |
| 14 |
|
| 15 |
cdef class pheap: |
| 16 |
cdef heap *thisptr |
| 17 |
def __cinit__(self, n, self_test): |
| 18 |
self.thisptr = new heap(n, self_test) |
| 19 |
|
| 20 |
def __dealloc__(self): |
| 21 |
del self.thisptr |
| 22 |
|
| 23 |
def _push(self, addr, value): |
| 24 |
return self.thisptr.push(addr, value) |
| 25 |
|
| 26 |
def _pop(self): |
| 27 |
cdef int addr |
| 28 |
cdef double value |
| 29 |
self.thisptr.pop(&addr, &value) |
| 30 |
return addr, value |
| 31 |
|
| 32 |
def _set(self, addr, value): |
| 33 |
self.thisptr.set(addr, value) |
| 34 |
|
| 35 |
def _empty(self): |
| 36 |
return self.thisptr.empty() |
| 37 |
|
| 38 |
def _peek(self): |
| 39 |
cdef double dist |
| 40 |
return self.thisptr.peek() |