Exemple #1
0
        public FVList <T> InsertRange(int index, IList <T> list)
        {
            this = VListBlock <T> .InsertRange(_block, _localCount, list, index, false);

            return(this);
        }
Exemple #2
0
 public RVList <T> WithoutLast(int offset)
 {
     return(VListBlock <T> .SubList(_block, _localCount, offset).ToRVList());
 }
Exemple #3
0
 public FVList <T> PreviousIn(FVList <T> largerList)
 {
     return(VListBlock <T> .BackUpOnce(this, largerList));
 }
Exemple #4
0
 public RVList(T itemZero, T itemOne)
 {
     _block      = new VListBlockOfTwo <T>(itemZero, itemOne, false);
     _localCount = 2;
 }
Exemple #5
0
 /// <summary>Transforms a list (combines filtering with selection and more).</summary>
 /// <param name="x">Method to apply to each item in the list</param>
 /// <returns>A list formed from transforming all items in the list</returns>
 /// <remarks>See the documentation of FVList.Transform() for more information.</remarks>
 public RVList <T> Transform(VListTransformer <T> x)
 {
     return((RVList <T>) VListBlock <T> .Transform(_block, _localCount, x, true, null));
 }
Exemple #6
0
 /// <summary>Returns the RVList converted to an array.</summary>
 public T[] ToArray()
 {
     return(VListBlock <T> .ToArray(_block, _localCount, true));
 }
Exemple #7
0
 internal RVList(VListBlock <T> block, int localCount)
 {
     _block      = block;
     _localCount = localCount;
 }
Exemple #8
0
 protected internal WListBase(VListBlock <T> block, int localCount, bool isOwner)
     : base(block, localCount, isOwner)
 {
 }
Exemple #9
0
        public FWList <T> Clone()
        {
            VListBlock <T> .EnsureImmutable(Block, LocalCount);

            return(new FWList <T>(Block, LocalCount, false));
        }
Exemple #10
0
 public VList <T> WithoutLast(int numToRemove)
 {
     return(VListBlock <T> .EnsureImmutable(Block, LocalCount - numToRemove).ToVList());
 }
Exemple #11
0
 /// <summary>Inserts an item at the "front" of the list,
 /// which is index 0 for FWList, or Count for WList.</summary>
 protected void Add(T item)
 {
     VListBlock <T> .MuAdd(this, item);
 }
Exemple #12
0
 public FVList <T> WithoutFirst(int offset)
 {
     return(VListBlock <T> .SubList(_block, _localCount, offset));
 }
Exemple #13
0
 public FVList(IList <T> list)
 {
     _block      = null;
     _localCount = 0;
     AddRange(list);
 }
Exemple #14
0
 /// <summary>Transforms a list (combines filtering with selection and more).</summary>
 /// <param name="x">Method to apply to each item in the list</param>
 /// <returns>A list formed from transforming all items in the list</returns>
 /// <remarks>
 /// This is my attempt to make an optimized multi-purpose routine for
 /// transforming a FVList or RVList. It is slightly cumbersome to use,
 /// but allows you to do several common operations in one transformer
 /// method.
 /// <para/>
 /// The VListTransformer method takes two arguments: an item and its index
 /// in the FVList or RVList. It can modify the item if desired, and then it
 /// returns a XfAction value, which indicates the action to take. Most
 /// often you will return XfAction.Drop, XfAction.Keep, XfAction.Change,
 /// which, repectively, drop the item from the output list, copy the item
 /// to the output list unchanged (even if you modified the item), and
 /// copy the item to the output list (assuming you changed it).
 /// <para/>
 /// Transform() needs to know if the item changed, at least at first,
 /// because if the first items are kept without changes, then the output
 /// list can share a common tail with the input list. If the transformer
 /// method returns XfAction.Keep for every element, then the output list
 /// is exactly the same (operator== returns true).
 /// <para/>
 /// Of course, it would have been simpler just to return a boolean
 /// indicating whether to keep the item, and the Transform method itself
 /// could check whether the item changed. But checking for equality is
 /// a tad slow in the .NET framework, because there is no bitwise
 /// equality operator in .NET, so a virtual function would have to be
 /// called instead to test equality, which is especially slow if T is a
 /// value type that does not implement IEquatable(of T).
 /// <para/>
 /// The final possible action, XfAction.Repeat, is like XfAction.Change
 /// except that Transform() calls the VListTransformer again. The second
 /// call has the form x(~i, ref item), where ~i is the bitwise NOT of the
 /// index i, and item is the same item that x returned the first time it
 /// was called. On the second call, x() can return XfAction.Change again
 /// to get a third call, if it wants.
 /// <para/>
 /// XfAction.Repeat is best explained by example. In the following
 /// examples, assume "list" is an RVList holding the numbers (1, 2, 3):
 /// <example>
 /// output = list.Transform((i, ref n) => {
 ///     // This example produces (1, 1, 2, 2, 3, 3)
 ///     return i >= 0 ? XfAction.Repeat : XfAction.Keep;
 /// });
 ///
 /// output = list.Transform((i, ref n) => {
 ///     // This example produces (1, 10, 2, 20, 3, 30)
 ///     if (i >= 0)
 ///         return XfAction.Repeat;
 ///     n *= 10;
 ///     return XfAction.Change;
 /// });
 ///
 /// output = list.Transform((i, ref n) => {
 ///     // This example produces (10, 1, 20, 2, 30, 3)
 ///     if (i >= 0) {
 ///         n *= 10;
 ///         return XfAction.Repeat;
 ///     }
 ///     return XfAction.Keep;
 /// });
 ///
 /// output = list.Transform((i, ref n) => {
 ///     // This example produces (10, 100, 1000, 20, 200, 30, 300)
 ///     n *= 10;
 ///     if (n > 1000)
 ///         return XfAction.Drop;
 ///     return XfAction.Repeat;
 /// });
 /// </example>
 /// And now for some examples using XfAction.Keep, XfAction.Drop and
 /// XfAction.Change. Assume list is an RVList holding the following
 /// integers: (-1, 2, -2, 13, 5, 8, 9)
 /// <example>
 /// output = list.Transform((i, ref n) =>
 /// {   // Keep every second item: (2, 13, 8)
 ///     return (i % 2) == 1 ? XfAction.Keep : XfAction.Drop;
 /// });
 ///
 /// output = list.Transform((i, ref n) =>
 /// {   // Keep odd numbers: (-1, 13, 5, 9)
 ///     return (n % 2) != 0 ? XfAction.Keep : XfAction.Drop;
 /// });
 ///
 /// output = list.Transform((i, ref n) =>
 /// {   // Keep and square all odd numbers: (1, 169, 25, 81)
 ///     if ((n % 2) != 0) {
 ///         n *= n;
 ///         return XfAction.Change;
 ///     } else
 ///         return XfAction.Drop;
 /// });
 ///
 /// output = list.Transform((i, ref n) =>
 /// {   // Increase each item by its index: (-1, 3, 0, 16, 9, 13, 15)
 ///     n += i;
 ///     return i == 0 ? XfAction.Keep : XfAction.Change;
 /// });
 /// </example>
 /// </remarks>
 public FVList <T> Transform(VListTransformer <T> x)
 {
     return(VListBlock <T> .Transform(_block, _localCount, x, false, null));
 }
