/// <summary> /// 移除节点 /// </summary> public void RemoveNode(DoubleLinkListNode <T> pNode) { if (pNode == null) { return; } if (pNode == Head) { Head = pNode.next; } if (pNode == Tail) { Tail = pNode.prev; } if (pNode.prev != null) { pNode.prev.next = pNode.next; } if (pNode.next != null) { pNode.next.prev = pNode.prev; } pNode.next = pNode.prev = null; pNode.t = null; m_DoubleLinkNodePool.Recycle(pNode); m_Count--; }
/// <summary> /// 添加一个节点到尾部 /// </summary> public DoubleLinkListNode <T> AddToTail(T t) { DoubleLinkListNode <T> pList = m_DoubleLinkNodePool.Spawn(true); pList.next = null; pList.prev = null; pList.t = t; return(AddToTail(pList)); }
public bool Find(T t) { DoubleLinkListNode <T> node = null; if (!m_FindMap.TryGetValue(t, out node) || node == null) { return(false); } return(true); }
/// <summary> /// 删除某个节点 /// </summary> public void Remove(T t) { DoubleLinkListNode <T> node = null; if (!m_FindMap.TryGetValue(t, out node) || node == null) { return; } m_Dlink.RemoveNode(node); m_FindMap.Remove(t); }
/// <summary> /// 刷新某个节点,把节点移动到头部 /// </summary> public bool Refresh(T t) { DoubleLinkListNode <T> node = null; if (!m_FindMap.TryGetValue(t, out node) || node == null) { return(false); } m_Dlink.MoveToHead(node); return(true); }
/// <summary> /// 插入一个节点到表头 /// </summary> /// <param name="t"></param> public void InsertToHead(T t) { DoubleLinkListNode <T> node = null; if (m_FindMap.TryGetValue(t, out node) && node != null) { m_Dlink.AddToHeader(node); return; } m_Dlink.AddToHeader(node); m_FindMap.Add(t, m_Dlink.Head); }
/// <summary> /// 添加节点到尾部 /// </summary> public DoubleLinkListNode <T> AddToTail(DoubleLinkListNode <T> pNode) { if (pNode == null) { return(null); } pNode.next = null; if (Tail == null) { Head = Tail = pNode; } else { pNode.prev = Tail; Tail.next = pNode; Tail = pNode; } m_Count++; return(Tail); }
/// <summary> /// 添加一个头部节点 /// </summary> public DoubleLinkListNode <T> AddToHeader(DoubleLinkListNode <T> pNode) { if (pNode == null) { return(null); } pNode.prev = null; if (Head == null) { Head = Tail = pNode; } else { pNode.next = Head; Head.prev = pNode; Head = pNode; } m_Count++; return(Head); }
/// <summary> /// 将某个节点移动到头部 /// </summary> /// <param name="pNode"></param> public void MoveToHead(DoubleLinkListNode <T> pNode) { if (pNode == null || pNode == Head) { return; } if (pNode.prev == null && pNode.next == null) { return; } if (pNode == Tail) { Tail = pNode.prev; } if (pNode.prev != null) { pNode.prev.next = pNode.next; } if (pNode.next != null) { pNode.next.prev = pNode.prev; } pNode.prev = null; pNode.next = Head; Head.prev = pNode; Head = pNode; if (Tail == null) { Tail = Head; } }