/// <summary> Remove the given seqno and resize or partition groups as
/// necessary. The algorithm is as follows:<br>
/// i. Find the group with low <= seqno <= high
/// ii. If seqno == low,
/// a. if low == high, then remove the group
/// Adjust global low. If global low was pointing to the group
/// deleted in the previous step, set it to point to the next group.
/// If there is no next group, set global low to be higher than
/// global high. This way the entry is invalidated and will be removed
/// all together from the pending msgs and the task scheduler
/// iii. If seqno == high, adjust high, adjust global high if this is
/// the group at the tail of the list
/// iv. Else low < seqno < high, break [low,high] into [low,seqno-1]
/// and [seqno+1,high]
///
/// </summary>
/// <param name="seqno">the sequence number to remove
/// </param>
public virtual void remove(long seqno)
{
int i;
long loBound = -1;
long hiBound = -1;
lock (this)
{
for (i = 0; i < list.Count; i += 2)
{
loBound = (long)list[i];
hiBound = (long)list[i + 1];
if (seqno < loBound || seqno > hiBound)
{
continue;
}
break;
}
if (i == list.Count)
{
return;
}
if (seqno == loBound)
{
if (loBound == hiBound)
{
list.RemoveAt(i);
list.RemoveAt(i);
}
else
{
list[i] = ++loBound;
}
if (i == 0)
{
low = list.Count == 0 ? high + 1:loBound;
}
}
else if (seqno == hiBound)
{
list[i + 1] = --hiBound;
if (i == list.Count - 1)
{
high = hiBound;
}
}
else
{
list[i + 1] = seqno - 1;
list.Insert(i + 2, hiBound);
list.Insert(i + 2, seqno + 1);
}
}
}