Java – define multiple hash functions for the same object
•
Java
I have several collections that store objects of the same class, but I want to specify a different identification function for each of them (that is, if AX = = BX, in one set a = = B and in another set a = = b) if ay = = by)
At present, I use TreeSet and define different comparators for each TreeSet I want to know if I want to switch to hashsets, I can do the same thing Java does not allow separate hash functions to be passed in the same way that comparators are allowed to sort / tree based collections The only way I can think of doing this is to create a different wrapper class and implement the hashcode () method in each HashSet element Is there a better way?
Solution
You can try using thashset in GNU trove, which supports multiple hash policies
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码