From da76b5a88b61a2f6af196af05155f279f0e7f014 Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Fri, 21 Dec 2018 09:50:34 +0100 Subject: [PATCH] Refresh generated code --- MoreLinq/BindByIndex.cs | 143 +++++++++--------- MoreLinq/Extensions.g.cs | 54 +++++++ .../PublicAPI/net6.0/PublicAPI.Unshipped.txt | 5 + .../PublicAPI/net8.0/PublicAPI.Unshipped.txt | 5 + .../PublicAPI/net9.0/PublicAPI.Unshipped.txt | 5 + .../netstandard2.0/PublicAPI.Unshipped.txt | 5 + .../netstandard2.1/PublicAPI.Unshipped.txt | 5 + 7 files changed, 149 insertions(+), 73 deletions(-) diff --git a/MoreLinq/BindByIndex.cs b/MoreLinq/BindByIndex.cs index 4cff945ba..e707db6e1 100644 --- a/MoreLinq/BindByIndex.cs +++ b/MoreLinq/BindByIndex.cs @@ -30,7 +30,7 @@ static partial class MoreEnumerable /// Type of elements in sequence. /// Type of result elements returned. /// The source sequence. - /// The sequence of indicies. + /// The sequence of indices. /// /// TODO Complete documentation /// @@ -42,9 +42,9 @@ static partial class MoreEnumerable /// public static IEnumerable - BindByIndex(this IEnumerable source, IEnumerable indicies, + BindByIndex(this IEnumerable source, IEnumerable indices, Func missingSelector, Func resultSelector) => - BindByIndex(source, indicies, null, missingSelector, resultSelector); + BindByIndex(source, indices, null, missingSelector, resultSelector); /// /// TODO Complete documentation @@ -53,7 +53,7 @@ public static IEnumerable /// Type of elements in sequence. /// Type of result elements returned. /// The source sequence. - /// The sequence of indicies. + /// The sequence of indices. /// Size of look-back buffer. /// /// TODO Complete documentation @@ -66,77 +66,79 @@ public static IEnumerable /// public static IEnumerable - BindByIndex(this IEnumerable source, IEnumerable indicies, - int lookBackSize, - Func missingSelector, - Func resultSelector) => - BindByIndex(source, indicies, (int?) lookBackSize, missingSelector, resultSelector); + BindByIndex(this IEnumerable source, IEnumerable indices, + int lookBackSize, + Func missingSelector, + Func resultSelector) => + BindByIndex(source, indices, (int?)lookBackSize, missingSelector, resultSelector); static IEnumerable - BindByIndex(IEnumerable source, IEnumerable indicies, - int? lookBackSize, - Func missingSelector, - Func resultSelector) + BindByIndex(IEnumerable source, IEnumerable indices, + int? lookBackSize, + Func missingSelector, + Func resultSelector) { if (source == null) throw new ArgumentNullException(nameof(source)); - if (indicies == null) throw new ArgumentNullException(nameof(indicies)); + if (indices == null) throw new ArgumentNullException(nameof(indices)); if (lookBackSize < 0) throw new ArgumentOutOfRangeException(nameof(lookBackSize)); if (missingSelector == null) throw new ArgumentNullException(nameof(missingSelector)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); // TODO A version optimized for lists - return _(lookBackSize is int lbs ? lbs > 0 ? new Queue(lbs, lbs) : null - : new Queue()); + return _(lookBackSize switch + { + { } lbs and > 0 => new Queue(lbs, lbs), + 0 => null, + _ => new Queue() + }); - IEnumerable _(Queue queue) + IEnumerable _(Queue? queue) { - using (var rie = indicies.GetEnumerator()) + using var rie = indices.GetEnumerator(); + if (!rie.MoveNext()) + yield break; + + while (rie.Current < 0) { + yield return missingSelector(rie.Current); if (!rie.MoveNext()) yield break; + } - while (rie.Current < 0) - { - yield return missingSelector(rie.Current); - if (!rie.MoveNext()) - yield break; - } - - var ri = rie.Current; - var si = 0; + var ri = rie.Current; + var si = 0; - foreach (var item in source) + foreach (var item in source) + { + while (si == ri) { - while (si == ri) + yield return resultSelector(item, si); + do { - yield return resultSelector(item, si); - do + if (!rie.MoveNext()) + yield break; + ri = rie.Current; + if (ri < si) { - if (!rie.MoveNext()) - yield break; - ri = rie.Current; - if (ri < si) - { - if (si - queue?.Count is int qi && ri >= qi) - yield return resultSelector(queue[ri - qi], ri); - else - yield return missingSelector(ri); - } + if (queue is { } q && si - q.Count is var qi && ri >= qi) + yield return resultSelector(q[ri - qi], ri); + else + yield return missingSelector(ri); } - while (ri < si); } - - queue?.Enqueue(item); - si++; + while (ri < si); } - if (ri != si) - { - yield return missingSelector(ri); - while (rie.MoveNext()) - yield return missingSelector(rie.Current); - } + queue?.Enqueue(item); + si++; + } + + if (ri != si) + { + yield return missingSelector(ri); + while (rie.MoveNext()) + yield return missingSelector(rie.Current); } } } @@ -149,23 +151,13 @@ IEnumerable _(Queue queue) /// directly indexing into the queue to retrieve any one item. /// - sealed class Queue : IReadOnlyList + sealed class Queue(int maxCount = 0, int capacity = 0) : IReadOnlyList { - T[] _items; - int _firstIndex; - readonly int _maxCount; - - static readonly T[] ZeroItems = new T[0]; + T[] items = capacity > 0 ? new T[capacity] : []; + int firstIndex; + readonly int maxCount = maxCount; - public Queue(int maxCount = 0, int capacity = 0) - { - _items = capacity > 0 ? new T[capacity] : ZeroItems; - _firstIndex = 0; - _maxCount = maxCount; - Count = 0; - } - - int Capacity => _items.Length; + int Capacity => this.items.Length; public int Count { get; private set; } T IReadOnlyList.this[int index] => this[index]; @@ -175,25 +167,30 @@ public T this[int index] get { if (index < 0 || index >= Count) - throw new IndexOutOfRangeException(); + { + #pragma warning disable CA2201 // Do not raise reserved exception types + throw new IndexOutOfRangeException(); + #pragma warning restore CA2201 + } + return Cell(index); } } - ref T Cell(int index) => ref _items[(_firstIndex + index) % Capacity]; + ref T Cell(int index) => ref this.items[(this.firstIndex + index) % Capacity]; public void Enqueue(T item) { - if (_maxCount > 0 && Count == _maxCount) - Dequeue(); + if (this.maxCount > 0 && Count == this.maxCount) + _ = Dequeue(); if (Count == Capacity) { var array = new T[Math.Max(4, Capacity * 2)]; for (var i = 0; i < Count; i++) array[i] = this[i]; - _firstIndex = 0; - _items = array; + this.firstIndex = 0; + this.items = array; } Cell(Count++) = item; @@ -204,7 +201,7 @@ public T Dequeue() if (Count == 0) throw new InvalidOperationException(); var result = this[0]; - _firstIndex++; + this.firstIndex++; --Count; return result; } diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index 52f76097c..f58837a88 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -716,6 +716,60 @@ public static IEnumerable Batch(this IEnumerableBindByIndex extension. + + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class BindByIndexExtension + { + /// + /// TODO Complete documentation + /// + /// + /// Type of elements in sequence. + /// Type of result elements returned. + /// The source sequence. + /// The sequence of indices. + /// + /// TODO Complete documentation + /// + /// + /// TODO Complete documentation + /// + /// + /// TODO Complete documentation + /// + + public static IEnumerable + BindByIndex(this IEnumerable source, IEnumerable indices, + Func missingSelector, Func resultSelector) => MoreEnumerable. BindByIndex(source, indices, missingSelector, resultSelector); + + /// + /// TODO Complete documentation + /// + /// + /// Type of elements in sequence. + /// Type of result elements returned. + /// The source sequence. + /// The sequence of indices. + /// Size of look-back buffer. + /// + /// TODO Complete documentation + /// + /// + /// TODO Complete documentation + /// + /// + /// TODO Complete documentation + /// + + public static IEnumerable + BindByIndex(this IEnumerable source, IEnumerable indices, + int lookBackSize, + Func missingSelector, + Func resultSelector) => MoreEnumerable. BindByIndex(source, indices, lookBackSize, missingSelector, resultSelector); + + } + /// Cartesian extension. [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] diff --git a/MoreLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/MoreLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt index 7dc5c5811..c5f2f242d 100644 --- a/MoreLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt +++ b/MoreLinq/PublicAPI/net6.0/PublicAPI.Unshipped.txt @@ -1 +1,6 @@ #nullable enable +MoreLinq.Extensions.BindByIndexExtension +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! diff --git a/MoreLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/MoreLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt index 7dc5c5811..c5f2f242d 100644 --- a/MoreLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt +++ b/MoreLinq/PublicAPI/net8.0/PublicAPI.Unshipped.txt @@ -1 +1,6 @@ #nullable enable +MoreLinq.Extensions.BindByIndexExtension +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! diff --git a/MoreLinq/PublicAPI/net9.0/PublicAPI.Unshipped.txt b/MoreLinq/PublicAPI/net9.0/PublicAPI.Unshipped.txt index 7dc5c5811..c5f2f242d 100644 --- a/MoreLinq/PublicAPI/net9.0/PublicAPI.Unshipped.txt +++ b/MoreLinq/PublicAPI/net9.0/PublicAPI.Unshipped.txt @@ -1 +1,6 @@ #nullable enable +MoreLinq.Extensions.BindByIndexExtension +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! diff --git a/MoreLinq/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt b/MoreLinq/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt index 7dc5c5811..c5f2f242d 100644 --- a/MoreLinq/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt +++ b/MoreLinq/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt @@ -1 +1,6 @@ #nullable enable +MoreLinq.Extensions.BindByIndexExtension +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! diff --git a/MoreLinq/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt b/MoreLinq/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt index 7dc5c5811..c5f2f242d 100644 --- a/MoreLinq/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt +++ b/MoreLinq/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt @@ -1 +1,6 @@ #nullable enable +MoreLinq.Extensions.BindByIndexExtension +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.Extensions.BindByIndexExtension.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable! +static MoreLinq.MoreEnumerable.BindByIndex(this System.Collections.Generic.IEnumerable! source, System.Collections.Generic.IEnumerable! indices, int lookBackSize, System.Func! missingSelector, System.Func! resultSelector) -> System.Collections.Generic.IEnumerable!