def list_index_for_timestamp(in_list, start_index, timestamp):
    """ A helper function for timed operators.
    The basic idea is to return the earliest index in
    in_list.list[start_index:in_list.stop] with a time field  
    that is greater than or equal to timestamp. If no such index 
    exists then return a negative number.

    Parameters
    ----------
    in_list: InList
             InList = namedtuple('InList', ['list', 'start', 'stop'])
             A slice into a stream.
    start_index: nonnegative integer
             A pointer into in_list.list
    timestamp: number

    Returns
    -------
    Returns positive integer i where:
    either: 'FOUND TIME WINDOW IN IN_LIST'
        i >= start_index and
        i <= in_list.stop  and
        (in_list[start_index] >= timestamp
        or
        in_list.list[i-2].time < timestamp <= in_list.list[i-1].time
        )
        
        )
    or: 'NO TIME WINDOW IN IN_LIST'
        i < 0 (negative i indicates no time window) and
           (in_list.list[in_list.stop-1] <= timestamp
                       or
           the list is empty, i.e.
           (in_list.start = in_list.stop)

    Requires
    --------
         start_index >= in_list.start and
         start_index < in_list.stop

    """
    # If the list is empty then return a negative number to indicate
    # absence of time window.
    if in_list.start == in_list.stop:
        return -1

    if start_index < in_list.start or start_index >= in_list.stop:
        raise Exception('start_index out of range: start_index =', start_index,
                        ' in_list.start = ', in_list.start,
                        ' in_list.stop = ', in_list.stop)
    
    for i in range(start_index, in_list.stop):
        # assert i <= in_list.stop-1
        if in_list.list[i].time >= timestamp:
            # Found an index i with a sufficiently large time.
            return i
        
    # All the times in in_list up to in_list.stop are less
    # than timestamp.
    # assert in_list.list[in_list.stop - 1] < timestamp
    return -1