Skip to content
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

implement containsRoute check in AbstractRib, tests #590

Merged
merged 2 commits into from
Oct 17, 2017

Conversation

arifogel
Copy link
Member

No description provided.

@arifogel arifogel merged commit 1887c49 into master Oct 17, 2017
currentAddressBit = bits.get(nextUnmatchedBit);
currentRightAddressBit = rightAddressBits.get(nextUnmatchedBit);
if (currentRightAddressBit != currentAddressBit) {
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to see how to simplify this code a bit, if possible.

  1. It looks to me like the _right and _left bits are identical except for whether you use _right or _left. Maybe extract a helper, and then this function could be simplified to (basically)
if (currentBit) {
    doIt(_right);
} else {
    doIt(_left);
}
  1. Can the break on this line just be return false, and then drop the if after the for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(p.s. I'm doubtful on 2. ; but see the comment above for why.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I'd prefer to defer. Helpers were avoided due to criticality of this code. IMO any proposed changes that execute more code should be justified with profiling. However early exits are uncontroversial.

boolean currentAddressBit = false;
boolean currentRightAddressBit;
for (nextUnmatchedBit = firstUnmatchedBitIndex + 1;
nextUnmatchedBit < rightPrefixLength && nextUnmatchedBit < prefixLength;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite understanding how the case is handled when prefixLength > rightPrefixLength. It looks like it will always return false, because even if everything matches we'll exit the for loop, fail the check at L114, and then return false.

If this is desired, just have that return earlier?

I am likely missing something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was trivially modified from the mergeRoute code which modifies the underlying DDNF-like structure containing the routes. This code itself was itself somewhat brutishly modified from the original trie-maintaining code before the structure was changed. There is likely quite a bit of room for improvement via careful analysis and tests in both mergeRoute and containsRoute.
I will say that at the time I wanted to avoid further function calls (helpers) because all this code is in a critical section (though that might have been overly paranoid).

Anyway the return false on L117 would in mergeRoute instead be code that performs modification. That modification depends on how far we get along rightAddressBits, regardless of whether prefixLength is larger than rightPrefixLength. However in this case since we don't care how far we get when prefixLength is larger than rightPrefixLength, the code can be simplified.

Due to the large amount of optimization we can do on this class, I'd personally prefer to just file a ticket and defer to a later PR.

@dhalperi dhalperi deleted the ari-contains-route branch October 17, 2017 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants