DLinkedNode PopTail() { DLinkedNode res = tail.prev; RemoveNode(res); return(res); }
public void Put(int key, int value) { if (!cache.ContainsKey(key)) { DLinkedNode newNode = new DLinkedNode { Key = key, Value = value }; cache.Add(key, newNode); AddNode(newNode); ++size; if (size > capacity) { // pop the tail DLinkedNode tail = PopTail(); cache.Remove(tail.Key); --size; } } else { // update the value. DLinkedNode node = cache[key]; node.Value = value; MoveToHead(node); } }
public static void KillAll() { DLinkedNode Child = GetGrid().GetFirstChild(); while (Child != null) { // Kill all Child DLinkedNode NextChild = Child.Next; // Kill all grand Child DLinkedNode GrandChild = ((AliensCol)Child).GetFirstChild(); while (GrandChild != null) { DLinkedNode NextGrandChild = GrandChild.Next; AlienLeaf tempGrandChild = ((AlienLeaf)GrandChild); ((AliensCol)Child).Remove(tempGrandChild); // Remove ProxySprite add Box Obj PlayBatchMan.Find(BatchName.Aliens).Remove(((AlienLeaf)GrandChild).GetProxy()); PlayBatchMan.Find(BatchName.Box).Remove(((AlienLeaf)GrandChild).CollisionObj.Box); GrandChild = NextGrandChild; } GetGrid().Remove((AliensCol)Child); // Remove Box Obj PlayBatchMan.Find(BatchName.Box).Remove(((AliensCol)Child).CollisionObj.Box); Child = NextChild; } }
public void put(int key, int value) { if (!cache.ContainsKey(key)) { DLinkedNode newNode = new DLinkedNode(); newNode.key = key; newNode.value = value; cache.Add(key, newNode); addNode(newNode); ++size; if (size > capacity) { // pop the tail DLinkedNode tail = popTail(); cache.Remove(tail.key); --size; } } else { DLinkedNode node = cache[key]; // update the value. node.value = value; moveToHead(node); } }
public void Put(int key, int value) { DLinkedNode node = (DLinkedNode)cache[key]; if (node == null) { DLinkedNode newNode = new DLinkedNode(); newNode.key = key; newNode.value = value; cache.Add(key, newNode); addNode(newNode); ++size; if (size > capacity) { //移除队尾元素 DLinkedNode tail = popTail(); cache.Remove(tail.key); --size; } } else { // 更新node的值并移到队头 node.value = value; moveToHead(node); } }
public void Set(int key, int value) { DLinkedNode node = null; if (cache.ContainsKey(key)) { node = cache[key]; } if (node == null) { DLinkedNode newNode = new DLinkedNode(); newNode.key = key; newNode.value = value; this.cache.Add(key, newNode); this.addNode(newNode); ++count; if (count > Capacity) { DLinkedNode tail = this.popTail(); this.cache.Remove(tail.key); --count; } } else { node.value = value; this.moveToHead(node); } }
private DLinkedNode popTail() { DLinkedNode res = tail.prev; removeNode(res); return(res); }
public void Put(int key, int value) { DLinkedNode node; cache.TryGetValue(key, out node); if (node == null) { DLinkedNode newNode = new DLinkedNode(); newNode.key = key; newNode.value = value; cache.Add(key, newNode); AddNode(newNode); ++size; if (size > capacity) { //pop the tail var tail = PopTail(); cache.Remove(tail.key); --size; } } else { //update the value node.value = value; MoveToHead(node); } }
public static void DoublyLinkedListPrint() { //insert node list = new DoublyLinkedList(); DLinkedNode node1 = new DLinkedNode(22); DLinkedNode node2 = new DLinkedNode(33); DLinkedNode node3 = new DLinkedNode(44); DLinkedNode node4 = new DLinkedNode(55); DLinkedNode node5 = new DLinkedNode(66); InsertBeginning(list, node1); InsertAfter(list, list.firstNode, node2); InsertAfter(list, node2, node3); InsertAfter(list, node3, node4); Insertlast(list, node5); RemoveNode(list, node5); var p = list.firstNode; while (p != null) { Console.WriteLine("value: " + p.data); if (p.next.data == list.lastNode.data) { Console.WriteLine("value: " + p.next.data); break; } p = p.next; } }
private DLinkedNode PopTail() { DLinkedNode res = _tail.Prev; RemoveNode(res); return(res); }
public void Put(int key, int value) { DLinkedNode node = cache.GetValueOrDefault(key); if (node == null) { var addnew = new DLinkedNode { key = key, value = value }; AddNode(addnew); cache.Add(key, addnew); size = cache.Count; if (size > _capacity) { var tail = PopTail(); cache.Remove(tail.key); } } else { node.value = value; MoveToHead(node); } }
public void Put(int key, int value) { if (_cache.TryGetValue(key, out DLinkedNode node)) { // 缓存中存在该值, 则更新值, 并移到头部 node.Value = value; MoveToHead(node); } else { // 该值在缓存中不存在, 则新增 DLinkedNode newNode = new DLinkedNode(); newNode.Key = key; newNode.Value = value; _cache.Add(key, newNode); AddNode(newNode); ++_size; if (_size > _capacity) { // 如果缓存大小超过容量, 则移除末尾元素 DLinkedNode tail = PopTail(); _cache.Remove(tail.Key); --_size; } } }
public static void InitializeGrid() { // get Alien Grid From ReservedChildren Group AliensGrid Grid = (AliensGrid)GameObjectMan.Find(0, 0).GameObj; //if Grid has Child in the object pool DLinkedNode Col = Grid.Reservedchildren.GetHead(); if (Col != null) { ResetGrid(Grid); // Update xs and ys of the whole grid UpdateGridPos(60, 530 - 30 * Nums.Level); // next line is necessary PlayBatchMan.Find(BatchName.Box).Add(GetGrid().CollisionObj.Box); } else { // if Aliens Grid is not in the object pool. create new Grid Obj for (int j = 1; j <= 11; j++) { Composite col = AlienObjectFactory.CreatComposite(j); Grid.Add(col); } } _AlienGridMan._AlienGrid = Grid; }
private void addNode(DLinkedNode node) { node.prev = head; node.next = head.next; head.next.prev = node; head.next = node; }
public override void MoveY() { y += Nums.AlienDeltaY; for (DLinkedNode node = children.GetHead(); node != null; node = node.Next) { ((GameObject)(Component)node).MoveY(); } }
private void AddToHead(DLinkedNode node) { node.Pre = this.head; node.Next = this.head.Next; this.head.Next.Pre = node; this.head.Next = node; }
private void moveToHead(DLinkedNode node) { /** * Move certain node in between to the head. */ removeNode(node); addNode(node); }
private void RemoveNode(DLinkedNode node) { DLinkedNode prev = node.Prev; DLinkedNode next = node.Next; prev.Next = next; next.Prev = prev; }
//在链表前面添加一个节点,[6] 1 2 3 4 5 public void InsertBefore_Head_Test() { DLinkedNode node6 = new DLinkedNode(); node6.InsertBefore(node1); Assert.AreEqual(node6.Next, node1); Assert.AreEqual(node1.Previous, node6); }
private DLinkedNode PopTail() { //Pop the current tail. DLinkedNode result = tail.prev; RemoveNode(result); return(result); }
public void InsertAfter_Tail_Test() { DLinkedNode node6 = new DLinkedNode(); node6.InsertAfter(node5); Assert.AreEqual(node5.Next, node6); Assert.AreEqual(node6.Previous, node5); }
private void removeNode(DLinkedNode node) { DLinkedNode prev = node.prev; DLinkedNode next = node.next; prev.next = next; next.prev = prev; }
public override bool Compare(DLinkedNode temp) { if (((CollisionPair)temp).Name == _ColMan.ComparePair.Name) { return(true); } return(false); }
private void AddNode(DLinkedNode node) { // 总是在头结点的后边插入新结点 node.Prev = _head; node.Next = _head.Next; _head.Next.Prev = node; _head.Next = node; }
public LRUCache(int capacity) { head = new DLinkedNode(); tail = new DLinkedNode(); head.next = tail; tail.prev = head; _capacity = capacity; }
private void RemoveNode(DLinkedNode node) { // * Remove an existing node from the linked list DLinkedNode prev = node.prev; DLinkedNode next = node.next; prev.next = next; next.prev = prev; }
private void addNode(DLinkedNode node) { //将新的node加入在头部的后面 node.prev = head; node.next = head.next; head.next.prev = node; head.next = node; }
public LRUCache(int capacity) { this._capacity = capacity; this.dictionary = new Dictionary <int, DLinkedNode>(capacity + 1); head = new DLinkedNode(); tail = new DLinkedNode(); head.Next = tail; tail.Pre = head; }
private DLinkedNode popTail() { /** * Pop the current tail. */ DLinkedNode res = tail.prev; removeNode(res); return(res); }
public LRUCache(int capacity) { _capacity = capacity; _head = new DLinkedNode(); _tail = new DLinkedNode(); _head.Next = _tail; _tail.Prev = _head; }
public override bool Compare(DLinkedNode temp) { SpriteBaseNode iTemp = (SpriteBaseNode)temp; if (iTemp.SpriteItem == compareItem.SpriteItem) { return(true); } return(false); }
public LRUCache(int capacity) { Capacity = capacity; count = 0; head = new DLinkedNode(); head.pre = null; tail = new DLinkedNode(); tail.post = null; head.post = tail; tail.pre = head; }
/// <summary> /// 添加 /// </summary> /// <param name="node"></param> private void addNode(DLinkedNode node) { node.pre = head; node.post = head.post; head.post.pre = node; head.post = node; }
/// <summary> /// 移动节点 /// </summary> /// <param name="node"></param> private void moveToHead(DLinkedNode node) { this.removeNode(node); this.addNode(node); }
/// <summary> /// 移除一个节点 /// </summary> /// <param name="node"></param> private void removeNode(DLinkedNode node) { DLinkedNode pre = node.pre; DLinkedNode post = node.post; pre.post = post; post.pre = pre; }