def numbits_union(numbits1, numbits2): """Compute the union of two numbits. Returns: A new numbits, the union of `numbits1` and `numbits2`. """ byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0) return _to_blob(binary_bytes(b1 | b2 for b1, b2 in byte_pairs))
def numbits_intersection(numbits1, numbits2): """Compute the intersection of two numbits. Returns: A new numbits, the intersection `numbits1` and `numbits2`. """ byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0) intersection_bytes = binary_bytes(b1 & b2 for b1, b2 in byte_pairs) return _to_blob(intersection_bytes.rstrip(b'\0'))
def numbits_any_intersection(numbits1, numbits2): """Is there any number that appears in both numbits? Determine whether two number sets have a non-empty intersection. This is faster than computing the intersection. Returns: A bool, True if there is any number in both `numbits1` and `numbits2`. """ byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0) return any(b1 & b2 for b1, b2 in byte_pairs)
def numbits_union(numbits1, numbits2): """Compute the union of two numbits. Arguments: numbits1, numbits2: packed number sets. Returns: A new numbits, the union of the two number sets. """ byte_pairs = zip_longest(bytes_to_ints(numbits1), bytes_to_ints(numbits2), fillvalue=0) return _to_blob(binary_bytes(b1 | b2 for b1, b2 in byte_pairs))
def merge_bitmaps(map1, map2): """Merge two bitmaps""" byte_pairs = zip_longest(bytes_to_ints(map1), bytes_to_ints(map2), fillvalue=0) return binary_bytes(b1 | b2 for b1, b2 in byte_pairs)