From af5a76bca8482ae5efbd10db8937bf2bdfe6ab55 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 18:32:38 +0000 Subject: [PATCH] refactor!: remove Count for Span and ROSpan --- CHANGELOG.md | 4 +++ X10D.Tests/src/Collections/SpanTest.cs | 40 -------------------------- X10D/src/Collections/SpanExtensions.cs | 37 ------------------------ 3 files changed, 4 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3217162..b7e782b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - X10D: Removed `DateOnly.Deconstruct` due to conflict with [`System.DateOnly.Deconstruct`](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.deconstruct?view=net-8.0). +- X10D: Removed `Span.Count` due to conflict with +[`System.MemoryExtensions.Count`](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.count?view=net-8.0). +- X10D: Removed `ReadOnlySpan.Count` due to conflict with +[`System.MemoryExtensions.Count`](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.count?view=net-8.0). - X10D: Removed `Span.Split` for .NET 9.0 target due to conflicts with [`System.MemoryExtensions.Split`](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.split?view=net-9.0). diff --git a/X10D.Tests/src/Collections/SpanTest.cs b/X10D.Tests/src/Collections/SpanTest.cs index 1f0b58a..d0b12d0 100644 --- a/X10D.Tests/src/Collections/SpanTest.cs +++ b/X10D.Tests/src/Collections/SpanTest.cs @@ -8,46 +8,6 @@ namespace X10D.Tests.Collections; [TestFixture] internal class SpanTest { - [Test] - public void Count_ShouldReturn0_GivenEmptySpan() - { - Span span = Span.Empty; - - int count = span.Count(2); - - Assert.That(count, Is.Zero); - } - - [Test] - public void Count_ShouldReturn0_GivenEmptyReadOnlySpan() - { - ReadOnlySpan span = ReadOnlySpan.Empty; - - int count = span.Count(2); - - Assert.That(count, Is.Zero); - } - - [Test] - public void Count_ShouldReturn8_GivenSpanWith8MatchingElements() - { - Span span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2]; - - int count = span.Count(2); - - Assert.That(count, Is.EqualTo(8)); - } - - [Test] - public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements() - { - ReadOnlySpan span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2]; - - int count = span.Count(2); - - Assert.That(count, Is.EqualTo(8)); - } - [Test] public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32() { diff --git a/X10D/src/Collections/SpanExtensions.cs b/X10D/src/Collections/SpanExtensions.cs index d063dd9..80add99 100644 --- a/X10D/src/Collections/SpanExtensions.cs +++ b/X10D/src/Collections/SpanExtensions.cs @@ -5,43 +5,6 @@ namespace X10D.Collections; /// public static class SpanExtensions { - /// - /// Returns the number of times that a specified element appears in a span of elements of the same type. - /// - /// The source to search. - /// The element to count. - /// The type of elements in . - /// The number of times that appears in . - public static int Count(this in Span source, T element) - where T : IEquatable - { - return source.AsReadOnly().Count(element); - } - - /// - /// Returns the number of times that a specified element appears in a read-only span of elements of the same type. - /// - /// The source to search. - /// The element to count. - /// The type of elements in . - /// The number of times that appears in . - public static int Count(this in ReadOnlySpan source, T element) - where T : IEquatable - { - var count = 0; - - for (var index = 0; index < source.Length; index++) - { - T item = source[index]; - if (item.Equals(element)) - { - count++; - } - } - - return count; - } - /// /// Returns a read-only wrapper for the current span. ///