I don't think it is possible to reuse the `binarysearch` method here. This expects slightly different result than what `binarysearch` would give. Here `ridx` points to the index uptill `row`, and has a valid value irrespective of whether `row` was found in `rowval[r1:r2]`. And `r1` is advanced till `ridx` so that subsequent searches in the same column are narrower.