Commit 714bdcff authored by Vincenzo Liberatore's avatar Vincenzo Liberatore

Addresses #288

Verifies end_cmp commutativity via overlap, and adds test cases to
stress exact comparison

git-svn-id: file:///svn/tokudb@1911 c7de825b-a66e-492c-adef-691d508d4ae1
parent 136b3161
......@@ -94,11 +94,9 @@ static BOOL __toku_rt_exact(toku_range_tree* tree,
assert(tree);
assert(a);
assert(b);
/* The comparison function must be commutative */
assert(tree->end_cmp (a->left, b->left) != 0 ||
tree->end_cmp (a->right, b->right) == 0 );
return (tree->end_cmp (a->left, b->left) == 0 &&
tree->end_cmp (a->right, b->right) == 0 &&
tree->data_cmp(a->data, b->data) == 0);
}
......@@ -188,8 +186,10 @@ int toku_rt_insert(toku_range_tree* tree, toku_range* range) {
}
else {
for (i = 0; i < tree->numelements; i++) {
if (__toku_rt_overlap(tree, range, &tree->ranges[i]) ||
__toku_rt_overlap(tree, &tree->ranges[i], range)) return EDOM;
/* I am going to check that end_cmp is commutative as such: */
assert (__toku_rt_overlap(tree, range, &tree->ranges[i]) ==
__toku_rt_overlap(tree, &tree->ranges[i], range));
if (__toku_rt_overlap(tree, range, &tree->ranges[i])) return EDOM;
}
}
r = __toku_rt_increase_capacity(tree, tree->numelements + 1);
......
......@@ -38,6 +38,16 @@ int main(int argc, const char *argv[]) {
/* Try and fail to insert exact same thing. */
r = toku_rt_insert(tree, &range); CKERR2(r,EDOM);
/* Try and succeed to insert (and delete) similar yet different things */
range.right = &nums[6];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_delete(tree, &range); CKERR(r);
range.right = &nums[5];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_delete(tree, &range); CKERR(r);
range.data = &letters[0];
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment