Skip to content

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

prat0088
Copy link

@prat0088 prat0088 commented Mar 3, 2021

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.

@prat0088 prat0088 marked this pull request as ready for review March 3, 2021 20:36
Copy link
Owner

@jlao jlao left a 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.

Comment on lines +91 to +92
throw new InvalidOperationException(
$"GetNodes() parameter n must be greater or equal to 1, but it was {n}");
Copy link
Owner

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.

Comment on lines +95 to +96
var toReturn = new List<TNode>();
var seen = new List<TNode>(); // Faster for small values of n, which is the expected use case.
Copy link
Owner

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>();
Copy link
Owner

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.

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.

2 participants