MCPcopy Create free account
hub / github.com/apache/impala / VerifyFindIntersectingInterval

Function VerifyFindIntersectingInterval

be/src/kudu/util/interval_tree-test.cc:219–265  ·  view source on GitHub ↗

Verify that IntervalTree::FindIntersectingInterval yields the same results as the naive brute-force O(n) algorithm.

Source from the content-addressed store, hash-verified

217// Verify that IntervalTree::FindIntersectingInterval yields the same results as the naive
218// brute-force O(n) algorithm.
219static void VerifyFindIntersectingInterval(const vector<IntInterval>& all_intervals,
220 const IntervalTree<IntTraits>& tree,
221 const IntInterval& query_interval) {
222 const auto& Process = [&] (const optional<int>& lower,
223 const optional<int>& upper) {
224 vector<IntInterval> results;
225 tree.FindIntersectingInterval(lower, upper, &results);
226 std::sort(results.begin(), results.end(), CompareIntervals);
227
228 vector<IntInterval> brute_force;
229 FindIntersectingBruteForce(all_intervals, lower, upper, &brute_force);
230 std::sort(brute_force.begin(), brute_force.end(), CompareIntervals);
231 EXPECT_EQ(Stringify(brute_force), Stringify(results));
232 };
233
234 {
235 // [lower, upper)
236 optional<int> lower = query_interval.left;
237 optional<int> upper = query_interval.right;
238 SCOPED_TRACE(Stringify(all_intervals) + StringPrintf(" {q=[%d, %d)}", *lower, *upper));
239 Process(lower, upper);
240 }
241
242 {
243 // [-OO, upper)
244 optional<int> lower = nullopt;
245 optional<int> upper = query_interval.right;
246 SCOPED_TRACE(Stringify(all_intervals) + StringPrintf(" {q=[-OO, %d)}", *upper));
247 Process(lower, upper);
248 }
249
250 {
251 // [lower, +OO)
252 optional<int> lower = query_interval.left;
253 optional<int> upper = nullopt;
254 SCOPED_TRACE(Stringify(all_intervals) + StringPrintf(" {q=[%d, +OO)}", *lower));
255 Process(lower, upper);
256 }
257
258 {
259 // [-OO, +OO)
260 optional<int> lower = query_interval.left;
261 optional<int> upper = nullopt;
262 SCOPED_TRACE(Stringify(all_intervals) + StringPrintf(" {q=[-OO, +OO)}"));
263 Process(lower, upper);
264 }
265}
266
267static vector<IntInterval> CreateRandomIntervals(int n = 100) {
268 vector<IntInterval> intervals;

Callers 1

TEST_FFunction · 0.85

Calls 8

sortFunction · 0.85
StringifyFunction · 0.85
StringPrintfFunction · 0.85
ProcessClass · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected