Ejemplo n.º 1
0
 /// <summary>
 /// Appends the passed in bucket after this bucket in the list.
 /// </summary>
 /// <param name="toAppend">To append.</param>
 public void AppendAfter(ListBucket <T> toAppend)
 {
     if (toAppend == null)
     {
         return;
     }
     toAppend.Next     = this.Next;
     toAppend.Previous = this;
     this.Next         = toAppend;
     if (toAppend.Next != null)
     {
         toAppend.Next.Previous = toAppend;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts the passed in bucket before this bucket in the list
        /// </summary>
        /// <param name="toInsert">To insert.</param>
        public void InsertBefore(ListBucket <T> toInsert)
        {
            if (toInsert == null)
            {
                return;
            }

            toInsert.Previous = this.Previous;
            toInsert.Next     = this;
            this.Previous     = toInsert;
            if (toInsert.Previous != null)
            {
                toInsert.Previous.Next = toInsert;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Finds the bucket with the specified contents using the comparer func specified.
        /// </summary>
        /// <param name="contents">The contents.</param>
        /// <param name="compareFunc">The compare func.</param>
        /// <returns>
        /// the bucket with the contents or null if not found.
        /// </returns>
        /// <remarks>Uses a linear search</remarks>
        public ListBucket <T> Find(T contents, Func <T, T, bool> compareFunc)
        {
            ListBucket <T> toReturn      = null;
            ListBucket <T> currentBucket = _head;

            while (currentBucket != null)
            {
                if (compareFunc(contents, currentBucket.Contents))
                {
                    toReturn = currentBucket;
                    break;
                }
                currentBucket = currentBucket.Next;
            }
            return(toReturn);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Concats the specified list after this list in an O(1) operation.
 /// </summary>
 /// <param name="toConcat">To concat.</param>
 /// <remarks>After the concat operation, the buckets in toConcat are referenced by this list. It's not recommended to keep on
 /// working with toConcat. Instead use this instance, as all data of toConcat is now part of this instance</remarks>
 public void Concat(LinkedBucketList <T> toConcat)
 {
     if (toConcat == null)
     {
         return;
     }
     if (_head == null)
     {
         _head = toConcat.Head;
         _tail = toConcat.Tail;
     }
     else
     {
         _tail.AppendAfter(toConcat.Head);
     }
     _count += toConcat.Count;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Appends the specified bucket to the list, after the last element as a new tail.
        /// </summary>
        /// <param name="toAppend">To append.</param>
        public void AppendTail(ListBucket <T> toAppend)
        {
            if (toAppend == null)
            {
                return;
            }

            if (_head == null)
            {
                _head = toAppend;
            }
            else
            {
                _tail.AppendAfter(toAppend);
            }
            _tail = toAppend;
            _count++;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Inserts the specified bucket as the new head in the list.
        /// </summary>
        /// <param name="toInsert">To insert.</param>
        public void InsertHead(ListBucket <T> toInsert)
        {
            if (toInsert == null)
            {
                return;
            }

            if (_tail == null)
            {
                _tail = toInsert;
            }
            else
            {
                _head.InsertBefore(toInsert);
            }
            _head = toInsert;
            _count++;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Removes the specified bucket from the list.
        /// </summary>
        /// <param name="toRemove">To remove.</param>
        /// <remarks>Routine assumes the passed in bucket is in the linked bucket list managed by this instance</remarks>
        /// <returns>true if remove took place, otherwise false</returns>
        public bool Remove(ListBucket <T> toRemove)
        {
            if (toRemove == null)
            {
                return(false);
            }

            if (_head == toRemove)
            {
                _head = toRemove.Next;
            }
            if (_tail == toRemove)
            {
                _tail = toRemove.Previous;
            }

            toRemove.RemoveFromList();
            _count--;
            return(true);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Inserts the specified node toInsert before the node toInsertBefore.
 /// </summary>
 /// <param name="toInsert">To insert into the list.</param>
 /// <param name="toInsertBefore">the node to insert before. Has to be in the list</param>
 public void InsertBefore(ListBucket <T> toInsert, ListBucket <T> toInsertBefore)
 {
     if (toInsert == null)
     {
         return;
     }
     if (toInsertBefore == null)
     {
         if (_count > 0)
         {
             throw new ArgumentException("toInsertBefore can't be null when this LinkedBucketList has 1 or more elements");
         }
         InsertHead(toInsert);
     }
     else
     {
         toInsertBefore.InsertBefore(toInsert);
         _count++;
         if (toInsertBefore == _head)
         {
             _head = toInsert;
         }
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Inserts the specified node toInsert after the node toInsertAfter.
 /// </summary>
 /// <param name="toInsert">To insert into the list.</param>
 /// <param name="toInsertAfter">the node to insert after. Has to be in the list</param>
 public void InsertAfter(ListBucket <T> toInsert, ListBucket <T> toInsertAfter)
 {
     if (toInsert == null)
     {
         return;
     }
     if (toInsertAfter == null)
     {
         if (_count > 0)
         {
             throw new ArgumentException("toInsertAfter can't be null when this LinkedBucketList has 1 or more elements");
         }
         InsertHead(toInsert);
     }
     else
     {
         toInsertAfter.AppendAfter(toInsert);
         _count++;
         if (toInsertAfter == _tail)
         {
             _tail = toInsert;
         }
     }
 }