Ejemplo n.º 1
0
        public void baseDestroy()
        {
            this.mTotalNumNodes = 0;
            this.mNumActive     = 0;
            this.mNumReserved   = 0;

            DLink pCurLink  = poActive;
            DLink pNextLink = pCurLink.pNext;

            while (pNextLink != null)
            {
                pCurLink.Clear();
                pCurLink  = pNextLink;
                pNextLink = pNextLink.pNext;
            }
            pCurLink.Clear();

            pCurLink  = poReserve;
            pNextLink = pCurLink.pNext;

            while (pNextLink != null)
            {
                pCurLink.Clear();
                pCurLink  = pNextLink;
                pNextLink = pNextLink.pNext;
            }
            pCurLink.Clear();
        }
Ejemplo n.º 2
0
        public static void RemoveNode(ref DLink pHead, DLink pNode)
        {
            Debug.Assert(pHead != null);
            Debug.Assert(pNode != null);

            if (pNode.pPrev != null)
            {
                pNode.pPrev.pNext = pNode.pNext;
            }
            else
            {
                pHead = pNode.pNext;
            }
            if (pHead != null)
            {
                pHead.pPrev = null;
            }

            if (pNode.pNext != null)
            {
                pNode.pNext.pPrev = pNode.pPrev;
            }
            // remove any lingering links
            pNode.Clear();
        }
Ejemplo n.º 3
0
        public static DLink PullFromFront(ref DLink pHead)
        {
            // There should always be something on list
            Debug.Assert(pHead != null);

            // return node
            DLink pNode = pHead;

            // Update head (OK if it points to NULL)
            pHead = pHead.pNext;
            if (pHead != null)
            {
                pHead.pPrev = null;
                // do not change pEnd
            }
            else
            {
                // only one on the list
                // pHead == null
            }

            // remove any lingering links
            // HUGELY important - otherwise its crossed linked
            pNode.Clear();

            return(pNode);
        }
Ejemplo n.º 4
0
        // Add a node one slot before the target node
        public void AddBeforeNode(DLink target, DLink node)
        {
            Debug.Assert(target != null);
            Debug.Assert(node != null);

            node.Clear();

            // Case 1: target is the head
            if (target == this.poActiveHead)
            {
                Debug.Assert(target.pPrev == null);

                target.pPrev      = node;
                node.pNext        = target;
                this.poActiveHead = node;
            }
            // Case 2: target is in the middle
            else
            {
                Debug.Assert(target.pPrev != null);

                target.pPrev.pNext = node;
                node.pPrev         = target.pPrev;
                target.pPrev       = node;
                node.pNext         = target;
            }

            mNumActive++;
        }
Ejemplo n.º 5
0
        // Add a node one slot after the target node
        public void AddAfterNode(DLink target, DLink node)
        {
            Debug.Assert(target != null);
            Debug.Assert(node != null);

            node.Clear();

            // Case 1: target is the tail
            if (target == this.pActiveEnd)
            {
                Debug.Assert(target.pNext == null);

                target.pNext = node;
                node.pPrev   = target;
            }
            // Case 2: target is in the middle
            else
            {
                Debug.Assert(target.pNext != null);

                target.pNext.pPrev = node;
                node.pNext         = target.pNext;
                target.pNext       = node;
                node.pPrev         = target;
            }

            mNumActive++;
        }
Ejemplo n.º 6
0
        public static void RemoveNode(ref DLink pHead, DLink pNode)
        {
            // protection
            Debug.Assert(pHead != null);
            Debug.Assert(pNode != null);

            // Quick HACK... might be a bug... need to diagram

            // 4 different conditions...
            if (pNode.pPrev != null)
            {   // middle part 1/2
                pNode.pPrev.pNext = pNode.pNext;
            }
            else
            {  // first
                pHead = pNode.pNext;
            }

            if (pNode.pNext != null)
            {   // middle node part 2/2
                pNode.pNext.pPrev = pNode.pPrev;
            }

            // remove any lingering links
            // HUGELY important - otherwise its crossed linked
            pNode.Clear();
        }
