Exemplo n.º 1
0
        /// <summary>
        ///     Adds the specified item to the end of the list.
        /// </summary>
        /// <param name="item"> The item to add. </param>
        /// <returns> </returns>
        public ImmList <T> AddLast(T item)
        {
            var ret = new ImmList <T>(Root.AddLast(item, Lineage.Immutable));

            ret.Last.AssertEqual(item);
            ret.Root.Measure.AssertEqual(Root.Measure + 1);

            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Adds the specified list to the end of this one.
        /// </summary>
        /// <param name="list"> The list. </param>
        /// <returns> </returns>
        ImmList <T> AddLastList(ImmList <T> list)
        {
            if (list.IsEmpty)
            {
                return(this);
            }
            if (IsEmpty)
            {
                return(list);
            }
            var result = Root.AddLastList(list.Root, Lineage.Immutable);

            return(result.Wrap());
        }
Exemplo n.º 3
0
        ImmList <T> InsertList(int index, ImmList <T> list)
        {
            index.CheckIsBetween("index", -Root.Measure - 1, Root.Measure);
            list.CheckNotNull("list");
            index = index < 0 ? Root.Measure + index + 1 : index;
            if (index == 0)
            {
                return(list.AddLastRange(this));
            }
            if (index == Root.Measure)
            {
                return(AddLastRange(list));
            }
            var lineage = Lineage.Mutable();

            FingerTree <T> .FTree <Leaf <T> > part1, part2;
            Root.Split(index, out part1, out part2, Lineage.Immutable);
            part1 = part1.AddLastList(list.Root, Lineage.Immutable);
            var result = part1.AddLastList(part2, Lineage.Immutable);

            return(result.Wrap());
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Joins the specified list to the beginning of this one.
 /// </summary>
 /// <param name="list"> The list to join. </param>
 /// <returns> </returns>
 ImmList <T> AddFirstList(ImmList <T> list)
 {
     return(list.AddLastList(this));
 }
Exemplo n.º 5
0
 /// <summary>
 ///     Inserts a list at the specified index, pushing the element at the index forward.
 /// </summary>
 /// <param name="index">The index. Can be negative. </param>
 /// <param name="list"> The list to insert. </param>
 /// <returns> </returns>
 /// <exception cref="ArgumentNullException">Thrown if the argument is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Thrown if the index does not exist in the list.</exception>
 public ImmList <T> InsertRange(int index, ImmList <T> list)
 {
     return(InsertList(index, list));
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Concatenates another list to the beginning of this one.
 /// </summary>
 /// <param name="last">The list to add to the beginning.</param>
 /// <returns></returns>
 public ImmList <T> AddFirstRange(ImmList <T> last)
 {
     last.CheckNotNull("last");
     return(AddLastList(last));
 }
Exemplo n.º 7
0
 public ListDebugView(ImmList <T> x)
 {
     _x = x;
 }
Exemplo n.º 8
0
 public Builder(ImmList <T> inner)
 {
     _inner   = inner.Root;
     _lineage = Lineage.Mutable();
 }
Exemplo n.º 9
0
 protected override ISequentialBuilder <T, ImmList <T> > BuilderFrom(ImmList <T> collection)
 {
     return(new Builder(collection));
 }