Do a linear search after half of the range

This way we are more likely ensured to have
an exponential pivot, preventing the case where
we get arbitrarily close to the high multiple times
in a row.
This commit is contained in:
Arpad Müller
2023-11-07 09:52:00 +01:00
parent 52017eff68
commit 2caa795139
2 changed files with 7 additions and 1 deletions

View File

@@ -32,6 +32,12 @@ pub struct ExpCounter {
}
impl ExpCounter {
/// Creates an iterator that uses `ExpCounter` for the first half of the
/// range and a linear range counter for the second half.
pub fn with_max_and_linear_search(max: u64) -> impl Iterator<Item = u64> {
let linear_start = max / 2;
ExpCounter::with_max(linear_start).chain(linear_start..max)
}
/// Creates a new `ExpCounter` instance that counts to the (exclusive) maximum
pub fn with_max(max: u64) -> Self {
Self {

View File

@@ -370,7 +370,7 @@ impl Timeline {
// We don't do an explosive search as we want to prove that
// every single lsn up to high is giving inconclusive results.
// This can only be done by trying all lsns.
for offs in ExpCounter::with_max(high - mid_start) {
for offs in ExpCounter::with_max_and_linear_search(high - mid_start) {
mid = offs + mid_start;
// Do the query for mid + 1 instead of mid so that we can make definite statements