@@ -392,9 +392,8 @@ cdef class {{name}}HashTable(HashTable):
392
392
393
393
def __cinit__(self, int64_t size_hint=1):
394
394
self.table = kh_init_{{dtype}}()
395
- if size_hint is not None:
396
- size_hint = min(size_hint, SIZE_HINT_LIMIT)
397
- kh_resize_{{dtype}}(self.table, size_hint)
395
+ size_hint = min(kh_needed_n_buckets(size_hint), SIZE_HINT_LIMIT)
396
+ kh_resize_{{dtype}}(self.table, size_hint)
398
397
399
398
def __len__(self) -> int:
400
399
return self.table.size
@@ -740,9 +739,8 @@ cdef class StringHashTable(HashTable):
740
739
741
740
def __init__(self, int64_t size_hint=1):
742
741
self.table = kh_init_str()
743
- if size_hint is not None:
744
- size_hint = min(size_hint, SIZE_HINT_LIMIT)
745
- kh_resize_str(self.table, size_hint)
742
+ size_hint = min(kh_needed_n_buckets(size_hint), SIZE_HINT_LIMIT)
743
+ kh_resize_str(self.table, size_hint)
746
744
747
745
def __dealloc__(self):
748
746
if self.table is not NULL:
@@ -1062,9 +1060,8 @@ cdef class PyObjectHashTable(HashTable):
1062
1060
1063
1061
def __init__(self, int64_t size_hint=1):
1064
1062
self.table = kh_init_pymap()
1065
- if size_hint is not None:
1066
- size_hint = min(size_hint, SIZE_HINT_LIMIT)
1067
- kh_resize_pymap(self.table, size_hint)
1063
+ size_hint = min(kh_needed_n_buckets(size_hint), SIZE_HINT_LIMIT)
1064
+ kh_resize_pymap(self.table, size_hint)
1068
1065
1069
1066
def __dealloc__(self):
1070
1067
if self.table is not NULL:
0 commit comments