r_select algorithm initial commit.