Efficiently finding the ranks of elements in an array?
问题 How does one find the rank of each element of an array, averaging in the case of ties, efficiently? For example: float[] rank(T)(T[] input) { // Implementation } auto foo = rank([3,6,4,2,2]); // foo == [3, 5, 4, 1.5, 1.5] The only way I can think of doing it requires allocating 3 arrays: A duplicate of the input array because it has to be sorted and we don't own it. An array to keep track of the order in which the input array was sorted. An array of ranks to return. Does anyone know how to do