Exemplo n.º 1
0
 public SequenceViewer(ISequenceView <T> collection, bool reverse = false)
 {
     ViewedCollection = collection ?? throw new ArgumentNullException(nameof(collection));
     Reverse          = reverse;
     RangeStartIndex  = -1;
     RangeCount       = -1;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Provided for deserialization for the parent.
 /// Sets this delegate collection ONLY IF it is currently null.
 /// </summary>
 /// <param name="parent">Not null.</param>
 internal void ResetCollection(ISequenceView <T> parent)
 {
     if (collection != null)
     {
         throw new ArgumentException("Collection cannot be changed.", nameof(parent));
     }
     collection = parent ?? throw new ArgumentNullException(nameof(parent));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="isStack">Specifies the mode of this collection. Notice that
 /// either mode will return elements from this collection in it's mode
 /// --- element zero in the Sequence will be the Head of this Queue or the Top of
 /// this Stack.</param>
 /// <param name="collection">Not null.</param>
 public ImmutableSequence(bool isStack, ISequenceView <T> collection)
 {
     if (collection == null)
     {
         throw new ArgumentNullException(nameof(collection));
     }
     array   = collection.ToArray();
     IsStack = isStack;
 }
Exemplo n.º 4
0
 public static T Oldest <T>(this ISequenceView <T> sequence)
 {
     if (sequence == null)
     {
         throw new ArgumentNullException(nameof(sequence));
     }
     return(sequence.IsStack
                                 ? sequence.Poke()
                                 : sequence.Peek());
 }
Exemplo n.º 5
0
 public static T TryPoke <T>(this ISequenceView <T> sequence, T returnIfEmpty)
 {
     if (sequence == null)
     {
         throw new ArgumentNullException(nameof(sequence));
     }
     return(sequence.Count == 0
                                 ? returnIfEmpty
                                 : sequence.Poke());
 }
Exemplo n.º 6
0
 public Sequence(ISequenceView <T> collection, float growFactor = 2F)
 {
     if (growFactor <= 1F)
     {
         throw new ArgumentOutOfRangeException(nameof(growFactor));
     }
     array      = collection?.ToArray() ?? throw new ArgumentNullException(nameof(collection));
     count      = array.Length;
     GrowFactor = growFactor;
     IsStack    = collection.IsStack;
     setElementType();
 }
Exemplo n.º 7
0
 public static IEnumerable <T> EnumerateInReverse <T>(this ISequenceView <T> sequenceView)
 {
     if (sequenceView == null)
     {
         throw new ArgumentNullException(nameof(sequenceView));
     }
     using (IEnumerator <T> enumerator = sequenceView.GetReverseEnumerator()) {
         while (enumerator.MoveNext())
         {
             yield return(enumerator.Current);
         }
     }
 }
Exemplo n.º 8
0
 public static bool TryPoke <T>(this ISequenceView <T> sequence, out T last)
 {
     if (sequence == null)
     {
         throw new ArgumentNullException(nameof(sequence));
     }
     if (sequence.Count == 0)
     {
         last = default;
         return(false);
     }
     last = sequence.Poke();
     return(true);
 }
Exemplo n.º 9
0
 public static bool TryPeekAt <T>(this ISequenceView <T> sequence, int index, out T element)
 {
     if (sequence == null)
     {
         throw new ArgumentNullException(nameof(sequence));
     }
     if ((index < 0) ||
         (index >= sequence.Count))
     {
         element = default;
         return(false);
     }
     element = sequence.PeekAt(index);
     return(true);
 }
Exemplo n.º 10
0
 public static IEnumerable <T> EnumerateRange <T>(
     this ISequenceView <T> sequenceView,
     int startIndex,
     int rangeCount)
 {
     if (sequenceView == null)
     {
         throw new ArgumentNullException(nameof(sequenceView));
     }
     using (IEnumerator <T> enumerator = sequenceView.GetEnumerator(startIndex, rangeCount)) {
         while (enumerator.MoveNext())
         {
             yield return(enumerator.Current);
         }
     }
 }
Exemplo n.º 11
0
 public static bool TryOldest <T>(this ISequenceView <T> sequence, out T oldest)
 {
     if (sequence == null)
     {
         throw new ArgumentNullException(nameof(sequence));
     }
     if (sequence.Count == 0)
     {
         oldest = default;
         return(false);
     }
     oldest = sequence.IsStack
                                 ? sequence.Poke()
                                 : sequence.Peek();
     return(true);
 }
Exemplo n.º 12
0
 public void FixedAddRange(
     ISequenceView <T> collection,
     bool enumerateInOrder = false,
     int?addCount          = null,
     bool countInOrder     = false)
 {
     AddRange(collection, enumerateInOrder, addCount, countInOrder);
     if (Count <= MaximumSize)
     {
         return;
     }
     T[] removed
         = IsStack
                                                 ? DropRange((Count - MaximumSize) + Overhead)
                                                 : DequeueRange((Count - MaximumSize) + Overhead);
     if (SetCapacityOnFixedAddRange)
     {
         SetCapacity(MaximumSize);
     }
     OnRemoveOverhead?.Invoke(removed);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Can be used to change the underlying collection. NOTICE that this WILL
 /// ADJUST the range by default if it is not unlimited and the values are not
 /// valid for the new collection --- but no other methods here ever make
 /// adjustments to the range (except <see cref="CheckRange"/>). This method
 /// always invokes <see cref="CheckRange"/> here, and returns that result:
 /// this <paramref name="adjustRange"/> argument is passed to that method;
 /// and if true, the range WILL be changed if not valid --- if you set this
 /// false, the range will not be changed, but may become invalid now.
 /// This method then then always returns the result of <see cref="CheckRange"/>.
 /// </summary>
 /// <param name="collection">Not null.</param>
 /// <param name="adjustRange">Defaults to TRUE: the range values WILL be CHANGED
 /// now if not valid, as documented by <see cref="CheckRange"/>. If set false,
 /// the method reports the state, and makes no changes.</param>
 /// <exception cref="ArgumentNullException"></exception>
 public bool SetCollection(ISequenceView <T> collection, bool adjustRange = true)
 {
     ViewedCollection = collection ?? throw new ArgumentNullException(nameof(collection));
     return(CheckRange(adjustRange));
 }
Exemplo n.º 14
0
 public ReadOnlySequence(ISequenceView <T> collection, int startIndex, int rangeCount)
 {
     this.collection = collection ?? throw new ArgumentNullException(nameof(collection));
     SetRange(startIndex, rangeCount);
 }
Exemplo n.º 15
0
 public ReadOnlySequence(ISequenceView <T> collection)
 {
     this.collection = collection ?? throw new ArgumentNullException(nameof(collection));
     thisStartIndex  = -1;
     thisRangeCount  = -1;
 }