1 cdef extern from "stdlib.h":
3 void *malloc
(size_t size
)
5 cdef extern from "Python.h":
8 cdef extern from "stdint.h":
9 ctypedef long long int64_t
10 ctypedef int64_t sympyint
12 cdef extern from "glib.h":
13 ctypedef unsigned guint
14 ctypedef void *gconstpointer
15 ctypedef void *gpointer
17 guint g_int_hash
(gconstpointer v
)
18 guint g_str_hash
(gconstpointer v
)
20 ctypedef struct GHashTable
21 ctypedef struct GHashTableIter
:
23 #guint (*GHashFunc) (gconstpointer key)
24 #gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b)
25 ctypedef void * GHashFunc
26 ctypedef void * GEqualFunc
28 GHashTable
*g_hash_table_new
(GHashFunc hash_func
, GEqualFunc key_equal_func
)
29 void g_hash_table_insert
(GHashTable
*hash_table
,
30 gpointer key
, gpointer value
)
31 void g_hash_table_destroy
(GHashTable
*hash_table
)
32 void g_hash_table_iter_init
(GHashTableIter
*iter
, GHashTable
*hash_table
)
33 gboolean g_hash_table_iter_next
(GHashTableIter
*iter
,
34 gpointer
*key
, gpointer
*value
)
39 def str_hash
(char *v
):
43 cdef GHashTable
*thisptr
46 self.thisptr
= g_hash_table_new
(NULL
, NULL
)
48 def __dealloc__
(self):
49 g_hash_table_destroy
(self.thisptr
)
51 def insert
(self, key
, coeff
):
52 g_hash_table_insert
(self.thisptr
, <gpointer
>key
, <gpointer
>coeff
)
55 cdef GHashTableIter iter
57 g_hash_table_iter_init
(&iter
, self.thisptr
);
58 cdef gpointer key
, value
61 while g_hash_table_iter_next
(&iter
, &key
, &value
):
62 a
.append
((<object>key
, <object>value
))
65 cdef guint my_hash
(gconstpointer v
):
69 cdef gboolean my_equal
(gconstpointer a
, gconstpointer b
):
75 cdef class HashTable
(Table
):
78 self.thisptr
= g_hash_table_new
(&my_hash
, &my_equal
)