Ejemplo n.º 7
0
        private void privRemoveNode(ref DLink pHead, ref DLink pLast, DLink pLink)
        {
            // protection
            Debug.Assert(pHead != null);
            Debug.Assert(pLink != null);


            if (pLink.pPrev != null)
            {
                pLink.pPrev.pNext = pLink.pNext;
            }
            else
            {  // first
                pHead = pLink.pNext;
            }

            if (pLink.pNext != null)
            {
                pLink.pNext.pPrev = pLink.pPrev;
            }
            else
            {
                pLast = pLink.pPrev;
            }

            pLink.Clear();

            // make sure its disconnected
            Debug.Assert(pLink.pNext == null);
            Debug.Assert(pLink.pPrev == null);
        }
Ejemplo n.º 8
0
        //----------------------------------------------------------------------
        // Base Methods
        //----------------------------------------------------------------------
        public DLink baseAdd()
        {
            //calls addtofront in DLink
            // derived add method will have parameters

            //Check if there are any nodes in reserve
            if (this.poHeadReserve == null)
            {
                //perform a refill
                this.privFillReservePool(this.growthRate);
            }

            // Now that we are guarenteed that the reserve is not-empty we can pull
            DLink pLink = DLink.PullFromFront(ref this.poHeadReserve);

            //Clean the node of data and references to other DLinks
            pLink.Clear();
            this.derivedWash(pLink);


            // initialize
            DLink.AddToFront(ref this.poHeadActive, pLink);

            // update counters
            this.mNumActiveNodes++;
            this.mNumReserveNodes--;

            return(pLink);
        }
