-
Notifications
You must be signed in to change notification settings - Fork 1
feat: new method GetNodes() #5
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
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for the contributions. Sorry I didn't look at this sooner. I started a new job earlier this year and it got lost in the mix.
throw new InvalidOperationException( | ||
$"GetNodes() parameter n must be greater or equal to 1, but it was {n}"); |
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 an ArgumentException would be better here.
var toReturn = new List<TNode>(); | ||
var seen = new List<TNode>(); // Faster for small values of n, which is the expected use case. |
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 seen
needed? Seems like it is the same as toReturn
.
} | ||
else | ||
|
||
var toReturn = new List<TNode>(); |
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.
Seems like we can initialize this list with capacity n
to avoid resizing.
A common way to implement replicas in a Hash Ring is to find a node on the ring, then return that node plus subsequent nodes. There was no way to do that with HashRing's interface.
I left GetNodes() as unimplemented on BstHashRing since that class only appears in the UnitTests project and it has no test coverage. It seemed like a prototype.
I'm going to be trying HashRing out in my own code this week and might submit further tweaks or changes in this PR or others.