// Adds a node to the head of the reserve list public void addReserve(CollectionNode node) { Debug.Assert(node != null); node.next = reserveHead; reserveHead = node; stats.currReserveNodes++; }
public void addActive(CollectionNode node) { Debug.Assert(node != null); node.next = activeHead; if(activeHead != null) activeHead.prev = node; activeHead = node; this.stats.currActiveNodes++; if (stats.currActiveNodes > stats.peakActiveNodes) { stats.peakActiveNodes = stats.currActiveNodes; } }
protected Collection(int toCreate, int willCreate) { Debug.Assert(toCreate > 0); Debug.Assert(willCreate > 0); activeHead = null; reserveHead = null; this.stats.currActiveNodes = 0; this.stats.currReserveNodes = 0; this.stats.peakActiveNodes = 0; this.stats.peakNumNodes = 0; this.stats.currNumNodes = 0; this.stats.beginToCreate = toCreate; this.stats.willCreate = willCreate; this.createReserve(toCreate); }
protected CollectionNode() { next = null; prev = null; }
// removes a node from the head of the reserve list public CollectionNode detachReserveHead() { if (reserveHead == null) { // Create more reserveNodes createReserve(stats.willCreate); } CollectionNode ret = this.reserveHead; reserveHead = reserveHead.next; if (ret.next != null) { ret.next.prev = ret.prev; } return ret; }
protected void Remove(Enum name, Index index = Index.Index_Null) { CollectionNode node = Find(name, index); Debug.Assert(node != null); // If it's the head if (activeHead == node) { activeHead = node.next; if(activeHead != null) activeHead.prev = null; } // Its now in the middle or end else if (node.prev != null) { node.prev.next = node.next; // It's in the middle! Hurray if (node.next != null) { node.next.prev = node.prev; } } addReserve(node); stats.currActiveNodes--; }