right_key

ABSTRACT

Right keys the given vector

IMPORTANT ELEMENT

This function is important enough to memorize. In particular, we recommend you read the remark about recovering permutations from a sort

REMARK

Like left_key, this function is helpful when we need the index of an element while iterating. However, this function also can be used when we want to sort a vector and then recover the permutation that the sort induced. In particular, if we call sort(right_key(v)), then the sequence of first subelements of each element in the resultant vector will be the same as sort(v), and the sequence of second subelements of each element in the resultant vector gives the permutation that the sort applied. Note that if we had used left_key instead, nothing would happen as in that case, the sequence of first subelements of each element is already sorted.

PARAMETERS
vthe vector to right key
RETURN

a vector of the same length as the input, but each element x in the input vector is replaced by a vector of two elements, where the first element of the sub vector is the index of x, and the second element of the sub vector is x.

DECLARATION
func right_key(v)