From 622c4f7cb1715c707d3ff00545a26a24c20e9ae1 Mon Sep 17 00:00:00 2001 From: Rajdeep Roy Chowdhury Date: Mon, 7 Feb 2022 14:45:18 +0530 Subject: [PATCH 1/2] fix: util::find() issue fixed When linear scanning doesn't find the target element, the control must not go back to the binary search logic. Signed-off-by: Rajdeep Roy Chowdhury --- include/util.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/util.hpp b/include/util.hpp index bb20bdb..27942d3 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -45,6 +45,7 @@ uint64_t find(S const& sequence, uint64_t id, uint64_t lo, uint64_t hi) { return pos; } } + break; } uint64_t pos = lo + ((hi - lo) >> 1); uint64_t val = sequence.access(pos); From 84e7823965e95e1b9c03772352d483f1bb7aecf9 Mon Sep 17 00:00:00 2001 From: Rajdeep Roy Chowdhury Date: Tue, 8 Feb 2022 12:38:46 +0530 Subject: [PATCH 2/2] fix: unsigned underflow handled Signed-off-by: Rajdeep Roy Chowdhury --- include/util.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/util.hpp b/include/util.hpp index 27942d3..b08b3b7 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -45,13 +45,17 @@ uint64_t find(S const& sequence, uint64_t id, uint64_t lo, uint64_t hi) { return pos; } } - break; +// break; } uint64_t pos = lo + ((hi - lo) >> 1); uint64_t val = sequence.access(pos); if (val == id) { return pos; } else if (val > id) { + // Rescuing hi from unsigned underflow + if (pos == 0) { + return global::not_found; + } hi = pos - 1; } else { lo = pos + 1;