summaryrefslogtreecommitdiff
path: root/coverage/numbits.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2019-07-31 10:18:43 -0400
committerNed Batchelder <ned@nedbatchelder.com>2019-07-31 10:24:39 -0400
commit66fb5e7bda44ac9f7b2d86687c96a34a0d632010 (patch)
tree05a41882e9c248cd37f0be2ac54fd84cd2f7fc2b /coverage/numbits.py
parentcb4080d565ddb1232674affb051944522ca37aee (diff)
downloadpython-coveragepy-git-66fb5e7bda44ac9f7b2d86687c96a34a0d632010.tar.gz
Add numbits_any_intersection
Diffstat (limited to 'coverage/numbits.py')
-rw-r--r--coverage/numbits.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/coverage/numbits.py b/coverage/numbits.py
index bc29ed94..19c328c4 100644
--- a/coverage/numbits.py
+++ b/coverage/numbits.py
@@ -40,3 +40,9 @@ def merge_numbits(numbits1, numbits2):
"""Merge two numbits"""
byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
return binary_bytes(b1 | b2 for b1, b2 in byte_pairs)
+
+@contract(numbits1='bytes', numbits2='bytes', returns='bool')
+def numbits_any_intersection(numbits1, numbits2):
+ """Is there any number that appears in both numbits?"""
+ byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0)
+ return any(b1 & b2 for b1, b2 in byte_pairs)