protected DLink BaseAdd() { // Are there any nodes on the Reserve list? if (this.poReserve == null) { // refill the reserve list by the DeltaGrow this.PrivFillReservedPool(this.mDeltaGrow); } // Always take from the reserve list DLink pLink = DLink.PopFromFront(ref this.poReserve); Debug.Assert(pLink != null); // Wash it this.DerivedWash(pLink); // Update stats this.mNumActive++; this.mNumReserved--; // copy to active DLink.AddToFront(ref this.poActive, pLink); // YES - here's your new one (its recycled from reserved) return(pLink); }
protected DLink BaseAddToPosition(DLink pNode) { if (this.poReserve == null) { this.PrivFillReservedPool(this.mDeltaGrow); } DLink pLink = DLink.PullFromFront(ref this.poReserve); Debug.Assert(pLink != null); // Wash it this.DerivedWash(pLink); // Update stats this.mNumActive++; this.mNumReserved--; // copy to active if (pNode == null) { DLink.AddToFront(ref this.poActive, pLink); } else { DLink.AddToBehind(ref pNode, pLink); } // YES - here's your new one (its recycled from reserved) return(pLink); }
protected DLink BaseAdd() { DLink newNode = DLink.RemoveFront(ref pReserve); if (newNode == null && growthSize > 0) { RefreshReserve(); newNode = DLink.RemoveFront(ref pReserve); DLink.AddToFront(ref pActive, newNode); } else if (newNode != null) { newNode.Wash(); DLink.AddToFront(ref pActive, newNode); } else { Debug.Assert(false, "Cannot add new node because reserve is empty and growth size is " + growthSize); } mNumActive++; mNumReserve--; return(newNode); }
protected DLink BaseAdd() { // If any node doesn't exist in reserve list. if(this.pReserve == null) { // Refill the reserve list by the growthSize this.PrivFillReservedPool(this.growthSize); } // Always take from the reserve list DLink pLink = DLink.PullFromFront(ref this.pReserve); Debug.Assert(pLink != null); // Wash it this.DerivedWash(pLink); // Update stats this.mNumActive++; this.mNumReserve--; if (this.mNumActive > this.maximumNumActive) { this.maximumNumActive = this.mNumActive; } // copy to active DLink.AddToFront(ref this.pActive, pLink); return pLink; }
//---------------------------------------------------------------------- // 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); }
private void RefreshReserve(int numNodesToAdd) { for (int i = 0; i < numNodesToAdd; i++) { DLink.AddToFront(ref pReserve, CreateNode()); mNumReserve++; } }
private void RefreshReserve() { for (int i = 0; i < growthSize; i++) { DLink.AddToFront(ref pReserve, CreateNode()); mNumReserve++; } }
public static void Attach(Observer pObserver) { // protection Debug.Assert(pObserver != null); DelayedObjectManager pDelayMan = DelayedObjectManager.privGetInstance(); DLink.AddToFront(ref pDelayMan.pHead, pObserver); }
override public void Add(Component pComponent) { Debug.Assert(pComponent != null); DLink.AddToFront(ref this.pHead, pComponent); this.numChildren += 1; pComponent.pParent = this; }
private static void privAddToFront(ref DLink pHead, DLink pNode) { // Will work for Active or Reserve List Debug.Assert(pNode != null); DLink.AddToFront(ref pHead, pNode); // worst case, pHead was null initially, now we added a node so... this is true Debug.Assert(pHead != null); }
override public void Add(Component pComponent) { GameObject pGameObject = (GameObject)pComponent; Debug.Assert(pGameObject != null); DLink.AddToFront(ref this.poHeadChild, pGameObject); pGameObject.pParent = this; this.numChildren++; }
protected void BaseRemove(DLink pDlink) { //depending on where the node is in the list we will have to move stuff around DLink.RemoveNode(ref this.poActive, pDlink); this.NumActive--; this.DerivedWash(pDlink); // then send that node or DLink back into the mNumReserve list DLink.AddToFront(ref this.poReserve, pDlink); this.NumReserve++; }
protected void BaseRemove(DLink pNode) { Debug.Assert(pNode != null); DLink.RemoveNode(ref this.poActive, pNode); this.DerivedWash(pNode); DLink.AddToFront(ref this.poReserve, pNode); this.mNumActive--; this.mNumReserved++; }
protected void BaseRemove(DLink pNode) { Debug.Assert(pNode != null); // Transfer the node in active list to reserve list. DLink.RemoveNode(ref this.pActive, pNode); this.DerivedWash(pNode); DLink.AddToFront(ref this.pReserve, pNode); // Update Stats this.mNumActive--; this.mNumReserve++; }
protected void BaseRemove(DLink pDLink) { // check that pDLink is not null Debug.Assert(pDLink != null); DLink retiredNode = DLink.Remove(ref pActive, pDLink); mNumActive--; // check that retiredNode is not null Debug.Assert(retiredNode != null); DLink.AddToFront(ref pReserve, retiredNode); mNumReserve++; }
/// <summary> /// Moves a node from reserve to active and then returns reference for client to modify as desired /// </summary> /// <returns>DLink that was added to active list</returns> protected DLink BaseAdd() { DLink pNodeToActivate = BaseGetNodeFromReserve(); // Add to front of Active List DLink.AddToFront(ref pActive, pNodeToActivate); // Stats this.reserveNodeNum--; this.activeNodeNum++; return(pNodeToActivate); }
private void PrivReFill(int count) { Debug.Assert(count > 0); this.NumReserve += count; this.TotalNodes += count; for (int i = 0; i < count; i++) { DLink pDlink = this.DerivedCreateNode(); DLink.AddToFront(ref this.poReserve, pDlink); } }
protected void BasePurgeAllNodes() { DLink pNode; while (this.pActive != null) { pNode = DLink.RemoveFront(ref pActive); DLink.AddToFront(ref pReserve, pNode); mNumActive--; mNumReserve++; } Debug.Assert(pActive == null); Debug.Assert(mNumActive == 0); }
protected void baseRemove(DLink pNode) { Debug.Assert(pNode != null); // remove the node from active list and update states DLink.RemoveNode(ref this.pActive, pNode); this.mNumActive--; // reset the node this.derivedReset(pNode); // add back to reserved list DLink.AddToFront(ref this.pReserved, pNode); this.mNumReserved++; }
//---------------------------------------------------------------------- // Private methods //---------------------------------------------------------------------- private void PrivFillReservedPool(int count) { Debug.Assert(count > 0); this.mNumTotal += count; this.mNumReserve += count; for(int i = 0; i < count; ++i) { DLink pNode = this.DerivedCreateNode(); Debug.Assert(pNode != null); DLink.AddToFront(ref this.pReserve, pNode); } }
/// <summary> /// Adds additional nodes to reserved list /// </summary> /// <param name="numNodes">Number of nodes to ad to reserved list</param> private void AddToReservedList(int numNodes) { Debug.Assert(numNodes > 0); DLink pNewNode; for (int i = 0; i < numNodes; i++) { pNewNode = this.DerivedCreateNode(); Debug.Assert(pNewNode != null); DLink.AddToFront(ref pReserve, pNewNode); } this.totalNodeNum += numNodes; this.reserveNodeNum += numNodes; }
/// <summary> /// Moves a node from active to reserve and cleans list references for node /// </summary> /// <param name="pNode"></param> protected void BaseRemove(DLink pNode) { Debug.Assert(pNode != null); // Update list pointers to remove pNode from list DLink.RemoveFromList(ref pActive, pNode); // Remove list references in removed node pNode.ClearLinks(); // Return pNode to pReserve list DLink.AddToFront(ref pReserve, pNode); // stats update this.activeNodeNum--; this.reserveNodeNum++; }
protected void BaseRemove(DLink pNode) { Debug.Assert(pNode != null); // Don't do the work here... delegate it DLink.RemoveNode(ref this.poActive, pNode); // wash it before returning to reserve list this.DerivedWash(pNode); // add it to the return list DLink.AddToFront(ref this.poReserve, pNode); // stats update this.mNumActive--; this.mNumReserved++; }
//---------------------------------------------------------------------- // Helper Methods //---------------------------------------------------------------------- private void privFillReservePool(int val) { Debug.Assert(val > 0); DLink current = this.poHeadReserve; for (int i = 0; i < val; i++) { DLink pLink = this.derivedCreateNode(); Debug.Assert(pLink != null); DLink.AddToFront(ref this.poHeadReserve, pLink); } // update counters this.mNumReserveNodes += val; this.mNumTotalNodes += val; }
//---------------------------------------------------------------------- // Private methods - helpers //---------------------------------------------------------------------- private void PrivFillReservedPool(int count) { // doesn't make sense if its not at least 1 Debug.Assert(count > 0); this.mTotalNumNodes += count; this.mNumReserved += count; // Preload the reserve for (int i = 0; i < count; i++) { DLink pNode = this.DerivedCreateNode(); Debug.Assert(pNode != null); DLink.AddToFront(ref this.poReserve, pNode); } }
//---------------------------------------------------------------------- // Private methods //---------------------------------------------------------------------- private void fillNodesToReservedList(int numNode) { int numAddedNode = 0; DLink currNode = null; while (numAddedNode < numNode) { // create a specific node currNode = this.derivedCreateNode(); Debug.Assert(currNode != null); DLink.AddToFront(ref pReserved, currNode); this.mNumReserved++; this.mTotalNumNodes++; numAddedNode++; } }
public void Attach(Image.Name imageName) { // Get the image Image pImage = ImageMan.Find(imageName); Debug.Assert(pImage != null); // Create a new holder ImageHolder pImageHolder = new ImageHolder(pImage); Debug.Assert(pImageHolder != null); // Attach it to the Animation Sprite ( Push to front ) DLink.AddToFront(ref this.poFirstImage, pImageHolder); // Set the first one to this image this.pCurrImage = pImageHolder; }
protected Manager(int numNodes = 5, int growthSize = 2) { // Check params Debug.Assert(numNodes >= 0); Debug.Assert(growthSize > 0); mNumActive = 0; pActive = null; pReserve = null; this.growthSize = growthSize; for (int i = 0; i < numNodes; i++) { DLink newNode = this.CreateNode(); Debug.Assert(newNode != null); DLink.AddToFront(ref pReserve, newNode); mNumReserve++; } }
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++; } }
protected DLink BaseAdd() { // refill Reserve List if empty if (this.NumReserve == 0) { this.PrivReFill(this.growth); } //pull from front of reserve list DLink pDlink = DLink.PullFromFront(ref this.poReserve); this.NumReserve--; //clean the notecard this.DerivedWash(pDlink); //then add to front of active list DLink.AddToFront(ref this.poActive, pDlink); this.NumActive++; return(pDlink); }