Exemple #1
0
        public static void RemoveFromList(ref DLink pCurrentHead, DLink pNodeToRemove)
        {
            Debug.Assert(pNodeToRemove != null);

            DLink pTmpNode = pNodeToRemove;

            // If pNode is head of list
            if (pCurrentHead == pNodeToRemove)
            {
                pCurrentHead = pCurrentHead.GetNext();

                if (pCurrentHead != null)
                {
                    // Set prev to null - it's the new list head
                    pCurrentHead.SetPrev(null);
                }
            }
            else
            {
                if (pTmpNode.GetPrev() != null)
                {
                    // Set the previous node's next to pNode's next
                    pTmpNode.GetPrev().SetNext(pNodeToRemove.GetNext());
                }

                if (pTmpNode.GetNext() != null)
                {
                    // Set the next node's prev to pNodes prev
                    pTmpNode.GetNext().SetPrev(pTmpNode.GetPrev());
                }
            }
        }
Exemple #2
0
        protected DLink BaseGetNodeFromReserve()
        {
            // If pReserve is empty, refill with growDelta
            if (pReserve == null)
            {
                AddToReservedList(this.growDelta);
            }

            // Get and remove head of pReserve (as pNode)
            Debug.Assert(pReserve != null);
            DLink pNodeToActivate = pReserve;

            // Set new head of Reserve
            pReserve = pReserve.GetNext();

            // If new head is not null, clear its previous link to newly activated node
            if (pReserve != null)
            {
                pReserve.SetPrev(null);
            }

            // "Clean" values of pNode
            pNodeToActivate.Clean();

            return(pNodeToActivate);
        }
Exemple #3
0
        //----------------------------------------------------------------------
        // Static methods
        //----------------------------------------------------------------------

        public static void AddToFront(ref DLink pCurrentHead, DLink pNodeToAdd)
        {
            // Set current node as next of new node
            pNodeToAdd.SetNext(pCurrentHead);

            // Set new node as prev to current node
            if (pCurrentHead != null)
            {
                pCurrentHead.SetPrev(pNodeToAdd);
            }

            // Set new node as head of list
            pCurrentHead = pNodeToAdd;
        }
        public void Attach(InputObserver observer)
        {
            // protection
            Debug.Assert(observer != null);

            observer.pSubject = this;

            // add to front
            if (head == null)
            {
                head = observer;
                observer.SetNext(null);
                observer.SetPrev(null);
            }
            else
            {
                observer.SetNext(head);
                observer.SetPrev(null);
                head.SetPrev(observer);
                head = observer;
            }
        }