public SequenceViewer(ISequenceView <T> collection, bool reverse = false) { ViewedCollection = collection ?? throw new ArgumentNullException(nameof(collection)); Reverse = reverse; RangeStartIndex = -1; RangeCount = -1; }
/// <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)); }
/// <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; }
public static T Oldest <T>(this ISequenceView <T> sequence) { if (sequence == null) { throw new ArgumentNullException(nameof(sequence)); } return(sequence.IsStack ? sequence.Poke() : sequence.Peek()); }
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()); }
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(); }
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); } } }
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); }
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); }
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); } } }
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); }
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); }
/// <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)); }
public ReadOnlySequence(ISequenceView <T> collection, int startIndex, int rangeCount) { this.collection = collection ?? throw new ArgumentNullException(nameof(collection)); SetRange(startIndex, rangeCount); }
public ReadOnlySequence(ISequenceView <T> collection) { this.collection = collection ?? throw new ArgumentNullException(nameof(collection)); thisStartIndex = -1; thisRangeCount = -1; }