khash.pxd 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. from cpython.object cimport PyObject
  2. from numpy cimport (
  3. complex64_t,
  4. complex128_t,
  5. float32_t,
  6. float64_t,
  7. int8_t,
  8. int16_t,
  9. int32_t,
  10. int64_t,
  11. uint8_t,
  12. uint16_t,
  13. uint32_t,
  14. uint64_t,
  15. )
  16. cdef extern from "khash_python.h":
  17. const int KHASH_TRACE_DOMAIN
  18. ctypedef uint32_t khuint_t
  19. ctypedef khuint_t khiter_t
  20. ctypedef struct khcomplex128_t:
  21. double real
  22. double imag
  23. bint are_equivalent_khcomplex128_t \
  24. "kh_complex_hash_equal" (khcomplex128_t a, khcomplex128_t b) nogil
  25. ctypedef struct khcomplex64_t:
  26. float real
  27. float imag
  28. bint are_equivalent_khcomplex64_t \
  29. "kh_complex_hash_equal" (khcomplex64_t a, khcomplex64_t b) nogil
  30. bint are_equivalent_float64_t \
  31. "kh_floats_hash_equal" (float64_t a, float64_t b) nogil
  32. bint are_equivalent_float32_t \
  33. "kh_floats_hash_equal" (float32_t a, float32_t b) nogil
  34. uint32_t kh_python_hash_func(object key)
  35. bint kh_python_hash_equal(object a, object b)
  36. ctypedef struct kh_pymap_t:
  37. khuint_t n_buckets, size, n_occupied, upper_bound
  38. uint32_t *flags
  39. PyObject **keys
  40. size_t *vals
  41. kh_pymap_t* kh_init_pymap()
  42. void kh_destroy_pymap(kh_pymap_t*)
  43. void kh_clear_pymap(kh_pymap_t*)
  44. khuint_t kh_get_pymap(kh_pymap_t*, PyObject*)
  45. void kh_resize_pymap(kh_pymap_t*, khuint_t)
  46. khuint_t kh_put_pymap(kh_pymap_t*, PyObject*, int*)
  47. void kh_del_pymap(kh_pymap_t*, khuint_t)
  48. bint kh_exist_pymap(kh_pymap_t*, khiter_t)
  49. ctypedef struct kh_pyset_t:
  50. khuint_t n_buckets, size, n_occupied, upper_bound
  51. uint32_t *flags
  52. PyObject **keys
  53. size_t *vals
  54. kh_pyset_t* kh_init_pyset()
  55. void kh_destroy_pyset(kh_pyset_t*)
  56. void kh_clear_pyset(kh_pyset_t*)
  57. khuint_t kh_get_pyset(kh_pyset_t*, PyObject*)
  58. void kh_resize_pyset(kh_pyset_t*, khuint_t)
  59. khuint_t kh_put_pyset(kh_pyset_t*, PyObject*, int*)
  60. void kh_del_pyset(kh_pyset_t*, khuint_t)
  61. bint kh_exist_pyset(kh_pyset_t*, khiter_t)
  62. ctypedef char* kh_cstr_t
  63. ctypedef struct kh_str_t:
  64. khuint_t n_buckets, size, n_occupied, upper_bound
  65. uint32_t *flags
  66. kh_cstr_t *keys
  67. size_t *vals
  68. kh_str_t* kh_init_str() nogil
  69. void kh_destroy_str(kh_str_t*) nogil
  70. void kh_clear_str(kh_str_t*) nogil
  71. khuint_t kh_get_str(kh_str_t*, kh_cstr_t) nogil
  72. void kh_resize_str(kh_str_t*, khuint_t) nogil
  73. khuint_t kh_put_str(kh_str_t*, kh_cstr_t, int*) nogil
  74. void kh_del_str(kh_str_t*, khuint_t) nogil
  75. bint kh_exist_str(kh_str_t*, khiter_t) nogil
  76. ctypedef struct kh_str_starts_t:
  77. kh_str_t *table
  78. int starts[256]
  79. kh_str_starts_t* kh_init_str_starts() nogil
  80. khuint_t kh_put_str_starts_item(kh_str_starts_t* table, char* key,
  81. int* ret) nogil
  82. khuint_t kh_get_str_starts_item(kh_str_starts_t* table, char* key) nogil
  83. void kh_destroy_str_starts(kh_str_starts_t*) nogil
  84. void kh_resize_str_starts(kh_str_starts_t*, khuint_t) nogil
  85. # sweep factorize
  86. ctypedef struct kh_strbox_t:
  87. khuint_t n_buckets, size, n_occupied, upper_bound
  88. uint32_t *flags
  89. kh_cstr_t *keys
  90. PyObject **vals
  91. kh_strbox_t* kh_init_strbox() nogil
  92. void kh_destroy_strbox(kh_strbox_t*) nogil
  93. void kh_clear_strbox(kh_strbox_t*) nogil
  94. khuint_t kh_get_strbox(kh_strbox_t*, kh_cstr_t) nogil
  95. void kh_resize_strbox(kh_strbox_t*, khuint_t) nogil
  96. khuint_t kh_put_strbox(kh_strbox_t*, kh_cstr_t, int*) nogil
  97. void kh_del_strbox(kh_strbox_t*, khuint_t) nogil
  98. bint kh_exist_strbox(kh_strbox_t*, khiter_t) nogil
  99. khuint_t kh_needed_n_buckets(khuint_t element_n) nogil
  100. include "khash_for_primitive_helper.pxi"