def binary_lookup(index, offsets):
    """
    Given a character index, look up the index of it in the offsets. This will
    be the number at which the next index is greater
    """
    bottom = 0
    top = len(offsets) - 1
    if index > offsets[top]:
        return top
    
    while top - bottom > 1:
        mid = (top + bottom) // 2
        if index >= offsets[mid]:
            bottom = mid
        else:
            top = mid

    return bottom