collections.pxd 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. from libc.stdint cimport uint32_t
  2. ctypedef void* (*mem_alloc_ft)(size_t size)
  3. ctypedef void* (*mem_calloc_ft)(size_t blocks, size_t size)
  4. ctypedef void (*mem_free_ft)(void* block)
  5. ctypedef size_t (*hash_ft)(const void* key, int l, uint32_t seed)
  6. ctypedef int (*key_compare_ft)(const void* key1, const void* key2)
  7. cdef extern from "common.h":
  8. cdef enum cc_stat:
  9. CC_OK
  10. CC_ERR_ALLOC
  11. CC_ERR_INVALID_CAPACITY
  12. CC_ERR_INVALID_RANGE
  13. CC_ERR_MAX_CAPACITY
  14. CC_ERR_KEY_NOT_FOUND
  15. CC_ERR_VALUE_NOT_FOUND
  16. CC_ERR_OUT_OF_RANGE
  17. CC_ITER_END
  18. CC_DUP_KEY
  19. #
  20. # int cc_common_cmp_str(const void* key1, const void* key2)
  21. #
  22. # int cc_common_cmp_ptr(const void* key1, const void* key2)
  23. #cdef extern from "array.h":
  24. # ctypedef struct Array:
  25. # pass
  26. #
  27. # ctypedef struct ArrayConf:
  28. # size_t capacity
  29. # float exp_factor
  30. # mem_alloc_ft mem_alloc
  31. # mem_calloc_ft mem_calloc
  32. # mem_free_ft mem_free
  33. #
  34. # ctypedef struct ArrayIter:
  35. # Array* ar
  36. # size_t index
  37. # bint last_removed
  38. #
  39. # ctypedef struct ArrayZipIter:
  40. # Array* ar1
  41. # Array* ar2
  42. # size_t index
  43. # bint last_removed
  44. #
  45. # cc_stat array_new(Array** out)
  46. #
  47. # cc_stat array_new_conf(ArrayConf* conf, Array** out)
  48. #
  49. # void array_conf_init(ArrayConf* conf)
  50. #
  51. # void array_destroy(Array* ar)
  52. #
  53. # ctypedef void (*_array_destroy_cb_cb_ft)(void*)
  54. #
  55. # void array_destroy_cb(Array* ar, _array_destroy_cb_cb_ft cb)
  56. #
  57. # #cc_stat array_add(Array* ar, void* element)
  58. #
  59. # #cc_stat array_add_at(Array* ar, void* element, size_t index)
  60. #
  61. # cc_stat array_replace_at(Array* ar, void* element, size_t index, void** out)
  62. #
  63. # cc_stat array_swap_at(Array* ar, size_t index1, size_t index2)
  64. #
  65. # cc_stat array_remove(Array* ar, void* element, void** out)
  66. #
  67. # cc_stat array_remove_at(Array* ar, size_t index, void** out)
  68. #
  69. # cc_stat array_remove_last(Array* ar, void** out)
  70. #
  71. # void array_remove_all(Array* ar)
  72. #
  73. # void array_remove_all_free(Array* ar)
  74. #
  75. # cc_stat array_get_at(Array* ar, size_t index, void** out)
  76. #
  77. # cc_stat array_get_last(Array* ar, void** out)
  78. #
  79. # cc_stat array_subarray(Array* ar, size_t from_, size_t to, Array** out)
  80. #
  81. # cc_stat array_copy_shallow(Array* ar, Array** out)
  82. #
  83. # ctypedef void* (*_array_copy_deep_cp_ft)(void*)
  84. #
  85. # cc_stat array_copy_deep(Array* ar, _array_copy_deep_cp_ft cp, Array** out)
  86. #
  87. # void array_reverse(Array* ar)
  88. #
  89. # cc_stat array_trim_capacity(Array* ar)
  90. #
  91. # size_t array_contains(Array* ar, void* element)
  92. #
  93. # ctypedef int (*_array_contains_value_cmp_ft)(void*, void*)
  94. #
  95. # size_t array_contains_value(Array* ar, void* element, _array_contains_value_cmp_ft cmp)
  96. #
  97. # size_t array_size(Array* ar)
  98. #
  99. # size_t array_capacity(Array* ar)
  100. #
  101. # cc_stat array_index_of(Array* ar, void* element, size_t* index)
  102. #
  103. # ctypedef int (*_array_sort_cmp_ft)(void*, void*)
  104. #
  105. # void array_sort(Array* ar, _array_sort_cmp_ft cmp)
  106. #
  107. # ctypedef void (*_array_map_fn_ft)(void*)
  108. #
  109. # void array_map(Array* ar, _array_map_fn_ft fn)
  110. #
  111. # ctypedef void (*_array_reduce_fn_ft)(void*, void*, void*)
  112. #
  113. # void array_reduce(Array* ar, _array_reduce_fn_ft fn, void* result)
  114. #
  115. # ctypedef bint (*_array_filter_mut_predicate_ft)(void*)
  116. #
  117. # cc_stat array_filter_mut(Array* ar, _array_filter_mut_predicate_ft predicate)
  118. #
  119. # ctypedef bint (*_array_filter_predicate_ft)(void*)
  120. #
  121. # cc_stat array_filter(Array* ar, _array_filter_predicate_ft predicate, Array** out)
  122. #
  123. # void array_iter_init(ArrayIter* iter, Array* ar)
  124. #
  125. # cc_stat array_iter_next(ArrayIter* iter, void** out)
  126. #
  127. # cc_stat array_iter_remove(ArrayIter* iter, void** out)
  128. #
  129. # cc_stat array_iter_add(ArrayIter* iter, void* element)
  130. #
  131. # cc_stat array_iter_replace(ArrayIter* iter, void* element, void** out)
  132. #
  133. # size_t array_iter_index(ArrayIter* iter)
  134. #
  135. # void array_zip_iter_init(ArrayZipIter* iter, Array* a1, Array* a2)
  136. #
  137. # cc_stat array_zip_iter_next(ArrayZipIter* iter, void** out1, void** out2)
  138. #
  139. # cc_stat array_zip_iter_add(ArrayZipIter* iter, void* e1, void* e2)
  140. #
  141. # cc_stat array_zip_iter_remove(ArrayZipIter* iter, void** out1, void** out2)
  142. #
  143. # cc_stat array_zip_iter_replace(ArrayZipIter* iter, void* e1, void* e2, void** out1, void** out2)
  144. #
  145. # size_t array_zip_iter_index(ArrayZipIter* iter)
  146. #
  147. # void** array_get_buffer(Array* ar)
  148. cdef extern from "hashtable.h":
  149. ctypedef struct TableEntry:
  150. void* key
  151. void* value
  152. size_t hash
  153. TableEntry* next
  154. ctypedef struct HashTable:
  155. pass
  156. ctypedef struct HashTableConf:
  157. float load_factor
  158. size_t initial_capacity
  159. int key_length
  160. uint32_t hash_seed
  161. hash_ft hash
  162. key_compare_ft key_compare
  163. mem_alloc_ft mem_alloc
  164. mem_calloc_ft mem_calloc
  165. mem_free_ft mem_free
  166. ctypedef struct HashTableIter:
  167. HashTable* table
  168. size_t bucket_index
  169. TableEntry* prev_entry
  170. TableEntry* next_entry
  171. # size_t get_table_index(HashTable *table, void *key)
  172. #
  173. # void hashtable_conf_init(HashTableConf* conf)
  174. #
  175. # cc_stat hashtable_new(HashTable** out)
  176. #
  177. # cc_stat hashtable_new_conf(HashTableConf* conf, HashTable** out)
  178. #
  179. # void hashtable_destroy(HashTable* table)
  180. #
  181. # cc_stat hashtable_add(HashTable* table, void* key, void* val)
  182. #
  183. # cc_stat hashtable_get(HashTable* table, void* key, void** out)
  184. #
  185. # cc_stat hashtable_remove(HashTable* table, void* key, void** out)
  186. #
  187. # void hashtable_remove_all(HashTable* table)
  188. #
  189. # bint hashtable_contains_key(HashTable* table, void* key)
  190. #
  191. # size_t hashtable_size(HashTable* table)
  192. #
  193. # size_t hashtable_capacity(HashTable* table)
  194. #
  195. # cc_stat hashtable_get_keys(HashTable* table, Array** out)
  196. #
  197. # cc_stat hashtable_get_values(HashTable* table, Array** out)
  198. #
  199. # size_t hashtable_hash_string(void* key, int len, uint32_t seed)
  200. #
  201. # size_t hashtable_hash(void* key, int len, uint32_t seed)
  202. #
  203. size_t hashtable_hash_ptr(void* key, int len, uint32_t seed)
  204. #
  205. # ctypedef void (*_hashtable_foreach_key_op_ft)(void*)
  206. #
  207. # void hashtable_foreach_key(HashTable* table, _hashtable_foreach_key_op_ft op)
  208. #
  209. # ctypedef void (*_hashtable_foreach_value_op_ft)(void*)
  210. #
  211. # void hashtable_foreach_value(HashTable* table, _hashtable_foreach_value_op_ft op)
  212. #
  213. # void hashtable_iter_init(HashTableIter* iter, HashTable* table)
  214. #
  215. # cc_stat hashtable_iter_next(HashTableIter* iter, TableEntry** out)
  216. #
  217. # cc_stat hashtable_iter_remove(HashTableIter* iter, void** out)
  218. cdef extern from "hashset.h":
  219. ctypedef struct HashSet:
  220. pass
  221. ctypedef HashTableConf HashSetConf
  222. ctypedef struct HashSetIter:
  223. HashTableIter iter
  224. void hashset_conf_init(HashSetConf* conf)
  225. cc_stat hashset_new(HashSet** hs)
  226. cc_stat hashset_new_conf(HashSetConf* conf, HashSet** hs)
  227. void hashset_destroy(HashSet* set)
  228. cc_stat hashset_add(HashSet* set, void* element)
  229. cc_stat hashset_add_or_get(HashSet* set, void** element)
  230. cc_stat hashset_remove(HashSet* set, void* element, void** out)
  231. void hashset_remove_all(HashSet* set)
  232. bint hashset_contains(HashSet* set, void* element)
  233. size_t hashset_size(HashSet* set)
  234. size_t hashset_capacity(HashSet* set)
  235. ctypedef void (*_hashset_foreach_op_ft)(void*)
  236. void hashset_foreach(HashSet* set, _hashset_foreach_op_ft op)
  237. void hashset_iter_init(HashSetIter* iter, HashSet* set)
  238. cc_stat hashset_iter_next(HashSetIter* iter, void** out)
  239. cc_stat hashset_iter_remove(HashSetIter* iter, void** out)