Re: Arrays as key in a HashMap
- From: tom fredriksen <tom@xxxxxxxxxx>
- Date: Sun, 19 Feb 2006 19:17:15 +0100
Chris Smith wrote:
tom fredriksen <tom@xxxxxxxxxx> wrote:Chris Smith wrote:The point that any necessary complexity can be encapsulated behind the contract for Object.equals and Object.hashCode.Just because you have a contract about an interface, and it can be kept constant, does not mean that the code behind it needs to be as complicated as you can manage, or want to, create it. Thats the key to low complexity/high maintainability code.
Can you solve that problem with less complexity, or do you just move the complexity elsewhere? Somewhere, you've got to have code that compares two graphs for equality. The hash code is, of course, an optimization to avoid a linear search... but it's an even more welcome optimization when the graphs are so expensive to compare.
Of course somewhere you have to have the logic to perform the operations you need done. And using equals() to initiate a comparison of two graphs is as good as any.
But, using a hash code of the graph as a unique identifier of the graph is not the way to go, as you then have to take into consideration many factors that are quite complex, such as
- the complexity of the graph,
- a correct algorithm to produce a representative hash code for the
type and complexity of the graph,
- accuracy of the representation,
- collision rate of the hash code
- distribution properties of the hash code, when considering the accuracy, collision rate etc
I would try to look for another piece of simple information about a graph that can be used as a unique identifier.
/tom
.
- References:
- Arrays as key in a HashMap
- From: Hendrik Maryns
- Re: Arrays as key in a HashMap
- From: tom fredriksen
- Re: Arrays as key in a HashMap
- From: Chris Uppal
- Re: Arrays as key in a HashMap
- From: tom fredriksen
- Re: Arrays as key in a HashMap
- From: Chris Smith
- Re: Arrays as key in a HashMap
- From: tom fredriksen
- Re: Arrays as key in a HashMap
- From: Chris Smith
- Re: Arrays as key in a HashMap
- From: tom fredriksen
- Re: Arrays as key in a HashMap
- From: Chris Smith
- Arrays as key in a HashMap
- Prev by Date: Re: NullPointerException vs '= null' check
- Next by Date: Re: Singular and Plural Classes - conventions
- Previous by thread: Re: Arrays as key in a HashMap
- Next by thread: Re: Arrays as key in a HashMap
- Index(es):
Relevant Pages
|