--- old/test/native/utilities/test_bitMap_search.cpp 2017-04-01 17:52:18.043670901 -0400 +++ new/test/native/utilities/test_bitMap_search.cpp 2017-04-01 17:52:17.927664943 -0400 @@ -91,6 +91,23 @@ return true; } +static idx_t compute_expected(idx_t search_start, + idx_t search_end, + idx_t left_bit, + idx_t right_bit) { + idx_t expected = search_end; + if (search_start <= left_bit) { + if (left_bit < search_end) { + expected = left_bit; + } + } else if (search_start <= right_bit) { + if (right_bit < search_end) { + expected = right_bit; + } + } + return expected; +} + static void test_search_ranges(BitMap& test_ones, BitMap& test_zeros, idx_t left, @@ -118,8 +135,12 @@ for (size_t c_start = 0; c_start < search_nchunks; ++c_start) { for (size_t o_start = 0; o_start < search_noffsets; ++o_start) { idx_t start = c_start * search_chunk_size + search_offsets[o_start]; + // Terminate start iteration if start is more than two full + // chunks beyond left. There isn't anything new to learn by + // continuing the iteration, and this noticably reduces the + // time to run the test. if (left + 2 * search_chunk_size < start) { - c_start = search_nchunks; + c_start = search_nchunks; // Set to limit to terminate iteration. break; } @@ -128,19 +149,26 @@ o_end < search_noffsets; ++o_end) { idx_t end = c_end * search_chunk_size + search_offsets[o_end]; - if (end + 2 * search_chunk_size < right) { - c_end = search_nchunks; + // Similarly to start and left, terminate end iteration if + // end is more than two full chunks beyond right. + if (right + 2 * search_chunk_size < end) { + c_end = search_nchunks; // Set to limit to terminate iteration. break; } + // Skip this chunk if right is much larger than max(left, start) + // and this chunk is one of many similar chunks in between, + // again to reduce testing time. + if (MAX2(start, left) + 2 * search_chunk_size < end) { + if (end + 2 * search_chunk_size < right) { + break; + } + } bool aligned_right = search_offsets[o_end] == 0; ASSERT_LE(start, end); // test bug if fail ASSERT_LT(end, BITMAP_SIZE); // test bug if fail - idx_t expected = left; - if (start > left) expected = right; - if (start > right) expected = end; - if (expected > end) expected = end; + idx_t expected = compute_expected(start, end, left, right); EXPECT_EQ(expected, test_ones.get_next_one_offset(start, end)); EXPECT_EQ(expected, test_zeros.get_next_zero_offset(start, end)); @@ -150,17 +178,14 @@ test_ones.get_next_one_offset_inline_aligned_right(start, end)); } - idx_t start2 = expected + 1; - if (start2 > end) start2 = end; - expected = right; - if (start2 > right) expected = end; - if (expected > end) expected = end; + idx_t start2 = MIN2(expected + 1, end); + idx_t expected2 = compute_expected(start2, end, left, right); - EXPECT_EQ(expected, test_ones.get_next_one_offset(start2, end)); - EXPECT_EQ(expected, test_zeros.get_next_zero_offset(start2, end)); + EXPECT_EQ(expected2, test_ones.get_next_one_offset(start2, end)); + EXPECT_EQ(expected2, test_zeros.get_next_zero_offset(start2, end)); if (aligned_right) { EXPECT_EQ( - expected, + expected2, test_ones.get_next_one_offset_inline_aligned_right(start2, end)); } }