2018-11-10 15:16:52 -05:00
|
|
|
__all__ = ['popCount']
|
|
|
|
|
|
|
|
|
2021-06-04 10:03:21 -06:00
|
|
|
try:
|
|
|
|
bit_count = int.bit_count
|
|
|
|
except AttributeError:
|
|
|
|
def bit_count(v):
|
|
|
|
return bin(v).count('1')
|
2020-06-08 15:53:48 +01:00
|
|
|
|
2021-06-04 10:03:21 -06:00
|
|
|
"""Return number of 1 bits (population count) of the absolute value of an integer.
|
2020-06-08 15:53:48 +01:00
|
|
|
|
2021-06-04 10:03:21 -06:00
|
|
|
See https://docs.python.org/3.10/library/stdtypes.html#int.bit_count
|
|
|
|
"""
|
|
|
|
popCount = bit_count
|