Example #1
0
        /// <summary>
        /// Gets the node at a logical index by walking the linked list.
        /// </summary>
        /// <param name="index">The logical index.</param>
        /// <remarks>
        /// The caller should make sure <paramref name="index"/> is less than this node's count.
        /// </remarks>
        public SingleLinkedNode <TSource> GetNode(int index)
        {
            Debug.Assert(index >= 0 && index < GetCount());

            SingleLinkedNode <TSource> node = this;

            for (; index > 0; index--)
            {
                node = node.Linked;
            }

            Debug.Assert(node != null);
            return(node);
        }
Example #2
0
        /// <summary>
        /// Returns an <see cref="T:TSource[]"/> that contains the items of this node's singly-linked list in reverse.
        /// </summary>
        /// <param name="count">The number of items in this node.</param>
        private TSource[] ToArray(int count)
        {
            Debug.Assert(count == GetCount());

            TSource[] array = new TSource[count];
            int       index = count;

            for (SingleLinkedNode <TSource> node = this; node != null; node = node.Linked)
            {
                --index;
                array[index] = node.Item;
            }

            Debug.Assert(index == 0);
            return(array);
        }
Example #3
0
 /// <summary>
 /// Constructs a node linked to the specified node.
 /// </summary>
 /// <param name="linked">The linked node.</param>
 /// <param name="item">The item to place in this node.</param>
 private SingleLinkedNode(SingleLinkedNode <TSource> linked, TSource item)
 {
     Debug.Assert(linked != null);
     Linked = linked;
     Item   = item;
 }
Example #4
0
            internal override UnionIterator <TSource> Union(IEnumerable <TSource> next)
            {
                var sources = new SingleLinkedNode <IEnumerable <TSource> >(_first).Add(_second).Add(next);

                return(new UnionIteratorN <TSource>(sources, 2, _comparer));
            }