Ejemplo n.º 9
0
        public void AddAndSort(ref DLink pHead, ref DLink pTail, DLink node)
        {
            node.Clear();

            // If reserved is empty, replenish with nodes
            if (this.mNumReserved == 0)
            {
                CreateReservedNodes(this.mGrowthSize);
            }

            // Case 1, First Node
            if (pHead == null)
            {
                pHead = node;
                pTail = node;
            }
            // Case 2: Not first node
            else
            {
                // Traverse the list to find first node have greater trigger time than node
                DLink current = pHead;
                while (current != null)
                {
                    if (((TimerEvent)current).triggerTime >= ((TimerEvent)node).triggerTime)
                    {
                        break;
                    }

                    current = current.pNext;
                }
                if (current != null)
                {
                    this.AddBeforeNode(current, node);
                }
                else
                {
                    // Add to end
                    if (this.poActiveHead == null)
                    {
                        // no node in the list
                        this.poActiveHead = node;
                        this.pActiveEnd   = node;
                    }
                    else
                    {
                        // there are nodes, Add to end
                        this.pActiveEnd.pNext = node;
                        node.pNext            = null;
                        node.pPrev            = this.pActiveEnd;
                        this.pActiveEnd       = node;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void baseRemove(DLink pLink)
        {
            privRemove(ref this.poActive, pLink);

            pLink.Clear();
            //derivedWash(pLink);
            privAddToFront(ref this.poReserve, pLink);

            // update stats
            this.mNumActive--;
            this.mNumReserved++;
        }
Ejemplo n.º 11
0
        // Recycle a node to the reserve list, internally
        private void AddToReserve(DLink node)
        {
            Debug.Assert(node != null);

            node.Clear();

            // Add to the front of the reserved list
            this.poReservedHead.pPrev = node;
            node.pNext          = this.poReservedHead;
            this.poReservedHead = node;

            this.mNumReserved++;
        }
Ejemplo n.º 12
0
        public static DLink PullFront(ref DLink pHead)
        {
            Debug.Assert(pHead != null);
            DLink pNode = pHead;

            pHead = pHead.pNext;
            if (pHead != null)
            {
                pHead.pPrev = null;
            }
            // remove any lingering links
            pNode.Clear();
            return(pNode);
        }
Ejemplo n.º 13
0
        public void AddAndSort(ref DLink pHead, ref DLink pTail, DLink node)
        {
            node.Clear();

            // Case 1, First Node
            if (pHead == null)
            {
                pHead = node;
                pTail = node;
            }
            // Case 2: Not first node
            else
            {
                // Traverse the list to find first node have greater priority than node
                DLink current = pHead;
                while (current != null)
                {
                    if (((SpriteBatch)current).priority >= ((SpriteBatch)node).priority)
                    {
                        break;
                    }

                    current = current.pNext;
                }
                if (current != null)
                {
                    this.AddBeforeNode(current, node);
                }
                else
                {
                    // Add to end
                    if (this.poActiveHead == null)
                    {
                        // no node in the list
                        this.poActiveHead = node;
                        this.pActiveEnd   = node;
                    }
                    else
                    {
                        // there are nodes, Add to end
                        this.pActiveEnd.pNext = node;
                        node.pNext            = null;
                        node.pPrev            = this.pActiveEnd;
                        this.pActiveEnd       = node;
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public static DLink RemoveNode(ref DLink pHead, ref DLink pTail, DLink pNode)
        {
            // protection
            Debug.Assert(pNode != null);

            // Might have bug
            //tried to diagram and change, but added more issues
            //check again later

            // 4 different conditions...
            if (pNode.pPrev != null)
            {   // middle or last node
                pNode.pPrev.pNext = pNode.pNext;

                if (pNode == pTail)
                {
                    pTail = pNode.pPrev;
                }
            }

            else
            {  // first
                pHead = pNode.pNext;

                if (pNode == pTail)
                {
                    // Only one node
                    pTail = pNode.pNext;
                }

                else
                {
                    // Only first not the last
                    // do nothing more
                }
            }

            if (pNode.pNext != null)
            {   // middle node
                pNode.pNext.pPrev = pNode.pPrev;
            }

            pNode.Clear();

            return(pNode);
        }
Ejemplo n.º 15
0
        public static DLink PullFromFront(ref DLink pHead)
        {
            Debug.Assert(pHead != null);

            // Return node
            DLink pNode = pHead;

            // Update head
            pHead = pHead.pNext;
            if (pHead != null)
            {
                pHead.pPrev = null;
            }

            pNode.Clear();

            return(pNode);
        }
Ejemplo n.º 16
0
        private DLink privPopFront(ref DLink pHead)
        {
            Debug.Assert(pHead != null);

            // move pHead to next
            DLink pLink = pHead;

            pHead = pHead.pNext;

            // set pHead pPrev
            if (pHead != null)
            {
                pHead.pPrev = null;
            }

            // clean node
            pLink.Clear();
            return(pLink);
        }
Ejemplo n.º 17
0
        // Add a node to the end of the active list
        public static void AddToEnd(ref DLink pHead, ref DLink pTail, DLink node)
        {
            Debug.Assert(node != null);

            node.Clear();

            // Case 1: First node
            if (pTail == null)
            {
                pHead = node;
                pTail = node;
            }
            // Case 2: not first node
            else
            {
                pTail.pNext = node;
                node.pPrev  = pTail;
                pTail       = node;
            }
        }
Ejemplo n.º 18
0
        // Add a node to the front of the active list
        public static void AddToFront(ref DLink pHead, ref DLink pTail, DLink node)
        {
            Debug.Assert(node != null);

            node.Clear();

            // Case 1: First node
            if (pHead == null)
            {
                pHead = node;
                pTail = node;
            }
            // Case 2: Not first node
            else
            {
                pHead.pPrev = node;
                node.pNext  = pHead;
                pHead       = node;
            }
        }
Ejemplo n.º 19
0
        public static DLink PullFromFront(ref DLink pHead)
        {
            // There should always be something on list
            Debug.Assert(pHead != null);

            // return node
            DLink pNode = pHead;

            // Update head
            pHead = pHead.pNext;
            if (pHead != null)
            {
                pHead.pPrev = null;
            }

            // Set prev and next links
            pNode.Clear();

            return(pNode);
        }
Ejemplo n.º 20
0
        public static void AddToEnd(ref DLink pHead, DLink pLink)
        {
            //This is inefficient since it will walk the DLink
            Debug.Assert(pLink != null);
            pLink.Clear();

            if (pHead == null)
            {
                pHead = pLink;
            }
            else
            {
                DLink pCurrent = pHead;
                while (pCurrent.pNext != null)
                {
                    pCurrent = pCurrent.pNext;
                }
                // At the end
                pCurrent.pNext = pLink;
            }
        }
Ejemplo n.º 21
0
        public static DLink PopFromFront(ref DLink pHead)
        {
            // There should always be something on list
            Debug.Assert(pHead != null);

            // return node
            DLink pNode = pHead;

            // Update head (OK if it points to NULL)
            pHead = pHead.pNext;
            if (pHead != null)
            {
                pHead.pPrev = null;
            }

            // HUGELY important - otherwise its crossed linked
            //      Very hard to figure out
            pNode.Clear();

            return(pNode);
        }
Ejemplo n.º 22
0
        public static DLink PullFromFront(ref DLink pHead)
        {
            Debug.Assert(pHead != null);

            DLink pDLink = pHead;

            pHead = pHead.pNext;

            // if we have more links
            //set the new start's previous to null
            if (pHead != null)
            {
                pHead.pPrev = null;
            }

            //we dont want any links coming with
            //found out the hard way
            pDLink.Clear();

            return(pDLink);
        }
Ejemplo n.º 23
0
        //------------------------------------------
        //---------Dealing with last node-----------
        //------------------------------------------
        public static void RemoveNode(ref DLink pHead, ref DLink pEnd, DLink pNode)
        {
            // protection
            Debug.Assert(pHead != null);
            Debug.Assert(pEnd != null);
            Debug.Assert(pNode != null);

            if (pNode.pPrev != null)
            {   // middle part 1/2
                pNode.pPrev.pNext = pNode.pNext;

                // last node
                if (pNode == pEnd)
                {
                    pEnd = pNode.pPrev;
                }
            }
            else
            {  // first
                pHead = pNode.pNext;

                if (pNode == pEnd)
                {
                    // Only one node
                    pEnd = pNode.pNext;
                }
                else
                {
                    // Only first not the last
                    // do nothing more
                }
            }

            if (pNode.pNext != null)
            {   // middle node part 2/2
                pNode.pNext.pPrev = pNode.pPrev;
            }

            pNode.Clear();
        }
Ejemplo n.º 24
0
        public void baseRemove(DLink pLink)
        {
            // remove safely
            Debug.Assert(pLink != null);
            DLink target = this.baseFind(pLink);

            DLink.RemoveNode(ref this.poHeadActive, target);

            if (target != null)
            {
                // Clean the node
                target.Clear();
                this.derivedWash(target);

                // Push the node to the reserve list
                DLink.AddToFront(ref this.poHeadReserve, target);

                // update counters
                this.mNumActiveNodes--;
                this.mNumReserveNodes++;
            }
        }
Ejemplo n.º 25
0
        protected void BaseRemove(DLink node)
        {   // remove from Active, and add to Reserve
            DLink foundNode = BaseFind(node);

            if (foundNode != null)
            {
                if (foundNode.pDPrev == null)
                {   // Remove first node in source List
                    this.pActive = this.pActive.pDNext;
                    if (this.pActive != null)
                    {
                        this.pActive.pDPrev = null;
                    }
                }
                else if (foundNode.pDNext == null)
                {   // Remove last node in source list
                    foundNode.pDPrev.pDNext = null;
                }
                else
                {   // Remove node somewhere in the middle
                    foundNode.pDPrev.pDNext = foundNode.pDNext;
                    foundNode.pDNext.pDPrev = foundNode.pDPrev;
                }
                // Clear foundNode and add to front of Reserve List
                foundNode.Clear();
                foundNode.status     = DLinkStatus.Reserve;
                foundNode.pDNext     = this.pReserve;
                this.pReserve.pDPrev = foundNode;
                this.pReserve        = foundNode;

                --this.mNumActive;
                ++this.mNumReserve;
            }
            else
            {
                //Debug.WriteLine(String.Format("Node {0} was not found.", node.GetHashCode()));
            }
        }
Ejemplo n.º 26
0
        private void privRemove(ref DLink pHead, DLink pLink)
        {
            // protection
            Debug.Assert(pHead != null);
            Debug.Assert(pLink != null);

            // fix
            if (pLink.pPrev != null)
            {
                pLink.pPrev.pNext = pLink.pNext;
            }
            else
            {  // first
                pHead = pLink.pNext;
            }

            if (pLink.pNext != null)
            {
                pLink.pNext.pPrev = pLink.pPrev;
            }

            pLink.Clear();
        }
Ejemplo n.º 27
0
        public static void RemoveNode(ref DLink pHead, DLink pNode)
        {
            // protection
            Debug.Assert(pHead != null);
            Debug.Assert(pNode != null);

            // 4 different conditions...
            if (pNode.pPrev != null)
            {   // middle part 1/2
                pNode.pPrev.pNext = pNode.pNext;
            }
            else
            {  // first
                pHead = pNode.pNext;
            }

            if (pNode.pNext != null)
            {   // middle node part 2/2
                pNode.pNext.pPrev = pNode.pPrev;
            }

            // Set prev and next links
            pNode.Clear();
        }