Skip to content

Commit e7968a9

Browse files
committed
.
1 parent 848e267 commit e7968a9

19 files changed

+441
-109
lines changed

api_list.include.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,14 @@
665665
* `int CommonPrefixLength<T>(ReadOnlySpan<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-10.0#system-memoryextensions-commonprefixlength-1(system-span((-0))-system-readonlyspan((-0))))
666666
* `bool Contains<T>(T) where T : IEquatable<T>` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-10.0#system-memoryextensions-contains-1(system-span((-0))-0))
667667
* `void Sort<T>(Comparison<T>)`
668-
* `void Sort<T>() where T : IComparable<T>`
668+
* `void Sort<T>() where T : IComparable<T>` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-1(system-span((-0))))
669669

670670

671671
#### Span<TKey>
672672

673-
* `void Sort<TKey, TValue, TComparer>(Span<TValue>, TComparer) where TComparer : IComparer<TKey>`
674-
* `void Sort<TKey, TValue>(Span<TValue>, Comparison<TKey>)`
675-
* `void Sort<TKey, TValue>(Span<TValue>)`
673+
* `void Sort<TKey, TValue, TComparer>(Span<TValue>, TComparer) where TComparer : IComparer<TKey>` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-3(system-span((-0))-system-span((-1))-2))
674+
* `void Sort<TKey, TValue>(Span<TValue>, Comparison<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-2(system-span((-0))-system-span((-1))-system-comparison((-0))))
675+
* `void Sort<TKey, TValue>(Span<TValue>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-2(system-span((-0))-system-span((-1))))
676676

677677

678678
#### Stack<T>

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,14 +1110,14 @@ The class `Polyfill` includes the following extension methods:
11101110
* `int CommonPrefixLength<T>(ReadOnlySpan<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-10.0#system-memoryextensions-commonprefixlength-1(system-span((-0))-system-readonlyspan((-0))))
11111111
* `bool Contains<T>(T) where T : IEquatable<T>` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-10.0#system-memoryextensions-contains-1(system-span((-0))-0))
11121112
* `void Sort<T>(Comparison<T>)`
1113-
* `void Sort<T>() where T : IComparable<T>`
1113+
* `void Sort<T>() where T : IComparable<T>` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-1(system-span((-0))))
11141114

11151115

11161116
#### Span<TKey>
11171117

1118-
* `void Sort<TKey, TValue, TComparer>(Span<TValue>, TComparer) where TComparer : IComparer<TKey>`
1119-
* `void Sort<TKey, TValue>(Span<TValue>, Comparison<TKey>)`
1120-
* `void Sort<TKey, TValue>(Span<TValue>)`
1118+
* `void Sort<TKey, TValue, TComparer>(Span<TValue>, TComparer) where TComparer : IComparer<TKey>` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-3(system-span((-0))-system-span((-1))-2))
1119+
* `void Sort<TKey, TValue>(Span<TValue>, Comparison<TKey>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-2(system-span((-0))-system-span((-1))-system-comparison((-0))))
1120+
* `void Sort<TKey, TValue>(Span<TValue>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-2(system-span((-0))-system-span((-1))))
11211121

11221122

11231123
#### Stack<T>

src/Polyfill/Polyfill_Memory_SpanSort.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
3030
try
3131
{
3232
source.CopyTo(array);
33-
Array.Sort(array, comparison);
33+
Array.Sort(array, 0, source.Length, Comparer<T>.Create(comparison));
3434

3535
array.AsSpan(0, source.Length).CopyTo(source);
3636
}
@@ -68,7 +68,7 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
6868
keys.CopyTo(keysArray);
6969
values.CopyTo(valsArray);
7070

71-
Array.Sort(keysArray, valsArray, comparer);
71+
Array.Sort(keysArray, valsArray, 0, keys.Length, comparer);
7272

7373
keysArray.AsSpan(0, keys.Length).CopyTo(keys);
7474
valsArray.AsSpan(0, values.Length).CopyTo(values);

