Skip to content

Commit a2e5679

Browse files
committed
adding comment why unsigned int is used for maps
1 parent 6d026b2 commit a2e5679

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/_libs/src/klib/khash.h

+7
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ PANDAS_INLINE khint_t __ac_Wang_hash(khint_t key)
599599
@param name Name of the hash table [symbol]
600600
@param khval_t Type of values [type]
601601
*/
602+
603+
// we implicitly convert signed int to unsigned int, thus potential overflows
604+
// for operations (<<,*,+) don't trigger undefined behavior, also >>-operator
605+
// is implementation defined for signed ints if sign-bit is set.
606+
// because we never really "get" the keys, there will be no convertion from
607+
// unsigend int to (signed) int (which would be implementation defined behavior)
608+
// this holds also for 16- and 8-bit integers
602609
#define KHASH_MAP_INIT_INT(name, khval_t) \
603610
KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal)
604611

0 commit comments

Comments
 (0)