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

Define Hashable Interface #49

Open
syaiful6 opened this issue Apr 27, 2016 · 3 comments
Open

Define Hashable Interface #49

syaiful6 opened this issue Apr 27, 2016 · 3 comments

Comments

@syaiful6
Copy link

For map implementation, expecially HashMap it advantage for us to define Hashable interface, this interface only require 2 method: hashCode and isEquals modeled after Java. The advantage having this interface are the HashMap no longer take hashfunction argument and move the responsibily of compare two key is equal to the interface. It maybe overkill what do you think?

@syaiful6
Copy link
Author

Note: if two entry have same hash is doesn't mean they are equals. it just mean they are may be equals so we ask isEquals.

@morrisonlevi
Copy link
Owner

morrisonlevi commented Apr 27, 2016

If it only uses Hashable then primitives types don't work. Also, inevitably people want to store objects in multiple ways and the Hashable interface has no way to indicate that choice. Also, what if you want to store objects you didn't define such as is common with third-party libraries? In my opinion this choice is very restrictive.

In cases where Hashable is suitable it is more convenient. That is its only strength. So far I have taken the stance that the convenience of omitting a hashing function is not worth the loss in capabilities.

Does that make sense?

@syaiful6
Copy link
Author

You made a good reason. yes, i understand your point.

But here my solution if we want accept primitive value and common object. We can fallback it if the key is primitive type, or wrap it on our default Hashable implementation. For other object we can do the same approach, wrap them on Hashable implementation that only equals if it compared with themself.

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

No branches or pull requests

2 participants