import ipaddress


def search_prefix_list(ip, prefix_list):
    """
    Check if IP address exists in some prefix which is part of `prefix_list`
    `prefix_list` must be a list of tuples
    Each tuple must be of form (ip_prefix_begin, ip_prefix_end) in int equivalent (check preparation step)
    1. Convert IP to int equivalent
    2. Binary search through list of tuples. Check if ip falls between (tuple[0], tuple[1])
    3. Return prefix if it does
    """
    if isinstance(ip, str) and ("." in ip or ":" in ip):
        ip = int(ipaddress.ip_address(ip))

    low = 0
    high = len(prefix_list) - 1

    while (low <= high):
        mid = (low + high) >> 1 # divide by 2
        if ip >= prefix_list[mid][0] and ip <= prefix_list[mid][1]:
            return mid
        elif ip < prefix_list[mid][0]:
            high = mid - 1
        else:
            low = mid + 1

    return -1