rank(S,k):
/*
Given key k, in set S, returns the rank
*/