public static List <Item> fastSort(List <Item> unsorted) { //double [] values = unsorted.ConvertAll<double>(item => item.Value).ToArray(); //// maybe more efficient? safes O(n) run //double[] values = new double[unsorted.Count]; //for (int i = 0; i < values.Length; i++) { // values[i] = unsorted[i].Value; //} using (ILScope.Enter()) { // convert incoming ILArray <double> doubles = zeros(unsorted.Count); double[] doublesArr = doubles.GetArrayForWrite(); for (int i = 0; i < doubles.Length; i++) { doublesArr[i] = unsorted[i].Value; } // do fast sort ILArray <double> indices = empty(); doubles = sort(doubles, Indices: indices); // convert outgoing List <Item> ret = new List <Item>(unsorted.Count); foreach (double i in indices) { ret.Add(unsorted[(int)i]); } return(ret); } }