Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Providing a custom hash function to HashMap?

807591Mar 6 2008 — edited Mar 6 2008
Hi,

I have some objects which in some scenarios should use one hashCode/equals method while in other cases use another. I cant see any way to provide the standard Java HashMap with a custom hash function and equals method (i expected something similar to passing in a comparator) which is somewhat problematic.

For the curious, the objects are nodes in a layered DAG and in some cases they should simply be hashed by their unique index or reference while in others they are hashed so that isomorphic nodes (in the sense of their substructure) collide.

Due to the size of the graph involved i would rather avoid encapsulating the nodes in a shell object which could then provide the new hashCode and equals method.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 3 2008
Added on Mar 6 2008
6 comments
1,604 views