Skip to content

Commit 848e267

Browse files
committed
docs
1 parent 5dd06ce commit 848e267

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/Polyfill/Polyfill_Memory_SpanSort.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
#if FeatureMemory
1+
#if FeatureMemory && !NET5_0_OR_GREATER
22

33
namespace Polyfills;
44

5-
#if !NET5_0_OR_GREATER
65
using System;
76
using System.Collections.Generic;
87
using System.Buffers;
9-
#endif
108

119
static partial class Polyfill
1210
{
13-
#if !NET5_0_OR_GREATER
11+
/// <summary>
12+
/// 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}"/>.
13+
/// </summary>
14+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-10.0#system-memoryextensions-sort-1(system-span((-0)))
1415
public static void Sort<T>(this Span<T> source)
1516
where T : IComparable<T>
1617
=> Sort(source, (x, y) => x.CompareTo(y));
1718

19+
/// <summary>
20+
/// Sorts the elements in the entire <see cref="Span{T}"/> using the specified <see cref="Comparison{T}"/>.
21+
/// </summary>
22+
/// 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)))
1823
public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
1924
{
2025
if((Comparison<T>?)comparison is null)
@@ -35,9 +40,18 @@ public static void Sort<T>(this Span<T> source, Comparison<T> comparison)
3540
}
3641
}
3742

43+
/// <summary>
44+
/// 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.
45+
/// </summary>
46+
//Link: 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)))
3847
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values)
3948
=> Sort(keys, values, Comparer<TKey>.Default);
4049

50+
51+
/// <summary>
52+
/// 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.
53+
/// </summary>
54+
//Link: 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)
4155
public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TValue> values, TComparer comparer)
4256
where TComparer : IComparer<TKey>
4357
{
@@ -66,10 +80,14 @@ public static void Sort<TKey, TValue, TComparer>(this Span<TKey> keys, Span<TVal
6680
}
6781
}
6882

69-
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> values, Comparison<TKey> comparison)
70-
=> Sort(keys, values, new ComparerWrapper<TKey>(comparison));
83+
/// <summary>
84+
/// 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.
85+
/// </summary>
86+
//Link: 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)))
87+
public static void Sort<TKey, TValue>(this Span<TKey> keys, Span<TValue> items, Comparison<TKey> comparison)
88+
=> Sort(keys, items, new ComparerWrapper<TKey>(comparison));
7189

72-
private class ComparerWrapper<T> : IComparer<T>
90+
class ComparerWrapper<T> : IComparer<T>
7391
{
7492
readonly Comparison<T> comparison;
7593

@@ -89,7 +107,6 @@ public int Compare(T? x, T? y)
89107
return comparison((T)x, (T)y);
90108
}
91109
}
92-
#endif
93110
}
94111

95-
#endif
112+
#endif

0 commit comments

Comments
 (0)