use C++-style binary search