Skip to content

Commit e9ced71

Browse files
committed
Split into many files..
1 parent 0fd22db commit e9ced71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3881
-3631
lines changed

src/Enumerators/Split/SpanSplitStringSplitOptionsWithCountEnumerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public ref struct SpanSplitStringSplitOptionsWithCountEnumerator
2929
/// <param name="count">The maximum number of sub-ReadOnlySpans to split into.</param>
3030
/// <param name="options">A bitwise combination of the enumeration values that specifies whether to trim results and include empty results.</param>
3131
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
32-
public SpanSplitStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source, char delimiter, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
32+
public SpanSplitStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source, char delimiter, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendRemainingElements)
3333
{
3434
Span = source;
3535
Delimiter = delimiter;
@@ -70,9 +70,9 @@ public bool MoveNext()
7070

7171
switch(CountExceedingBehaviour)
7272
{
73-
case CountExceedingBehaviour.CutLastElements:
73+
case CountExceedingBehaviour.CutRemainingElements:
7474
break;
75-
case CountExceedingBehaviour.AppendLastElements:
75+
case CountExceedingBehaviour.AppendRemainingElements:
7676
if(currentCount == CountMinusOne)
7777
{
7878
ReadOnlySpan<char> lower = span[..index];

src/Enumerators/Split/SpanSplitWithCountEnumerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace SpanExtensions.Enumerators
2828
/// <param name="delimiter">An instance of <typeparamref name="T"/> that delimits the various sub-ReadOnlySpans in <paramref name="source"/>.</param>
2929
/// <param name="count">The maximum number of sub-ReadOnlySpans to split into.</param>
3030
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
31-
public SpanSplitWithCountEnumerator(ReadOnlySpan<T> source, T delimiter, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
31+
public SpanSplitWithCountEnumerator(ReadOnlySpan<T> source, T delimiter, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendRemainingElements)
3232
{
3333
Span = source;
3434
Delimiter = delimiter;
@@ -67,9 +67,9 @@ public bool MoveNext()
6767
int index = span.IndexOf(Delimiter);
6868
switch(CountExceedingBehaviour)
6969
{
70-
case CountExceedingBehaviour.CutLastElements:
70+
case CountExceedingBehaviour.CutRemainingElements:
7171
break;
72-
case CountExceedingBehaviour.AppendLastElements:
72+
case CountExceedingBehaviour.AppendRemainingElements:
7373
if(currentCount == CountMinusOne)
7474
{
7575
ReadOnlySpan<T> lower = span[..index];

src/Enumerators/SplitAny/SpanSplitAnyStringSplitOptionsWithCountEnumerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public ref struct SpanSplitAnyStringSplitOptionsWithCountEnumerator
2929
/// <param name="count">The maximum number of sub-ReadOnlySpans to split into.</param>
3030
/// <param name="options">A bitwise combination of the enumeration values that specifies whether to trim results and include empty results.</param>
3131
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
32-
public SpanSplitAnyStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source, ReadOnlySpan<char> delimiters, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
32+
public SpanSplitAnyStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source, ReadOnlySpan<char> delimiters, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendRemainingElements)
3333
{
3434
Span = source;
3535
Delimiters = delimiters;
@@ -70,9 +70,9 @@ public bool MoveNext()
7070

7171
switch(CountExceedingBehaviour)
7272
{
73-
case CountExceedingBehaviour.CutLastElements:
73+
case CountExceedingBehaviour.CutRemainingElements:
7474
break;
75-
case CountExceedingBehaviour.AppendLastElements:
75+
case CountExceedingBehaviour.AppendRemainingElements:
7676
if(currentCount == CountMinusOne)
7777
{
7878
ReadOnlySpan<char> lower = span[..index];

src/Enumerators/SplitAny/SpanSplitAnyWithCountEnumerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace SpanExtensions.Enumerators
2828
/// <param name="delimiters">A <see cref="ReadOnlySpan{T}"/> with the instances of <typeparamref name="T"/> that delimit the various sub-ReadOnlySpans in <paramref name="source"/>.</param>
2929
/// <param name="count">The maximum number of sub-ReadOnlySpans to split into.</param>
3030
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
31-
public SpanSplitAnyWithCountEnumerator(ReadOnlySpan<T> source, ReadOnlySpan<T> delimiters, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
31+
public SpanSplitAnyWithCountEnumerator(ReadOnlySpan<T> source, ReadOnlySpan<T> delimiters, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendRemainingElements)
3232
{
3333
Span = source;
3434
Delimiters = delimiters;
@@ -67,9 +67,9 @@ public bool MoveNext()
6767
int index = span.IndexOfAny(Delimiters);
6868
switch(CountExceedingBehaviour)
6969
{
70-
case CountExceedingBehaviour.CutLastElements:
70+
case CountExceedingBehaviour.CutRemainingElements:
7171
break;
72-
case CountExceedingBehaviour.AppendLastElements:
72+
case CountExceedingBehaviour.AppendRemainingElements:
7373
if(currentCount == CountMinusOne)
7474
{
7575
ReadOnlySpan<T> lower = span[..index];

src/Enumerators/SplitSequence/SpanSplitSequenceStringSplitOptionsWithCountEnumerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ref struct SpanSplitSequenceStringSplitOptionsWithCountEnumerator
2828
/// <param name="options">A bitwise combination of the enumeration values that specifies whether to trim results and include empty results.</param>
2929
/// <param name="count">The maximum number of sub-ReadOnlySpans to split into.</param>
3030
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
31-
public SpanSplitSequenceStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source, ReadOnlySpan<char> delimiter, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
31+
public SpanSplitSequenceStringSplitOptionsWithCountEnumerator(ReadOnlySpan<char> source, ReadOnlySpan<char> delimiter, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendRemainingElements)
3232
{
3333
Span = source;
3434
Delimiter = delimiter;
@@ -69,9 +69,9 @@ public bool MoveNext()
6969

7070
switch(CountExceedingBehaviour)
7171
{
72-
case CountExceedingBehaviour.CutLastElements:
72+
case CountExceedingBehaviour.CutRemainingElements:
7373
break;
74-
case CountExceedingBehaviour.AppendLastElements:
74+
case CountExceedingBehaviour.AppendRemainingElements:
7575
if(currentCount == CountMinusOne)
7676
{
7777
ReadOnlySpan<char> lower = span[..index];

src/Enumerators/SplitSequence/SpanSplitSequenceWithCountEnumerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace SpanExtensions.Enumerators
2828
/// <param name="delimiter">An instance of <see cref="ReadOnlySpan{T}"/> that delimits the various sub-ReadOnlySpans in <paramref name="source"/>.</param>
2929
/// <param name="count">The maximum number of sub-ReadOnlySpans to split into.</param>
3030
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
31-
public SpanSplitSequenceWithCountEnumerator(ReadOnlySpan<T> source, ReadOnlySpan<T> delimiter, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
31+
public SpanSplitSequenceWithCountEnumerator(ReadOnlySpan<T> source, ReadOnlySpan<T> delimiter, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendRemainingElements)
3232
{
3333
Span = source;
3434
Delimiter = delimiter;
@@ -67,9 +67,9 @@ public bool MoveNext()
6767
int index = span.IndexOf(Delimiter);
6868
switch(CountExceedingBehaviour)
6969
{
70-
case CountExceedingBehaviour.CutLastElements:
70+
case CountExceedingBehaviour.CutRemainingElements:
7171
break;
72-
case CountExceedingBehaviour.AppendLastElements:
72+
case CountExceedingBehaviour.AppendRemainingElements:
7373
if(currentCount == CountMinusOne)
7474
{
7575
ReadOnlySpan<T> lower = span[..index];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
namespace SpanExtensions
4+
{
5+
public static partial class ReadOnlySpanExtensions
6+
{
7+
/// <summary>
8+
/// Determines whether all elements in <paramref name="source"/> satisfy a condition.
9+
/// </summary>
10+
/// <typeparam name="T">The type of elements in the <see cref="ReadOnlySpan{T}"/>.</typeparam>
11+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to operate on.</param>
12+
/// <param name="predicate">The condition to be satisfied.</param>
13+
/// <returns>A <see cref="bool"/> indicating whether or not every element in <paramref name="source"/> satisified the condition.</returns>
14+
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
15+
public static bool All<T>(this ReadOnlySpan<T> source, Predicate<T> predicate)
16+
{
17+
for(int i = 0; i < source.Length; i++)
18+
{
19+
if(!predicate(source[i]))
20+
{
21+
return false;
22+
}
23+
}
24+
return true;
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
namespace SpanExtensions
4+
{
5+
public static partial class ReadOnlySpanExtensions
6+
{
7+
/// <summary>
8+
/// Determines whether any element in <paramref name="source"/> satisfies a condition.
9+
/// </summary>
10+
/// <typeparam name="T">The type of elements in the <see cref="ReadOnlySpan{T}"/>.</typeparam>
11+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to operate on.</param>
12+
/// <param name="predicate">The condition to be satisfied.</param>
13+
/// <returns>A <see cref="bool"/> indicating whether or not any elements satisified the condition.</returns>
14+
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
15+
public static bool Any<T>(this ReadOnlySpan<T> source, Predicate<T> predicate)
16+
{
17+
for(int i = 0; i < source.Length; i++)
18+
{
19+
if(predicate(source[i]))
20+
{
21+
return true;
22+
}
23+
}
24+
return false;
25+
}
26+
}
27+
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
using System;
2+
using System.Numerics;
3+
4+
namespace SpanExtensions
5+
{
6+
public static partial class ReadOnlySpanExtensions
7+
{
8+
9+
#if NET7_0_OR_GREATER
10+
11+
/// <summary>
12+
/// Computes the Average of all the values in <paramref name="source"/>.
13+
/// </summary>
14+
/// <typeparam name="T">The type of elements in the <see cref="ReadOnlySpan{T}"/>.</typeparam>
15+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to operate on.</param>
16+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
17+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
18+
public static T Average<T>(this ReadOnlySpan<T> source) where T : INumberBase<T>
19+
{
20+
T sum = source.Sum();
21+
return sum / T.CreateChecked(source.Length);
22+
}
23+
#else
24+
25+
#if NET5_0_OR_GREATER
26+
27+
/// <summary>
28+
/// Computes the Average of all the values in <paramref name="source"/>.
29+
/// </summary>
30+
/// <param name="source">The <see cref="ReadOnlySpan{Half}"/> to operate on.</param>
31+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
32+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
33+
public static Half Average(this ReadOnlySpan<Half> source)
34+
{
35+
Half sum = source.Sum();
36+
return (Half)((float)sum / source.Length);
37+
}
38+
#endif
39+
40+
/// <summary>
41+
/// Computes the Average of all the values in <paramref name="source"/>.
42+
/// </summary>
43+
/// <param name="source">The <see cref="ReadOnlySpan{Byte}"/> to operate on.</param>
44+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
45+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
46+
public static byte Average(this ReadOnlySpan<byte> source)
47+
{
48+
byte sum = source.Sum();
49+
return (byte)(sum / source.Length);
50+
}
51+
52+
/// <summary>
53+
/// Computes the Average of all the values in <paramref name="source"/>.
54+
/// </summary>
55+
/// <param name="source">The <see cref="ReadOnlySpan{UInt16}"/> to operate on.</param>
56+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
57+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
58+
public static ushort Average(this ReadOnlySpan<ushort> source)
59+
{
60+
ushort sum = source.Sum();
61+
return (ushort)(sum / source.Length);
62+
}
63+
64+
/// <summary>
65+
/// Computes the Average of all the values in <paramref name="source"/>.
66+
/// </summary>
67+
/// <param name="source">The <see cref="ReadOnlySpan{uint32}"/> to operate on.</param>
68+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
69+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
70+
public static uint Average(this ReadOnlySpan<uint> source)
71+
{
72+
uint sum = source.Sum();
73+
return (uint)(sum / source.Length);
74+
}
75+
76+
/// <summary>
77+
/// Computes the Average of all the values in <paramref name="source"/>.
78+
/// </summary>
79+
/// <param name="source">The <see cref="ReadOnlySpan{UInt64}"/> to operate on.</param>
80+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
81+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
82+
public static ulong Average(this ReadOnlySpan<ulong> source)
83+
{
84+
ulong sum = source.Sum();
85+
return sum / (ulong)source.Length;
86+
}
87+
88+
/// <summary>
89+
/// Computes the Average of all the values in <paramref name="source"/>.
90+
/// </summary>
91+
/// <param name="source">The <see cref="ReadOnlySpan{SByte}"/> to operate on.</param>
92+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
93+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
94+
public static sbyte Average(this ReadOnlySpan<sbyte> source)
95+
{
96+
sbyte sum = source.Sum();
97+
return (sbyte)(sum / source.Length);
98+
}
99+
100+
/// <summary>
101+
/// Computes the Average of all the values in <paramref name="source"/>.
102+
/// </summary>
103+
/// <param name="source">The <see cref="ReadOnlySpan{Int16}"/> to operate on.</param>
104+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
105+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
106+
public static short Average(this ReadOnlySpan<short> source)
107+
{
108+
short sum = source.Sum();
109+
return (short)(sum / source.Length);
110+
}
111+
112+
/// <summary>
113+
/// Computes the Average of all the values in <paramref name="source"/>.
114+
/// </summary>
115+
/// <param name="source">The <see cref="ReadOnlySpan{Int32}"/> to operate on.</param>
116+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
117+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
118+
public static int Average(this ReadOnlySpan<int> source)
119+
{
120+
int sum = source.Sum();
121+
return sum / source.Length;
122+
}
123+
124+
/// <summary>
125+
/// Computes the Average of all the values in <paramref name="source"/>.
126+
/// </summary>
127+
/// <param name="source">The <see cref="ReadOnlySpan{Int64}"/> to operate on.</param>
128+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
129+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
130+
public static long Average(this ReadOnlySpan<long> source)
131+
{
132+
long sum = source.Sum();
133+
return (sum / source.Length);
134+
}
135+
136+
/// <summary>
137+
/// Computes the Average of all the values in <paramref name="source"/>.
138+
/// </summary>
139+
/// <param name="source">The <see cref="ReadOnlySpan{Single}"/> to operate on.</param>
140+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
141+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
142+
public static float Average(this ReadOnlySpan<float> source)
143+
{
144+
float sum = source.Sum();
145+
return (float)(sum / source.Length);
146+
}
147+
148+
/// <summary>
149+
/// Computes the Average of all the values in <paramref name="source"/>.
150+
/// </summary>
151+
/// <param name="source">The <see cref="ReadOnlySpan{Double}"/> to operate on.</param>
152+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
153+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
154+
public static double Average(this ReadOnlySpan<double> source)
155+
{
156+
double sum = source.Sum();
157+
return (double)(sum / source.Length);
158+
}
159+
160+
/// <summary>
161+
/// Computes the Average of all the values in <paramref name="source"/>.
162+
/// </summary>
163+
/// <param name="source">The <see cref="ReadOnlySpan{Int64}"/> to operate on.</param>
164+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
165+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
166+
public static decimal Average(this ReadOnlySpan<decimal> source)
167+
{
168+
decimal sum = source.Sum();
169+
return sum / source.Length;
170+
}
171+
172+
/// <summary>
173+
/// Computes the Average of all the values in <paramref name="source"/>.
174+
/// </summary>
175+
/// <param name="source">The <see cref="ReadOnlySpan{BigInteger}"/> to operate on.</param>
176+
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
177+
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
178+
public static BigInteger Average(this ReadOnlySpan<BigInteger> source)
179+
{
180+
BigInteger sum = source.Sum();
181+
return sum / source.Length;
182+
}
183+
#endif
184+
}
185+
}

0 commit comments

Comments
 (0)