Returns index of a that is closest to x.

    Arguments:
      a -- ordered numeric sequence
      x -- element to search within a
      lo -- lowest index to consider in search*
      hi -- highest index to consider in search*

    *bisect.bisect_left capability that we don't need to loose.

def BSearchRound(a, x, lo=0, hi=None):
    """Returns index of a that is closest to x.

    Arguments:
      a -- ordered numeric sequence
      x -- element to search within a
      lo -- lowest index to consider in search*
      hi -- highest index to consider in search*

    *bisect.bisect_left capability that we don't need to loose."""
    if len(a) == 0: return -1
    hi = hi if hi is not None else len(a)
    pos = bisect_left(a, x, lo, hi)

    if pos >= hi:
        return hi - 1
    elif a[pos] == x or pos == lo:
        return pos
    else:
        return pos - 1 if x - a[pos - 1] <= a[pos] - x else pos