Пример #1
0
    /// <summary>
    /// 移除某个结点
    /// </summary>
    public bool RemoveNode(DoubleLinedListNode <T> pNode)
    {
        if (pNode == null)
        {
            return(false);
        }
        //if (!ContainsNode(pNode)) return false;

        if (pNode == Head)
        {
            Head         = Head.nextNode;
            Head.preNode = null;
        }
        if (pNode == Tail)
        {
            Tail          = Tail.preNode;
            Tail.nextNode = null;
        }

        if (pNode.preNode != null)
        {
            pNode.preNode.nextNode = pNode.nextNode;
        }
        if (pNode.nextNode != null)
        {
            pNode.nextNode.preNode = pNode.preNode;
        }

        pNode.Reset();
        m_DoubleLinedNodePool.UnSpawn(pNode);
        m_Count--;
        return(true);
    }
Пример #2
0
    /// <summary>
    /// 添加结点至尾部
    /// </summary>
    public DoubleLinedListNode <T> AddToTailer(T t)
    {
        DoubleLinedListNode <T> pNode = m_DoubleLinedNodePool.Spawn();

        pNode.t = t;
        return(AddToHeader(pNode));
    }
Пример #3
0
    /// <summary>
    /// 判断结点是否在列表内
    /// </summary>
    //public bool ContainsNode(DoubleLinedListNode<T> pNode)
    //{
    //    DoubleLinedListNode<T> tempNode = Head;
    //    for (int i = 0; i < m_Count; i++)
    //    {
    //        if (pNode == tempNode)
    //        {
    //            return true;
    //        }
    //        tempNode = tempNode.nextNode;
    //    }
    //    Debug.LogError("该结点不在双向列表内,无法进行操作!");
    //    return false;
    //}
    /// <summary>
    /// 将某个结点移至头结点
    /// </summary>
    public bool MoveToHeader(DoubleLinedListNode <T> pNode)
    {
        if (pNode == null)
        {
            return(false);
        }
        if (pNode.preNode == null && pNode.nextNode == null)
        {
            return(false);
        }
        //if (!ContainsNode(pNode)) return false;

        if (Tail == pNode)
        {
            Tail = pNode.preNode;
        }
        if (pNode.preNode != null)
        {
            pNode.preNode.nextNode = pNode.nextNode;
        }
        if (pNode.nextNode != null)
        {
            pNode.nextNode.preNode = pNode.preNode;
        }
        pNode.nextNode = Head;
        Head.preNode   = pNode;
        Head           = pNode;
        pNode.preNode  = null;
        //当列表只有1-2个结点时,会出现尾结点为空,这里加一个判断
        if (Tail == null)
        {
            Tail = Head;
        }
        return(true);
    }
Пример #4
0
    /// <summary>
    /// 移至头结点
    /// </summary>
    public bool MoveToHead(T t)
    {
        DoubleLinedListNode <T> node = null;

        if (m_FindMap.TryGetValue(t, out node) && node != null)
        {
            return(m_DoubleLinedList.MoveToHeader(node));
        }
        return(false);
    }
Пример #5
0
    /// <summary>
    /// 是否包含
    /// </summary>
    public bool Contains(T t)
    {
        DoubleLinedListNode <T> node = null;

        if (m_FindMap.TryGetValue(t, out node) && node != null)
        {
            return(true);
        }
        return(false);
    }
Пример #6
0
    public void Remove(T t)
    {
        DoubleLinedListNode <T> node = null;

        if (!m_FindMap.TryGetValue(t, out node) || node == null)
        {
            return;
        }
        m_DoubleLinedList.RemoveNode(node);
        m_FindMap.Remove(t);
    }
Пример #7
0
    /// <summary>
    /// 插入至尾部
    /// </summary>
    public void InsertTail(T t)
    {
        DoubleLinedListNode <T> node = null;

        if (m_FindMap.TryGetValue(t, out node) && node != null)
        {
            m_DoubleLinedList.AddToTailer(node);
            return;
        }
        m_DoubleLinedList.AddToTailer(t);
        m_FindMap.Add(t, m_DoubleLinedList.Tail);
    }
Пример #8
0
 /// <summary>
 /// 添加结点至尾部
 /// </summary>
 public DoubleLinedListNode <T> AddToTailer(DoubleLinedListNode <T> pNode)
 {
     if (pNode == null)
     {
         return(null);
     }
     if (Tail == null)
     {
         Head = Tail = pNode;
     }
     else
     {
         Tail.nextNode = pNode;
         pNode.preNode = Tail;
         Tail          = pNode;
     }
     m_Count++;
     return(Tail);
 }
Пример #9
0
 /// <summary>
 /// 添加结点至头部
 /// </summary>
 public DoubleLinedListNode <T> AddToHeader(DoubleLinedListNode <T> pNode)
 {
     if (pNode == null)
     {
         return(null);
     }
     pNode.preNode = null;
     if (Head == null)
     {
         Head = Tail = pNode;
     }
     else
     {
         Head.preNode   = pNode;
         pNode.nextNode = Head;
         Head           = pNode;
     }
     m_Count++;
     return(Head);
 }
Пример #10
0
 public void Reset()
 {
     preNode  = null;
     nextNode = null;
     t        = null;
 }