Exemple #15
0
        public RVList <T> AddRange(IEnumerable <T> list)
        {
            this = VListBlock <T> .AddRange(_block, _localCount, list.GetEnumerator());

            return(this);
        }
Exemple #16
0
 public FVList <T> WithoutFirst(int numToRemove)
 {
     return(VListBlock <T> .EnsureImmutable(Block, LocalCount - numToRemove));
 }
Exemple #17
0
        public RVList <T> InsertRange(int index, IList <T> list)
        {
            this = VListBlock <T> .InsertRange(_block, _localCount, list, Count - index, true).ToRVList();

            return(this);
        }
Exemple #18
0
        /// <summary>Returns this list as an RWList, which effectively reverses
        /// the order of the elements.</summary>
        /// <remarks>This operation marks the items of the list as immutable.
        /// You can modify either list afterward, but some or all of the list
        /// may have to be copied.</remarks>
        public RWList <T> ToRWList()
        {
            VListBlock <T> .EnsureImmutable(Block, LocalCount);

            return(new RWList <T>(Block, LocalCount, false));
        }
Exemple #19
0
 public RVList <T> Clear()
 {
     _block      = null;
     _localCount = 0;
     return(this);
 }
Exemple #20
0
 /// <summary>Returns the FWList converted to an array.</summary>
 public T[] ToArray()
 {
     return(VListBlock <T> .ToArray(Block, LocalCount, false));
 }
Exemple #21
0
 public RVList(T firstItem)
 {
     _block      = new VListBlockOfTwo <T>(firstItem, false);
     _localCount = 1;
 }
Exemple #22
0
 internal FWList(VListBlock <T> block, int localCount, bool isOwner)
     : base(block, localCount, isOwner)
 {
 }
Exemple #23
0
 /// <summary>Maps a list to another list of the same length.</summary>
 /// <param name="map">A function that transforms each item in the list.</param>
 /// <returns>The list after the map function is applied to each item. The
 /// original RVList structure is not modified.</returns>
 public RVList <Out> Select <Out>(Func <T, Out> map)
 {
     return((RVList <Out>) VListBlock <T> .Select <Out>(_block, _localCount, map, null));
 }
Exemple #24
0
        }                          // empty list is all null

        public FWList(int initialSize)
        {
            VListBlock <T> .MuAddEmpty(this, initialSize);
        }
Exemple #25
0
 public RVList(IEnumerable <T> list)
 {
     _block      = null;
     _localCount = 0;
     AddRange(list);
 }
Exemple #26
0
        public RVList <T> AddRange(RVList <T> list, RVList <T> excludeSubList)
        {
            this = VListBlock <T> .AddRange(_block, _localCount, list.ToFVList(), excludeSubList.ToFVList()).ToRVList();

            return(this);
        }
Exemple #27
0
 public RVList <T> NextIn(RVList <T> largerList)
 {
     return(VListBlock <T> .BackUpOnce(this, largerList));
 }
Exemple #28
0
        public RVList <T> AddRange(IList <T> list)
        {
            this = VListBlock <T> .AddRange(_block, _localCount, list, true).ToRVList();

            return(this);
        }
Exemple #29
0
        public FVList <T> AddRange(FVList <T> list, FVList <T> excludeSubList)
        {
            this = VListBlock <T> .AddRange(_block, _localCount, list, excludeSubList);

            return(this);
        }
Exemple #30
0
        public FVList <T> AddRange(IList <T> list)
        {
            this = VListBlock <T> .AddRange(_block, _localCount, list, false);

            return(this);
        }