Implementation of the hd-PS algorithm.