-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MysqlGTIDSet.Add() and Minus() methods #667
Conversation
ostinru
commented
Jan 18, 2022
- fix off-by-one error
@@ -180,6 +180,8 @@ func (t *mysqlTestSuite) TestMysqlGTIDMinus(c *check.C) { | |||
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-57:60-90", "3E11FA47-71CA-11E1-9E33-C80AA9429562:23", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20-22:24-57:60-90"}, | |||
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-57:60-90", "3E11FA47-71CA-11E1-9E33-C80AA9429562:22-70", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20-21:71-90"}, | |||
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:28-57", "3E11FA47-71CA-11E1-9E33-C80AA9429562:28-57", ""}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found a failed case
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-21", "3E11FA47-71CA-11E1-9E33-C80AA9429562:21", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20"},
please check it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You right.
New version with changes:
- merge 2 loops into one, so it will be easier to reason about
- explicit IF conditions to make it clear which cases are handled in each branch
Hope, this time it is correct for all inputs
* fix off-by-one error
if j < len(in) { | ||
subtrahend = in[j] | ||
} else { | ||
subtrahend = Interval{math.MaxInt64, math.MaxInt64} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can
append minuend to n
check if i+1 out of range and append s.Intervals[i+1:]... to n
it's OK not to change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were 2 bugs in 50 lines :(
So, I would prefer not to increase cyclomatic complexity of this code and keep it as it in PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait @atercattus 's review as this function is complex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @atercattus have you had a chance to look into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm going to merge this PR if he does not respond it tomorrow)