summaryrefslogtreecommitdiffstats
path: root/contrib/python/fonttools/fontTools/misc/intTools.py
diff options
context:
space:
mode:
authorshumkovnd <[email protected]>2023-11-10 14:39:34 +0300
committershumkovnd <[email protected]>2023-11-10 16:42:24 +0300
commit77eb2d3fdcec5c978c64e025ced2764c57c00285 (patch)
treec51edb0748ca8d4a08d7c7323312c27ba1a8b79a /contrib/python/fonttools/fontTools/misc/intTools.py
parentdd6d20cadb65582270ac23f4b3b14ae189704b9d (diff)
KIKIMR-19287: add task_stats_drawing script
Diffstat (limited to 'contrib/python/fonttools/fontTools/misc/intTools.py')
-rw-r--r--contrib/python/fonttools/fontTools/misc/intTools.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/contrib/python/fonttools/fontTools/misc/intTools.py b/contrib/python/fonttools/fontTools/misc/intTools.py
new file mode 100644
index 00000000000..0ca29854aae
--- /dev/null
+++ b/contrib/python/fonttools/fontTools/misc/intTools.py
@@ -0,0 +1,25 @@
+__all__ = ["popCount", "bit_count", "bit_indices"]
+
+
+try:
+ bit_count = int.bit_count
+except AttributeError:
+
+ def bit_count(v):
+ return bin(v).count("1")
+
+
+"""Return number of 1 bits (population count) of the absolute value of an integer.
+
+See https://docs.python.org/3.10/library/stdtypes.html#int.bit_count
+"""
+popCount = bit_count # alias
+
+
+def bit_indices(v):
+ """Return list of indices where bits are set, 0 being the index of the least significant bit.
+
+ >>> bit_indices(0b101)
+ [0, 2]
+ """
+ return [i for i, b in enumerate(bin(v)[::-1]) if b == "1"]