Providing a custom hash function to HashMap?
807591Mar 6 2008 — edited Mar 6 2008Hi,
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.