Skip to content

Commit 39e1261

Browse files
authored
CLN: Use signed integers in khash maps for signed integer keys (#38882)
1 parent 9dd17f2 commit 39e1261

File tree

4 files changed

+125
-122
lines changed

4 files changed

+125
-122
lines changed

pandas/_libs/khash.pxd

+26-26
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ from numpy cimport (
1818
cdef extern from "khash_python.h":
1919
const int KHASH_TRACE_DOMAIN
2020

21-
ctypedef uint32_t khint_t
22-
ctypedef khint_t khiter_t
21+
ctypedef uint32_t khuint_t
22+
ctypedef khuint_t khiter_t
2323

2424
ctypedef struct khcomplex128_t:
2525
double real
@@ -42,52 +42,52 @@ cdef extern from "khash_python.h":
4242
"kh_floats_hash_equal" (float32_t a, float32_t b) nogil
4343

4444
ctypedef struct kh_pymap_t:
45-
khint_t n_buckets, size, n_occupied, upper_bound
45+
khuint_t n_buckets, size, n_occupied, upper_bound
4646
uint32_t *flags
4747
PyObject **keys
4848
size_t *vals
4949

5050
kh_pymap_t* kh_init_pymap()
5151
void kh_destroy_pymap(kh_pymap_t*)
5252
void kh_clear_pymap(kh_pymap_t*)
53-
khint_t kh_get_pymap(kh_pymap_t*, PyObject*)
54-
void kh_resize_pymap(kh_pymap_t*, khint_t)
55-
khint_t kh_put_pymap(kh_pymap_t*, PyObject*, int*)
56-
void kh_del_pymap(kh_pymap_t*, khint_t)
53+
khuint_t kh_get_pymap(kh_pymap_t*, PyObject*)
54+
void kh_resize_pymap(kh_pymap_t*, khuint_t)
55+
khuint_t kh_put_pymap(kh_pymap_t*, PyObject*, int*)
56+
void kh_del_pymap(kh_pymap_t*, khuint_t)
5757

5858
bint kh_exist_pymap(kh_pymap_t*, khiter_t)
5959

6060
ctypedef struct kh_pyset_t:
61-
khint_t n_buckets, size, n_occupied, upper_bound
61+
khuint_t n_buckets, size, n_occupied, upper_bound
6262
uint32_t *flags
6363
PyObject **keys
6464
size_t *vals
6565

6666
kh_pyset_t* kh_init_pyset()
6767
void kh_destroy_pyset(kh_pyset_t*)
6868
void kh_clear_pyset(kh_pyset_t*)
69-
khint_t kh_get_pyset(kh_pyset_t*, PyObject*)
70-
void kh_resize_pyset(kh_pyset_t*, khint_t)
71-
khint_t kh_put_pyset(kh_pyset_t*, PyObject*, int*)
72-
void kh_del_pyset(kh_pyset_t*, khint_t)
69+
khuint_t kh_get_pyset(kh_pyset_t*, PyObject*)
70+
void kh_resize_pyset(kh_pyset_t*, khuint_t)
71+
khuint_t kh_put_pyset(kh_pyset_t*, PyObject*, int*)
72+
void kh_del_pyset(kh_pyset_t*, khuint_t)
7373

7474
bint kh_exist_pyset(kh_pyset_t*, khiter_t)
7575

7676
ctypedef char* kh_cstr_t
7777

7878
ctypedef struct kh_str_t:
79-
khint_t n_buckets, size, n_occupied, upper_bound
79+
khuint_t n_buckets, size, n_occupied, upper_bound
8080
uint32_t *flags
8181
kh_cstr_t *keys
8282
size_t *vals
8383

8484
kh_str_t* kh_init_str() nogil
8585
void kh_destroy_str(kh_str_t*) nogil
8686
void kh_clear_str(kh_str_t*) nogil
87-
khint_t kh_get_str(kh_str_t*, kh_cstr_t) nogil
88-
void kh_resize_str(kh_str_t*, khint_t) nogil
89-
khint_t kh_put_str(kh_str_t*, kh_cstr_t, int*) nogil
90-
void kh_del_str(kh_str_t*, khint_t) nogil
87+
khuint_t kh_get_str(kh_str_t*, kh_cstr_t) nogil
88+
void kh_resize_str(kh_str_t*, khuint_t) nogil
89+
khuint_t kh_put_str(kh_str_t*, kh_cstr_t, int*) nogil
90+
void kh_del_str(kh_str_t*, khuint_t) nogil
9191

9292
bint kh_exist_str(kh_str_t*, khiter_t) nogil
9393

@@ -96,27 +96,27 @@ cdef extern from "khash_python.h":
9696
int starts[256]
9797

9898
kh_str_starts_t* kh_init_str_starts() nogil
99-
khint_t kh_put_str_starts_item(kh_str_starts_t* table, char* key,
100-
int* ret) nogil
101-
khint_t kh_get_str_starts_item(kh_str_starts_t* table, char* key) nogil
99+
khuint_t kh_put_str_starts_item(kh_str_starts_t* table, char* key,
100+
int* ret) nogil
101+
khuint_t kh_get_str_starts_item(kh_str_starts_t* table, char* key) nogil
102102
void kh_destroy_str_starts(kh_str_starts_t*) nogil
103-
void kh_resize_str_starts(kh_str_starts_t*, khint_t) nogil
103+
void kh_resize_str_starts(kh_str_starts_t*, khuint_t) nogil
104104

105105
# sweep factorize
106106

107107
ctypedef struct kh_strbox_t:
108-
khint_t n_buckets, size, n_occupied, upper_bound
108+
khuint_t n_buckets, size, n_occupied, upper_bound
109109
uint32_t *flags
110110
kh_cstr_t *keys
111111
PyObject **vals
112112

113113
kh_strbox_t* kh_init_strbox() nogil
114114
void kh_destroy_strbox(kh_strbox_t*) nogil
115115
void kh_clear_strbox(kh_strbox_t*) nogil
116-
khint_t kh_get_strbox(kh_strbox_t*, kh_cstr_t) nogil
117-
void kh_resize_strbox(kh_strbox_t*, khint_t) nogil
118-
khint_t kh_put_strbox(kh_strbox_t*, kh_cstr_t, int*) nogil
119-
void kh_del_strbox(kh_strbox_t*, khint_t) nogil
116+
khuint_t kh_get_strbox(kh_strbox_t*, kh_cstr_t) nogil
117+
void kh_resize_strbox(kh_strbox_t*, khuint_t) nogil
118+
khuint_t kh_put_strbox(kh_strbox_t*, kh_cstr_t, int*) nogil
119+
void kh_del_strbox(kh_strbox_t*, khuint_t) nogil
120120

121121
bint kh_exist_strbox(kh_strbox_t*, khiter_t) nogil
122122

pandas/_libs/khash_for_primitive_helper.pxi.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ primitive_types = [('int64', 'int64_t'),
2626

2727
cdef extern from "khash_python.h":
2828
ctypedef struct kh_{{name}}_t:
29-
khint_t n_buckets, size, n_occupied, upper_bound
29+
khuint_t n_buckets, size, n_occupied, upper_bound
3030
uint32_t *flags
3131
{{c_type}} *keys
3232
size_t *vals
3333

3434
kh_{{name}}_t* kh_init_{{name}}() nogil
3535
void kh_destroy_{{name}}(kh_{{name}}_t*) nogil
3636
void kh_clear_{{name}}(kh_{{name}}_t*) nogil
37-
khint_t kh_get_{{name}}(kh_{{name}}_t*, {{c_type}}) nogil
38-
void kh_resize_{{name}}(kh_{{name}}_t*, khint_t) nogil
39-
khint_t kh_put_{{name}}(kh_{{name}}_t*, {{c_type}}, int*) nogil
40-
void kh_del_{{name}}(kh_{{name}}_t*, khint_t) nogil
37+
khuint_t kh_get_{{name}}(kh_{{name}}_t*, {{c_type}}) nogil
38+
void kh_resize_{{name}}(kh_{{name}}_t*, khuint_t) nogil
39+
khuint_t kh_put_{{name}}(kh_{{name}}_t*, {{c_type}}, int*) nogil
40+
void kh_del_{{name}}(kh_{{name}}_t*, khuint_t) nogil
4141

4242
bint kh_exist_{{name}}(kh_{{name}}_t*, khiter_t) nogil
4343

0 commit comments

Comments
 (0)