Commit fecbbf64 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 4a903beb
...@@ -94,11 +94,9 @@ static BOOL __toku_rt_exact(toku_range_tree* tree, ...@@ -94,11 +94,9 @@ static BOOL __toku_rt_exact(toku_range_tree* tree,
assert(tree); assert(tree);
assert(a); assert(a);
assert(b); 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 && 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); tree->data_cmp(a->data, b->data) == 0);
} }
...@@ -188,8 +186,10 @@ int toku_rt_insert(toku_range_tree* tree, toku_range* range) { ...@@ -188,8 +186,10 @@ int toku_rt_insert(toku_range_tree* tree, toku_range* range) {
} }
else { else {
for (i = 0; i < tree->numelements; i++) { for (i = 0; i < tree->numelements; i++) {
if (__toku_rt_overlap(tree, range, &tree->ranges[i]) || /* I am going to check that end_cmp is commutative as such: */
__toku_rt_overlap(tree, &tree->ranges[i], range)) return EDOM; 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); r = __toku_rt_increase_capacity(tree, tree->numelements + 1);
......
...@@ -38,6 +38,16 @@ int main(int argc, const char *argv[]) { ...@@ -38,6 +38,16 @@ int main(int argc, const char *argv[]) {
/* Try and fail to insert exact same thing. */ /* Try and fail to insert exact same thing. */
r = toku_rt_insert(tree, &range); CKERR2(r,EDOM); 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.left = &nums[2];
range.right = &nums[6]; range.right = &nums[6];
range.data = &letters[0]; 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