Ejemplo n.º 1
0
 public FastLinkedListNode <T> AddLast(T value)
 {
     if (Last == null)
     {
         Debug.Assert(First == null);
         Debug.Assert(Count == 0);
         First = Last = new FastLinkedListNode <T>()
         {
             Value = value, Next = null, Previous = null
         };
         Count++;
         return(Last);
     }
     else
     {
         Debug.Assert(First != null);
         Debug.Assert(Count >= 1);
         var oldLast = Last;
         var nn      = new FastLinkedListNode <T>()
         {
             Value = value, Next = null, Previous = oldLast
         };
         Debug.Assert(oldLast.Next == null);
         oldLast.Next = nn;
         Last         = nn;
         Count++;
         return(nn);
     }
 }
Ejemplo n.º 2
0
    public void Remove(FastLinkedListNode <T> node)
    {
        Debug.Assert(First != null && Last != null);

        if (node.Previous != null && node.Next != null)
        {
            Debug.Assert(First != null);
            Debug.Assert(Last != null);
            Debug.Assert(First != node);
            Debug.Assert(Last != node);

            node.Previous.Next = node.Next;
            node.Next.Previous = node.Previous;

            Count--;
        }
        else if (node.Previous == null && node.Next == null)
        {
            Debug.Assert(First == node);
            Debug.Assert(Last == node);

            First = Last = null;

            Count--;
        }
        else if (node.Previous != null)
        {
            Debug.Assert(First != null);
            Debug.Assert(First != node);
            Debug.Assert(Last == node);

            node.Previous.Next = null;
            Last = node.Previous;

            Count--;
        }
        else
        {
            Debug.Assert(Last != null);
            Debug.Assert(Last != node);
            Debug.Assert(First == node);

            node.Next !.Previous = null;
            First = node.Next;

            Count--;
        }
    }
Ejemplo n.º 3
0
    public void AddBefore(FastLinkedListNode <T> nextNode, FastLinkedListNode <T> chainFirst, FastLinkedListNode <T> chainLast, int chainedCount)
    {
        var prevNode = nextNode.Previous;

        Debug.Assert(First != null && Last != null);
        Debug.Assert(prevNode != null || First == nextNode);
        Debug.Assert(prevNode == null || prevNode.Next == nextNode);
        nextNode.Previous = chainLast;
        chainLast.Next    = nextNode;
        if (prevNode != null)
        {
            prevNode.Next = chainFirst;
        }
        chainFirst.Previous = prevNode;
        if (First == nextNode)
        {
            First = chainFirst;
        }
        Count += chainedCount;
    }
Ejemplo n.º 4
0
    public void AddAfter(FastLinkedListNode <T> prevNode, FastLinkedListNode <T> chainFirst, FastLinkedListNode <T> chainLast, int chainedCount)
    {
        var nextNode = prevNode.Next;

        Debug.Assert(First != null && Last != null);
        Debug.Assert(nextNode != null || Last == prevNode);
        Debug.Assert(nextNode == null || nextNode.Previous == prevNode);
        prevNode.Next       = chainFirst;
        chainFirst.Previous = prevNode;
        if (nextNode != null)
        {
            nextNode.Previous = chainLast;
        }
        chainLast.Previous = nextNode;
        if (Last == prevNode)
        {
            Last = chainLast;
        }
        Count += chainedCount;
    }
Ejemplo n.º 5
0
 public void AddLast(FastLinkedListNode <T> chainFirst, FastLinkedListNode <T> chainLast, int chainedCount)
 {
     if (Last == null)
     {
         Debug.Assert(First == null);
         Debug.Assert(Count == 0);
         First = chainFirst;
         Last  = chainLast;
         chainFirst.Previous = null;
         chainLast.Next      = null;
         Count = chainedCount;
     }
     else
     {
         Debug.Assert(First != null);
         Debug.Assert(Count >= 1);
         var oldLast = Last;
         Debug.Assert(oldLast.Next == null);
         oldLast.Next = chainFirst;
         Last         = chainLast;
         Count       += chainedCount;
     }
 }
Ejemplo n.º 6
0
    public FastLinkedListNode <T> AddBefore(FastLinkedListNode <T> nextNode, T value)
    {
        var prevNode = nextNode.Previous;

        Debug.Assert(First != null && Last != null);
        Debug.Assert(prevNode != null || First == nextNode);
        Debug.Assert(prevNode == null || prevNode.Next == nextNode);
        var nn = new FastLinkedListNode <T>()
        {
            Value = value, Next = nextNode, Previous = prevNode
        };

        nextNode.Previous = nn;
        if (prevNode != null)
        {
            prevNode.Next = nn;
        }
        if (First == nextNode)
        {
            First = nn;
        }
        Count++;
        return(nn);
    }
Ejemplo n.º 7
0
    public FastLinkedListNode <T> AddAfter(FastLinkedListNode <T> prevNode, T value)
    {
        var nextNode = prevNode.Next;

        Debug.Assert(First != null && Last != null);
        Debug.Assert(nextNode != null || Last == prevNode);
        Debug.Assert(nextNode == null || nextNode.Previous == prevNode);
        var nn = new FastLinkedListNode <T>()
        {
            Value = value, Next = nextNode, Previous = prevNode
        };

        prevNode.Next = nn;
        if (nextNode != null)
        {
            nextNode.Previous = nn;
        }
        if (Last == prevNode)
        {
            Last = nn;
        }
        Count++;
        return(nn);
    }
Ejemplo n.º 8
0
 public void Clear()
 {
     Count = 0;
     First = Last = null;
 }