diff --git a/CHANGES.md b/CHANGES.md index b55f854f429..1f9a22923ac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,6 +44,7 @@ To be released. - Removed `IBlockChainStates.GetValidatorSet(BlockHash?)` method. - (@planetarium/tx) Remove the `T` generic argument of `SignedTx`. [[#3512]] + - (Libplanet.Common) Removed `EnumerableExtensions` class. [[#3625], [#3626]] ### Backward-incompatible network protocol changes @@ -82,6 +83,8 @@ To be released. [#3540]: https://github.com/planetarium/libplanet/pull/3540 [#3583]: https://github.com/planetarium/libplanet/pull/3583 [#3589]: https://github.com/planetarium/libplanet/pull/3589 +[#3625]: https://github.com/planetarium/libplanet/issues/3625 +[#3626]: https://github.com/planetarium/libplanet/pull/3626 Version 3.9.5 diff --git a/Libplanet.Common/EnumerableExtensions.cs b/Libplanet.Common/EnumerableExtensions.cs deleted file mode 100644 index fc473932620..00000000000 --- a/Libplanet.Common/EnumerableExtensions.cs +++ /dev/null @@ -1,102 +0,0 @@ -#nullable disable -using System; -using System.Collections.Generic; -#if !NETSTANDARD2_1 -using System.Diagnostics; -#endif -using System.Linq; - -namespace Libplanet.Common -{ - public static class EnumerableExtensions - { - /// - /// Similar to - /// method, but it returns the source element with the maximum value of the given - /// , instead of the maximum value. - /// - /// The source enumerable. - /// A function to select the value to compare. - /// The type of the source elements. - /// The type of the value to compare. - /// The source element with the maximum value of the given - /// . - /// Thrown when the source sequence is empty. - /// - public static TSource Greatest( - this IEnumerable source, - Func selector - ) - where TComparable : IComparable - { - bool first = true; - TSource greatestElement = default; - TComparable greatestValue = default; - foreach (TSource element in source) - { - TComparable value = selector(element); - if (first || value.CompareTo(greatestValue) > 0) - { - greatestValue = value; - greatestElement = element; - } - - first = false; - } - - if (first) - { - throw new InvalidOperationException("Sequence contains no elements."); - } - - return greatestElement; - } - -#if !NETSTANDARD2_1 - // Copied from .NET Runtime - public static IEnumerable SkipLast( - this IEnumerable source, - int count - ) - { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - - return count <= 0 ? source.Skip(0) : SkipLastIterator(source, count); - } - - private static IEnumerable SkipLastIterator( - IEnumerable source, - int count - ) - { - Debug.Assert(source != null, $"The {nameof(source)} must not be null."); - Debug.Assert(count > 0, $"The {count} must be greater than zero."); - - var queue = new Queue(); - - using IEnumerator e = source.GetEnumerator(); - while (e.MoveNext()) - { - if (queue.Count == count) - { - do - { - yield return queue.Dequeue(); - queue.Enqueue(e.Current); - } - while (e.MoveNext()); - break; - } - else - { - queue.Enqueue(e.Current); - } - } - } -#endif - } -} diff --git a/Libplanet.Net/Swarm.cs b/Libplanet.Net/Swarm.cs index 9d4d8317cff..6e1d057343e 100644 --- a/Libplanet.Net/Swarm.cs +++ b/Libplanet.Net/Swarm.cs @@ -11,7 +11,9 @@ using Bencodex; using Libplanet.Action; using Libplanet.Blockchain; +#if NETSTANDARD2_0 using Libplanet.Common; +#endif using Libplanet.Crypto; using Libplanet.Net.Consensus; using Libplanet.Net.Messages; @@ -594,7 +596,7 @@ public async Task PreloadAsync( Block localTip = BlockChain.Tip; IBlockExcerpt topmostTip = peersWithExcerpts .Select(pair => pair.Item2) - .Greatest(tip => tip.Index); + .Aggregate((prev, next) => prev.Index > next.Index ? prev : next); if (topmostTip.Index - (i > 0 ? tipDeltaThreshold : 0L) <= localTip.Index) { const string msg =