Made compute_idx function static and public since it's useful in other algoritms as well.
Also, added n as a third parameter, instead of a reference to the member class.