コード例 #1
0
ファイル: LinearList.cs プロジェクト: LaGuillotine/xcite
 /// <inheritdoc />
 public bool MoveNext()
 {
     if (iCurrent.Next == null)
     {
         return(false);
     }
     iCurrent = iCurrent.Next;
     return(true);
 }
コード例 #2
0
ファイル: LinearList.cs プロジェクト: LaGuillotine/xcite
            /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
            public LinearListEnumerator(LinearList <TItem> linearList)
            {
                iLinearList = linearList;

                // Must not be NULL
                iCurrent = new LinearListItem(default(TItem))
                {
                    Next = linearList._head
                };
            }
コード例 #3
0
ファイル: LinearList.cs プロジェクト: LaGuillotine/xcite
        /// <summary>
        /// Sorts the item of the collection using the given <paramref name="comparison"/>
        /// in ascending order.
        /// </summary>
        /// <param name="comparison">Comparison</param>
        private void SortInternal(Comparison <TItem> comparison)
        {
            // Note, the sort may be faster, if we use a 'sort by insert' (binary) approach

            LinearListItem currentRef = _head;

            // Iterate until the end
            while (currentRef != null)
            {
                // Current sublist head
                LinearListItem subListHead = currentRef;

                // Reference to current sublist minimum item
                LinearListItem minSublistItem = subListHead;
                TItem          minItem        = minSublistItem.Item;

                // Sublist iterator
                LinearListItem sublistCursor = subListHead;
                while (sublistCursor != null)
                {
                    TItem sublistCursorItem = sublistCursor.Item;

                    // If the current sublist cursor item is lower, we have a new minimum item
                    bool isLower = comparison(sublistCursorItem, minItem) < 0;
                    if (isLower)
                    {
                        minSublistItem = sublistCursor;
                        minItem        = sublistCursorItem;
                    }

                    // Move on
                    sublistCursor = sublistCursor.Next;
                }

                // Now we have the lowest item, so we can swap it
                if (minSublistItem != subListHead)   // Swap only if we have a real change
                {
                    TItem buffer = subListHead.Item;
                    subListHead.Item    = minSublistItem.Item;
                    minSublistItem.Item = buffer;
                }

                // Move on
                currentRef = currentRef.Next;
            }
        }
コード例 #4
0
ファイル: LinearList.cs プロジェクト: LaGuillotine/xcite
        /// <inheritdoc />
        public virtual bool Remove(TItem item)
        {
            if (item == null)
            {
                return(false);
            }

            LinearListItem precedingItem = null;
            LinearListItem current       = _head;

            while (current != null)
            {
                TItem currentItem = current.Item;

                if (!Equals(currentItem, item))
                {
                    precedingItem = current;
                    current       = current.Next;
                    continue;
                }

                // We matched the head
                if (current == _head)
                {
                    _head = current.Next;
                }

                // We matched the tail
                if (current == _tail)
                {
                    _tail = precedingItem;
                }

                // We matched any item in sequence
                if (precedingItem != null)
                {
                    precedingItem.Next = current.Next;
                }

                Count--;
                return(true);
            }

            return(false);
        }
コード例 #5
0
ファイル: LinearList.cs プロジェクト: LaGuillotine/xcite
        /// <inheritdoc />
        public virtual void Add(TItem item)
        {
            if (item == null)
            {
                return;
            }

            if (_head == null)
            {
                _head = new LinearListItem(item);
                _tail = _head;
            }
            else
            {
                LinearListItem oldTail = _tail;
                _tail        = new LinearListItem(item);
                oldTail.Next = _tail;
            }

            Count++;
        }
コード例 #6
0
ファイル: LinearList.cs プロジェクト: LaGuillotine/xcite
 /// <inheritdoc />
 public virtual void Clear()
 {
     _head = null;
     _tail = null;
     Count = 0;
 }
コード例 #7
0
ファイル: LinearList.cs プロジェクト: LaGuillotine/xcite
 /// <inheritdoc />
 public void Reset()
 => iCurrent = iLinearList._head;