<div style="color: rgb(102, 102, 102);" class="gmail_quote">2009/9/1 Ceki Gulcu <span dir="ltr"><<a href="mailto:ceki@qos.ch">ceki@qos.ch</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br></div>
No, they do not have different behavior. Both methods act according to their respective contracts. Keep in mind that in a typical hashtable the actual size of the table is much smaller than the hash space. Thus, it is *perfectly* OK for hash values to collide from time to time.</blockquote>
<div><span style="color: rgb(0, 0, 0);"><br><span style="color: rgb(0, 0, 0);">I'm happy with that, but</span> I was thinking about the particular case of several instances sharing a common enum value but differing in their parameters. They would all be in the same hashtable bucket so linear searching would be needed. If this is sufficiently unlikely, then there is no need to include the parameters in the hash value. However, a better hash value is produced by the more complex code I wrote 3 days ago.<br>
<br></span>Â </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Not only is the simpler hashCode implementation simpler, it will also be faster in computing its result. Since occasional hash collisions are OK, the overall results are likely to be better as well. As I said, having args contribute to the hashCode is a waste of the code reader/reviewer's time as well as CPU cycles. (If unconcinved, write a small test case comparing the performance of the two variants.)</blockquote>
</div><br>The performance is not an issue - in the code I emailed, I had a lazy cache of the hashcode to avoid the cost of recomputing it (and likewise for toString()). <br><br>As far as complexity is concerned, your simpler approach is much much better.<br>
<br>I don't really have a strong view on this and I'll leave the choice to you.<br><br clear="all">Rick :-)<br>-- <br>Big Bee Consultants Limited : Registered in England & Wales No. 6397941<br>Registered Office: 71 The Hundred, Romsey, Hampshire, SO51 8BZ<br>