[PATCH] D60779: [ADT] llvm::bsearch, binary search for mere mortals
Jan Korous via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 14:05:28 PDT 2019
jkorous added inline comments.
================
Comment at: include/llvm/ADT/STLExtras.h:1315
+template <typename Predicate>
+unsigned bsearch(unsigned Lo, unsigned Hi, Predicate P) {
+ while (Lo != Hi) {
----------------
Wouldn't `size_t` be better than `unsigned` for the use-case below?
================
Comment at: include/llvm/ADT/STLExtras.h:1317
+ while (Lo != Hi) {
+ unsigned Mid = Lo + ((Hi - Lo) >> 1);
+ if (P(Mid))
----------------
ilya-biryukov wrote:
> Maybe use `/2` instead of `>>1`?
I'd consider adding `assert(Hi > Lo)`.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60779/new/
https://reviews.llvm.org/D60779
More information about the llvm-commits
mailing list