-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Simpler TreeTrie.isEmpty() method #9075
Simpler TreeTrie.isEmpty() method #9075
Conversation
Avoid creating (Key)Set to just test for empty.
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.
Other than a rename LGTM
return !hasAnyKey(_root); | ||
} | ||
|
||
private boolean hasAnyKey(Node<V> t) | ||
{ | ||
if (t != null) | ||
{ | ||
if (t._key != null) | ||
return true; | ||
|
||
for (int i = 0; i < INDEX; i++) | ||
{ | ||
if (t._nextIndex[i] != null) | ||
{ | ||
if (hasAnyKey(t._nextIndex[i])) | ||
return true; | ||
} | ||
} | ||
for (int i = t._nextOther.size(); i-- > 0; ) | ||
{ | ||
if (hasAnyKey(t._nextOther.get(i))) | ||
return true; | ||
} | ||
} | ||
return false; |
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.
probably invert the boolean and rename isEmpty(Node)
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.
Inverted / Renamed
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.
This looks alright, but I think we should add some testing to cover the two loops in isEmpty(Node)
.
if (t._key != null) | ||
return false; | ||
|
||
for (int i = 0; i < INDEX; i++) |
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.
Is there some test coverage for this logic?
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.
Yup, the first loop is 100% covered by the 2 new test cases.
The second loop executes, but nothing can trigger the internal isEmpty() logic with the test cases as it stands.
…0.x/treetrie-isempty-redux
I just pushed 3d4bb49 which slightly improves the test coverage |
Avoid creating (Key)Set to just test for empty.