src/Split/net461/Polyfill_Memory_SpanSort.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ namespace Polyfills;
77
using System.Buffers;
88
static partial class Polyfill
99
{
10+
/// <summary>
11+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the <see cref="IComparable{T}"/> implementation of each element of the <see cref="Span{T}"/>.
12+
/// </summary>
1013
public static void Sort<T>(this Span<T> source)
1114
where T : IComparable<T>
1215
=> Sort(source, (x, y) => x.CompareTo(y));
16+
/// <summary>
17+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the specified <see cref="Comparison{T}"/>.
18+
/// </summary>
19+
/// Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-1(system-span((-0))-system-comparison((-0)))
1320
public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1421
{
1522
if((Comparison<T>?)comparison is null)
@@ -18,16 +25,22 @@ public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1825
try
1926
{
2027
source.CopyTo(array);
21-
Array.Sort(array, comparison);
28+
Array.Sort(array, 0, source.Length, Comparer<T>.Create(comparison));
2229
array.AsSpan(0, source.Length).CopyTo(source);
2330
}
2431
finally
2532
{
2633
ArrayPool<T>.Shared.Return(array);
2734
}
2835
}
36+
/// <summary>
37+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the <see cref=" IComparable{T}"/> implementation of each key.
38+
/// </summary>
2939
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values)
3040
=> Sort(keys, values, Comparer<TKey>.Default);
41+
/// <summary>
42+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparer.
43+
/// </summary>
3144
public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TValue> values, TComparer comparer)
3245
where TComparer : IComparer<TKey>
3346
{
@@ -40,7 +53,7 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
4053
{
4154
keys.CopyTo(keysArray);
4255
values.CopyTo(valsArray);
43-
Array.Sort(keysArray, valsArray, comparer);
56+
Array.Sort(keysArray, valsArray, 0, keys.Length, comparer);
4457
keysArray.AsSpan(0, keys.Length).CopyTo(keys);
4558
valsArray.AsSpan(0, values.Length).CopyTo(values);
4659
}
@@ -50,9 +63,12 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
5063
ArrayPool<TValue>.Shared.Return(valsArray);
5164
}
5265
}
53-
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values, Comparison<TKey> comparison)
54-
=> Sort(keys, values, new ComparerWrapper<TKey>(comparison));
55-
private class ComparerWrapper<T> : IComparer<T>
66+
/// <summary>
67+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparison.
68+
/// </summary>
69+
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> items, Comparison<TKey> comparison)
70+
=> Sort(keys, items, new ComparerWrapper<TKey>(comparison));
71+
class ComparerWrapper<T> : IComparer<T>
5672
{
5773
readonly Comparison<T> comparison;
5874
internal ComparerWrapper(Comparison<T> comparison)

src/Split/net462/Polyfill_Memory_SpanSort.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ namespace Polyfills;
77
using System.Buffers;
88
static partial class Polyfill
99
{
10+
/// <summary>
11+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the <see cref="IComparable{T}"/> implementation of each element of the <see cref="Span{T}"/>.
12+
/// </summary>
1013
public static void Sort<T>(this Span<T> source)
1114
where T : IComparable<T>
1215
=> Sort(source, (x, y) => x.CompareTo(y));
16+
/// <summary>
17+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the specified <see cref="Comparison{T}"/>.
18+
/// </summary>
19+
/// Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-1(system-span((-0))-system-comparison((-0)))
1320
public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1421
{
1522
if((Comparison<T>?)comparison is null)
@@ -18,16 +25,22 @@ public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1825
try
1926
{
2027
source.CopyTo(array);
21-
Array.Sort(array, comparison);
28+
Array.Sort(array, 0, source.Length, Comparer<T>.Create(comparison));
2229
array.AsSpan(0, source.Length).CopyTo(source);
2330
}
2431
finally
2532
{
2633
ArrayPool<T>.Shared.Return(array);
2734
}
2835
}
36+
/// <summary>
37+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the <see cref=" IComparable{T}"/> implementation of each key.
38+
/// </summary>
2939
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values)
3040
=> Sort(keys, values, Comparer<TKey>.Default);
41+
/// <summary>
42+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparer.
43+
/// </summary>
3144
public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TValue> values, TComparer comparer)
3245
where TComparer : IComparer<TKey>
3346
{
@@ -40,7 +53,7 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
4053
{
4154
keys.CopyTo(keysArray);
4255
values.CopyTo(valsArray);
43-
Array.Sort(keysArray, valsArray, comparer);
56+
Array.Sort(keysArray, valsArray, 0, keys.Length, comparer);
4457
keysArray.AsSpan(0, keys.Length).CopyTo(keys);
4558
valsArray.AsSpan(0, values.Length).CopyTo(values);
4659
}
@@ -50,9 +63,12 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
5063
ArrayPool<TValue>.Shared.Return(valsArray);
5164
}
5265
}
53-
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values, Comparison<TKey> comparison)
54-
=> Sort(keys, values, new ComparerWrapper<TKey>(comparison));
55-
private class ComparerWrapper<T> : IComparer<T>
66+
/// <summary>
67+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparison.
68+
/// </summary>
69+
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> items, Comparison<TKey> comparison)
70+
=> Sort(keys, items, new ComparerWrapper<TKey>(comparison));
71+
class ComparerWrapper<T> : IComparer<T>
5672
{
5773
readonly Comparison<T> comparison;
5874
internal ComparerWrapper(Comparison<T> comparison)

src/Split/net47/Polyfill_Memory_SpanSort.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ namespace Polyfills;
77
using System.Buffers;
88
static partial class Polyfill
99
{
10+
/// <summary>
11+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the <see cref="IComparable{T}"/> implementation of each element of the <see cref="Span{T}"/>.
12+
/// </summary>
1013
public static void Sort<T>(this Span<T> source)
1114
where T : IComparable<T>
1215
=> Sort(source, (x, y) => x.CompareTo(y));
16+
/// <summary>
17+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the specified <see cref="Comparison{T}"/>.
18+
/// </summary>
19+
/// Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-1(system-span((-0))-system-comparison((-0)))
1320
public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1421
{
1522
if((Comparison<T>?)comparison is null)
@@ -18,16 +25,22 @@ public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1825
try
1926
{
2027
source.CopyTo(array);
21-
Array.Sort(array, comparison);
28+
Array.Sort(array, 0, source.Length, Comparer<T>.Create(comparison));
2229
array.AsSpan(0, source.Length).CopyTo(source);
2330
}
2431
finally
2532
{
2633
ArrayPool<T>.Shared.Return(array);
2734
}
2835
}
36+
/// <summary>
37+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the <see cref=" IComparable{T}"/> implementation of each key.
38+
/// </summary>
2939
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values)
3040
=> Sort(keys, values, Comparer<TKey>.Default);
41+
/// <summary>
42+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparer.
43+
/// </summary>
3144
public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TValue> values, TComparer comparer)
3245
where TComparer : IComparer<TKey>
3346
{
@@ -40,7 +53,7 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
4053
{
4154
keys.CopyTo(keysArray);
4255
values.CopyTo(valsArray);
43-
Array.Sort(keysArray, valsArray, comparer);
56+
Array.Sort(keysArray, valsArray, 0, keys.Length, comparer);
4457
keysArray.AsSpan(0, keys.Length).CopyTo(keys);
4558
valsArray.AsSpan(0, values.Length).CopyTo(values);
4659
}
@@ -50,9 +63,12 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
5063
ArrayPool<TValue>.Shared.Return(valsArray);
5164
}
5265
}
53-
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values, Comparison<TKey> comparison)
54-
=> Sort(keys, values, new ComparerWrapper<TKey>(comparison));
55-
private class ComparerWrapper<T> : IComparer<T>
66+
/// <summary>
67+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparison.
68+
/// </summary>
69+
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> items, Comparison<TKey> comparison)
70+
=> Sort(keys, items, new ComparerWrapper<TKey>(comparison));
71+
class ComparerWrapper<T> : IComparer<T>
5672
{
5773
readonly Comparison<T> comparison;
5874
internal ComparerWrapper(Comparison<T> comparison)

src/Split/net471/Polyfill_Memory_SpanSort.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ namespace Polyfills;
77
using System.Buffers;
88
static partial class Polyfill
99
{
10+
/// <summary>
11+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the <see cref="IComparable{T}"/> implementation of each element of the <see cref="Span{T}"/>.
12+
/// </summary>
1013
public static void Sort<T>(this Span<T> source)
1114
where T : IComparable<T>
1215
=> Sort(source, (x, y) => x.CompareTo(y));
16+
/// <summary>
17+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the specified <see cref="Comparison{T}"/>.
18+
/// </summary>
19+
/// Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-1(system-span((-0))-system-comparison((-0)))
1320
public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1421
{
1522
if((Comparison<T>?)comparison is null)
@@ -18,16 +25,22 @@ public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1825
try
1926
{
2027
source.CopyTo(array);
21-
Array.Sort(array, comparison);
28+
Array.Sort(array, 0, source.Length, Comparer<T>.Create(comparison));
2229
array.AsSpan(0, source.Length).CopyTo(source);
2330
}
2431
finally
2532
{
2633
ArrayPool<T>.Shared.Return(array);
2734
}
2835
}
36+
/// <summary>
37+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the <see cref=" IComparable{T}"/> implementation of each key.
38+
/// </summary>
2939
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values)
3040
=> Sort(keys, values, Comparer<TKey>.Default);
41+
/// <summary>
42+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparer.
43+
/// </summary>
3144
public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TValue> values, TComparer comparer)
3245
where TComparer : IComparer<TKey>
3346
{
@@ -40,7 +53,7 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
4053
{
4154
keys.CopyTo(keysArray);
4255
values.CopyTo(valsArray);
43-
Array.Sort(keysArray, valsArray, comparer);
56+
Array.Sort(keysArray, valsArray, 0, keys.Length, comparer);
4457
keysArray.AsSpan(0, keys.Length).CopyTo(keys);
4558
valsArray.AsSpan(0, values.Length).CopyTo(values);
4659
}
@@ -50,9 +63,12 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
5063
ArrayPool<TValue>.Shared.Return(valsArray);
5164
}
5265
}
53-
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values, Comparison<TKey> comparison)
54-
=> Sort(keys, values, new ComparerWrapper<TKey>(comparison));
55-
private class ComparerWrapper<T> : IComparer<T>
66+
/// <summary>
67+
/// Sorts a pair of spans (one containing the keys and the other containing the corresponding items) based on the keys in the first <see cref="Span{T}"/> using the specified comparison.
68+
/// </summary>
69+
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> items, Comparison<TKey> comparison)
70+
=> Sort(keys, items, new ComparerWrapper<TKey>(comparison));
71+
class ComparerWrapper<T> : IComparer<T>
5672
{
5773
readonly Comparison<T> comparison;
5874
internal ComparerWrapper(Comparison<T> comparison)

0 commit comments

Comments
 (0)