protected bool UpdateSlice(TimeSlice slice)
{
// check if nothing to do.
if (m_values.First == null)
{
return slice.Complete;
}
// restart processing from where it left off.
LinkedListNode<DataValue> start = m_values.First;
if (!TimeFlowsBackward && slice.LastProcessedValue != null)
{
start = slice.LastProcessedValue.Next;
}
// reset the begin bound each time we go through the values.
if (TimeFlowsBackward)
{
slice.Begin = null;
}
// initialize slice from value list.
for (LinkedListNode<DataValue> ii = start; ii != null; ii = ii.Next)
{
if (TimeFlowsBackward)
{
// check if before the beginning of the slice.
if (CompareTimestamps(slice.StartTime, ii) >= 0)
{
if (IsGood(ii.Value))
{
slice.SecondEarlyBound = slice.EarlyBound;
slice.EarlyBound = ii;
}
continue;
}
// check if after the end if the slice.
if (CompareTimestamps(slice.EndTime, ii) < 0)
{
if (IsGood(ii.Value))
{
slice.LateBound = ii;
break;
}
continue;
}
// save first value in the slice.
if (slice.End == null)
{
slice.End = ii;
}
// save end of slice.
if (slice.Begin == null)
{
slice.Begin = ii;
slice.LastProcessedValue = ii;
}
}
else
{
// check if before the beginning of the slice.
if (CompareTimestamps(slice.StartTime, ii) > 0)
{
if (IsGood(ii.Value))
{
slice.SecondEarlyBound = slice.EarlyBound;
slice.EarlyBound = ii;
slice.LastProcessedValue = ii;
}
continue;
}
// check if after the end if the slice.
if (CompareTimestamps(slice.EndTime, ii) < 0)
{
if (IsGood(ii.Value))
{
slice.LateBound = ii;
slice.LastProcessedValue = ii;
break;
}
continue;
}
// save first value in the slice.
if (slice.Begin == null)
{
slice.Begin = ii;
}
// save end of slice.
slice.End = ii;
slice.LastProcessedValue = ii;
}
}
// check if no more data needs to be collected.
LinkedListNode<DataValue> requiredBound = null;
if (TimeFlowsBackward)
{
// only need second early bound if using sloped extrapolation and there is no late bound.
if (Configuration.UseSlopedExtrapolation && slice.LateBound == null)
{
requiredBound = slice.SecondEarlyBound;
}
else
{
requiredBound = slice.EarlyBound;
}
}
else
{
requiredBound = slice.LateBound;
}
// all done if required bound exists.
if (requiredBound != null)
{
slice.Complete = true;
}
return slice.Complete;
}