Class Compare
Provides methods to sort or search in lists of items
public static class Compare
- Inheritance
-
Compare
- Inherited Members
Methods
BSearch<T>(in T, ReadOnlySpan<T>, Comparer<T>)
Performs a binary search on a previously sorted list of items
public static int BSearch<T>(in T key, ReadOnlySpan<T> span, Comparer<T> comparer) where T : unmanaged
Parameters
keyTA comparable key item equal to the item that is being searched for
spanReadOnlySpan<T>The list of items to search in
comparerComparer<T>A Comparer<T> delegate used to compare the items
Returns
- int
The index into the
spanwhere a matching item to the givenkeywas found, if it was found; otherwise,-1
Type Parameters
TThe type of items to search for
Remarks
The list of items (span) must be previously sorted (e.g. by using QSort<T>(Span<T>, Comparer<T>)) or else the result will be unrelyable.
Note: The result of this method is somewhat different to SDL's native equivalent.
While SDL_bsearch() returns a pointer to the matching item into the given list or returns NULL when no match was found,
this method returns the index to the matching item into the given list (span) or returns -1 when no match was found.
Exceptions
- ArgumentNullException
comparerwasnull
BSearch<T>(in T, T[], Comparer<T>)
Performs a binary search on a previously sorted list of items
public static int BSearch<T>(in T key, T[] array, Comparer<T> comparer) where T : unmanaged
Parameters
keyTA comparable key item equal to the item that is being searched for
arrayT[]The list of items to search in
comparerComparer<T>A Comparer<T> delegate used to compare the items
Returns
- int
The index into the
arraywhere a matching item to the givenkeywas found, if it was found; otherwise,-1
Type Parameters
TThe type of items to search for
Remarks
The list of items (array) must be previously sorted (e.g. by using QSort<T>(T[], Comparer<T>)) or else the result will be unrelyable.
Note: The result of this method is somewhat different to SDL's native equivalent.
While SDL_bsearch() returns a pointer to the matching item into the given list or returns NULL when no match was found,
this method returns the index to the matching item into the given list (array) or returns -1 when no match was found.
Exceptions
- ArgumentNullException
arraywasnull- or -
comparerwasnull
- or -
QSort<T>(Span<T>, Comparer<T>)
Sorts a list of items
public static void QSort<T>(Span<T> span, Comparer<T> comparer) where T : unmanaged
Parameters
spanSpan<T>The list of items to sort
comparerComparer<T>A Comparer<T> delegate used to compare the items
Type Parameters
TThe type of items to sort
Remarks
After this returns, the contents of the span are sorted in regards to the given comparer.
Exceptions
- ArgumentNullException
comparerwasnull
QSort<T>(T[], Comparer<T>)
Sorts a list of items
public static void QSort<T>(T[] array, Comparer<T> comparer) where T : unmanaged
Parameters
arrayT[]The list of items to sort
comparerComparer<T>A Comparer<T> delegate used to compare the items
Type Parameters
TThe type of items to sort
Remarks
After this returns, the contents of the array are sorted in regards to the given comparer.
Exceptions
- ArgumentNullException
arraywasnull- or -
comparerwasnull
- or -