Пример #1
0
        /// <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--;
        }
Пример #2
0
        /// <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));
        }
Пример #3
0
        public bool Find(T t)
        {
            DoubleLinkListNode <T> node = null;

            if (!m_FindMap.TryGetValue(t, out node) || node == null)
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
        /// <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);
        }
Пример #8
0
        /// <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);
        }
Пример #9
0
        /// <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;
            }
        }