Created
May 9, 2015 12:01
-
-
Save cesarsouza/aeb3c080c502ea5702b5 to your computer and use it in GitHub Desktop.
Missing Sort<T> method for Jagged matrices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sorts the columns of a matrix by sorting keys. | |
/// </summary> | |
/// | |
/// <param name="keys">The key value for each column.</param> | |
/// <param name="values">The matrix to be sorted.</param> | |
/// <param name="comparer">The comparer to use.</param> | |
/// | |
public static TValue[][] Sort<TKey, TValue>(TKey[] keys, TValue[][] values, IComparer<TKey> comparer) | |
{ | |
int[] indices = new int[keys.Length]; | |
for (int i = 0; i < keys.Length; i++) | |
indices[i] = i; | |
Array.Sort<TKey, int>(keys, indices, comparer); | |
return values.Submatrix(0, values.Length - 1, indices); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment