public static IEnumerable <TSource> ToEnumerable <TSource>(this System.Memory <TSource> source) { for (int i = 0; i <= source.Length; i++) { yield return(source.Span[i]); } }
public static IEnumerable <IGrouping <TKey, TElement> > GroupBy <TSource, TKey, TElement> ( this System.Memory <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector ) { // Need to preserve output ordering! List <TKey> keys = new List <TKey>(); Lookup <TKey, TElement> ret = new Lookup <TKey, TElement>(); foreach (TSource item in source.ToEnumerable()) { TKey key = keySelector(item); if (ret.Add(key, elementSelector(item))) { keys.Add(key); } } foreach (TKey key in keys) { yield return(new Grouping <TKey, TElement>(key, ret[key])); } }
public static IEnumerable <TResult> GroupJoin <TOuter, TInner, TKey, TResult> ( this System.Memory <TOuter> outer, Memory <TInner> inner, Func <TOuter, TKey> outerKeySelector, Func <TInner, TKey> innerKeySelector, Func <TOuter, Memory <TInner>, TResult> resultSelector ) { ILookup <TKey, TInner> innerLookup = inner.ToLookup(innerKeySelector); foreach (TOuter outerElement in outer.ToEnumerable <TOuter>()) { TKey key = outerKeySelector(outerElement); Memory <TInner> innerMatches; if (innerLookup.Contains(key)) { innerMatches = innerLookup[key]; } else { innerMatches = Memory <TInner> .Empty; } yield return(resultSelector(outerElement, innerMatches)); } }
public static IEnumerable <TResult> Join <TOuter, TInner, TKey, TResult> ( this System.Memory <TOuter> outer, Memory <TInner> inner, Func <TOuter, TKey> outerKeySelector, Func <TInner, TKey> innerKeySelector, Func <TOuter, TInner, TResult> resultSelector ) { IEnumerable <Grouping <TOuter, TInner> > wah = outer.GroupJoin ( inner, outerKeySelector, innerKeySelector, (outerItem, sequenceOfInners) => new Grouping <TOuter, TInner>(outerItem, sequenceOfInners) ); foreach (Grouping <TOuter, TInner> grouping in wah) { foreach (var innerMatch in grouping) { yield return(resultSelector(grouping.Key, innerMatch)); } } }
public static bool SequenceEqual <TSource> ( this System.Memory <TSource> first, Memory <TSource> second ) { IEqualityComparer <TSource> comparer = EqualityComparer <TSource> .Default; using (IEnumerator <TSource> firstIterator = first.ToEnumerable().GetEnumerator()) { foreach (TSource secondElement in second.ToEnumerable()) { if (!firstIterator.MoveNext()) { // First sequence is shorter than second return(false); } if (!comparer.Equals(firstIterator.Current, secondElement)) { return(false); } } if (firstIterator.MoveNext()) { // First sequence is longer than first return(false); } } return(true); }
public static ILookup <TKey, TSource> ToLookup <TSource, TKey> ( this System.Memory <TSource> source, Func <TSource, TKey> keySelector ) { return(ToLookup(source, keySelector, element => element)); }
public static TSource First <TSource>(this System.Memory <TSource> source) { foreach (TSource element in source.ToEnumerable()) { return(element); } throw new System.InvalidOperationException("Empty sequence"); }
public static TSource FirstOrDefault <TSource>(this System.Memory <TSource> source) { foreach (TSource element in source.ToEnumerable()) { return(element); } return(default(TSource)); }
public static IEnumerable <TResult> Select <TSource, TResult> ( this System.Memory <TSource> source, Func <TSource, TResult> projection ) { return(SelectImpl(source, projection)); }
public static IEnumerable <IGrouping <TKey, TSource> > GroupBy <TSource, TKey> ( this System.Memory <TSource> source, Func <TSource, TKey> keySelector ) { return(source.GroupBy(keySelector, element => element)); }
/// <summary> /// Writes body/content bytes to the replay. /// </summary> /// <param name="bytes"> /// The number of bytes to write to the FIFO queue. /// </param> /// <returns> /// True if the write was a success, false otherwise. /// </returns> /// <remarks> /// If a return value of false is given, that means that the write that failed would have /// exceeded the upper boundary of reserved memory of buffering the replay event. In this /// case, the engine will internally abandon the replay because the user is considered to /// have failed to act on the replay, and resources must be reclaimed. /// </remarks> internal bool WriteBodyBytes(System.Memory <byte> bytes) { if (BodySize > _maxBufferSize) { return(false); } _pendingBody.Enqueue(bytes.ToArray()); return(true); }
public static double Average(this System.Memory <ulong> memory) { double sum = 0; for (int i = 0; i < memory.Length; i++) { sum += memory.Span[i]; } return(sum / memory.Length); }
public static decimal Average(this System.Memory <decimal> memory) { decimal sum = 0M; for (int i = 0; i < memory.Length; i++) { sum += memory.Span[i]; } return(sum / memory.Length); }
private static IEnumerable <TResult> SelectImpl <TSource, TResult> ( this System.Memory <TSource> source, Func <TSource, TResult> projection ) { for (int i = 0; i <= source.Length; i++) { yield return(projection(source.Span[i])); } }
public static decimal Sum(this System.Memory <decimal> m) { Span <decimal> s = m.Span; decimal sum = 0; for (int i = 0; i < s.Length; i++) { sum += s[i]; } return(sum); }
public static sbyte Sum(this System.Memory <sbyte> m) { Span <sbyte> s = m.Span; sbyte sum = 0; for (int i = 0; i < s.Length; i++) { sum += s[i]; } return(sum); }
public static ulong Sum(this System.Memory <ulong> m) { Span <ulong> s = m.Span; ulong sum = 0; for (int i = 0; i < s.Length; i++) { sum += s[i]; } return(sum); }
public static int Sum(this System.Memory <int> m) { Span <int> s = m.Span; int sum = 0; for (int i = 0; i < s.Length; i++) { sum += s[i]; } return(sum); }
public static double Sum(this System.Memory <double> m) { Span <double> s = m.Span; double sum = 0; for (int i = 0; i < s.Length; i++) { sum += s[i]; } return(sum); }
public static IOrderedEnumerable <TSource> OrderBy <TSource, TKey> ( this System.Memory <TSource> source, Func <TSource, TKey> keySelector ) { return(new OrderedEnumerable <TSource> ( source.ToEnumerable(), ProjectionComparer.Create(keySelector) )); }
public static sbyte Max(this System.Memory <sbyte> memory) { sbyte max = sbyte.MinValue; for (int i = 0; i < memory.Length; i++) { if (max < memory.Span[i]) { max = memory.Span[i]; } } return(max); }
public static sbyte Min(this System.Memory <sbyte> memory) { sbyte min = sbyte.MaxValue; for (int i = 0; i < memory.Length; i++) { if (min > memory.Span[i]) { min = memory.Span[i]; } } return(min); }
public static long Min(this System.Memory <long> memory) { long min = long.MaxValue; for (int i = 0; i < memory.Length; i++) { if (min > memory.Span[i]) { min = memory.Span[i]; } } return(min); }
public static decimal Min(this System.Memory <decimal> memory) { decimal min = decimal.MaxValue; for (int i = 0; i < memory.Length; i++) { if (min > memory.Span[i]) { min = memory.Span[i]; } } return(min); }
public static uint Min(this System.Memory <uint> memory) { uint min = uint.MaxValue; for (int i = 0; i < memory.Length; i++) { if (min > memory.Span[i]) { min = memory.Span[i]; } } return(min); }
public static double Min(this System.Memory <double> memory) { double min = double.MaxValue; for (int i = 0; i < memory.Length; i++) { if (min > memory.Span[i]) { min = memory.Span[i]; } } return(min); }
public static float Min(this System.Memory <float> memory) { float min = float.MaxValue; for (int i = 0; i < memory.Length; i++) { if (min > memory.Span[i]) { min = memory.Span[i]; } } return(min); }
public static bool Any(this System.Memory <long> x, Func <long, bool> func) { bool any = false; for (int i = 0; i < x.Length; i++) { if (func(x.Span[i])) { return(true); } } return(any); }
public static IEnumerable <TSource> Where <TSource> ( this System.Memory <TSource> source, Func <TSource, bool> predicate ) { foreach (TSource item in source.ToEnumerable()) { if (predicate(item)) { yield return(item); } } }
public static long Max(this System.Memory <long> memory) { long max = long.MinValue; for (int i = 0; i < memory.Length; i++) { if (max < memory.Span[i]) { max = memory.Span[i]; } } return(max); }