示例#1
0
        public bool remove(int seqno)
        {
            if (0 == m_iLength)
            {
                return(false);
            }

            // locate the position of "seqno" in the list
            int offset = SequenceNumber.seqoff(m_piData1[m_iHead], seqno);

            if (offset < 0)
            {
                return(false);
            }

            int loc = (m_iHead + offset) % m_iSize;

            if (seqno == m_piData1[loc])
            {
                // This is a seq. no. that starts the loss sequence

                if (-1 == m_piData2[loc])
                {
                    // there is only 1 loss in the sequence, delete it from the node
                    if (m_iHead == loc)
                    {
                        m_iHead = m_piNext[m_iHead];
                        if (-1 != m_iHead)
                        {
                            m_piPrior[m_iHead] = -1;
                        }
                    }
                    else
                    {
                        m_piNext[m_piPrior[loc]] = m_piNext[loc];
                        if (-1 != m_piNext[loc])
                        {
                            m_piPrior[m_piNext[loc]] = m_piPrior[loc];
                        }
                        else
                        {
                            m_iTail = m_piPrior[loc];
                        }
                    }

                    m_piData1[loc] = -1;
                }
                else
                {
                    // there are more than 1 loss in the sequence
                    // move the node to the next and update the starter as the next loss inSeqNo(seqno)

                    // find next node
                    int j = (loc + 1) % m_iSize;

                    // remove the "seqno" and change the starter as next seq. no.
                    m_piData1[j] = SequenceNumber.incseq(m_piData1[loc]);

                    // process the sequence end
                    if (SequenceNumber.seqcmp(m_piData2[loc], SequenceNumber.incseq(m_piData1[loc])) > 0)
                    {
                        m_piData2[j] = m_piData2[loc];
                    }

                    // remove the current node
                    m_piData1[loc] = -1;
                    m_piData2[loc] = -1;

                    // update list pointer
                    m_piNext[j]  = m_piNext[loc];
                    m_piPrior[j] = m_piPrior[loc];

                    if (m_iHead == loc)
                    {
                        m_iHead = j;
                    }
                    else
                    {
                        m_piNext[m_piPrior[j]] = j;
                    }

                    if (m_iTail == loc)
                    {
                        m_iTail = j;
                    }
                    else
                    {
                        m_piPrior[m_piNext[j]] = j;
                    }
                }

                m_iLength--;

                return(true);
            }

            // There is no loss sequence in the current position
            // the "seqno" may be contained in a previous node

            // searching previous node
            int i = (loc - 1 + m_iSize) % m_iSize;

            while (-1 == m_piData1[i])
            {
                i = (i - 1 + m_iSize) % m_iSize;
            }

            // not contained in this node, return
            if ((-1 == m_piData2[i]) || (SequenceNumber.seqcmp(seqno, m_piData2[i]) > 0))
            {
                return(false);
            }

            if (seqno == m_piData2[i])
            {
                // it is the sequence end

                if (seqno == SequenceNumber.incseq(m_piData1[i]))
                {
                    m_piData2[i] = -1;
                }
                else
                {
                    m_piData2[i] = SequenceNumber.decseq(seqno);
                }
            }
            else
            {
                // split the sequence

                // construct the second sequence from SequenceNumber.incseq(seqno) to the original sequence end
                // located at "loc + 1"
                loc = (loc + 1) % m_iSize;

                m_piData1[loc] = SequenceNumber.incseq(seqno);
                if (SequenceNumber.seqcmp(m_piData2[i], m_piData1[loc]) > 0)
                {
                    m_piData2[loc] = m_piData2[i];
                }

                // the first (original) sequence is between the original sequence start to SequenceNumber.decseq(seqno)
                if (seqno == SequenceNumber.incseq(m_piData1[i]))
                {
                    m_piData2[i] = -1;
                }
                else
                {
                    m_piData2[i] = SequenceNumber.decseq(seqno);
                }

                // update the list pointer
                m_piNext[loc]  = m_piNext[i];
                m_piNext[i]    = loc;
                m_piPrior[loc] = i;

                if (m_iTail == i)
                {
                    m_iTail = loc;
                }
                else
                {
                    m_piPrior[m_piNext[loc]] = loc;
                }
            }

            m_iLength--;

            return(true);
        }