<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: HashSet.contains(): does your busket contain something?</title>
	<atom:link href="http://boris.kirzner.info/blog/archives/2006/10/01/hashsetcontains-does-your-busket-contain-something/feed/" rel="self" type="application/rss+xml" />
	<link>http://boris.kirzner.info/blog/archives/2006/10/01/hashsetcontains-does-your-busket-contain-something/</link>
	<description>Only empty files are bugless</description>
	<lastBuildDate>Wed, 21 Dec 2011 15:04:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: Back to hashCode() mutability &#171; Technoblog by Boris Kirzner</title>
		<link>http://boris.kirzner.info/blog/archives/2006/10/01/hashsetcontains-does-your-busket-contain-something/comment-page-1/#comment-15</link>
		<dc:creator>Back to hashCode() mutability &#171; Technoblog by Boris Kirzner</dc:creator>
		<pubDate>Tue, 29 May 2007 12:55:47 +0000</pubDate>
		<guid isPermaLink="false">http://kbh.co.il/wordpress/?p=18#comment-15</guid>
		<description>[...] 29th, 2007   My &#171;HashSet.contains(): does your basket contain something?&#187; post got too expected responses: &#171;There is no way to avoid this behavior, why should you [...]</description>
		<content:encoded><![CDATA[<p>[...] 29th, 2007   My &laquo;HashSet.contains(): does your basket contain something?&raquo; post got too expected responses: &laquo;There is no way to avoid this behavior, why should you [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TheMuuj</title>
		<link>http://boris.kirzner.info/blog/archives/2006/10/01/hashsetcontains-does-your-busket-contain-something/comment-page-1/#comment-14</link>
		<dc:creator>TheMuuj</dc:creator>
		<pubDate>Mon, 02 Oct 2006 23:32:12 +0000</pubDate>
		<guid isPermaLink="false">http://kbh.co.il/wordpress/?p=18#comment-14</guid>
		<description>A single guideline will keep this from being a problem: Only override hashCode/equals (or GetHashCode/Equals in .NET) on immutable classes.

If an object is mutable, then their identity needs to stay with the object instance, not with the data.  In .NET, I tend to only override GetHashCode and Equals on structs and sealed classes.

If you need a way to compare the values of two instances, you can always add a &quot;Matches&quot; method.

If you need to look mutable objects up in a hashtable, consider a custom hashcode/equality provider (I assume this is possible in Java).</description>
		<content:encoded><![CDATA[<p>A single guideline will keep this from being a problem: Only override hashCode/equals (or GetHashCode/Equals in .NET) on immutable classes.</p>
<p>If an object is mutable, then their identity needs to stay with the object instance, not with the data.  In .NET, I tend to only override GetHashCode and Equals on structs and sealed classes.</p>
<p>If you need a way to compare the values of two instances, you can always add a &#8220;Matches&#8221; method.</p>
<p>If you need to look mutable objects up in a hashtable, consider a custom hashcode/equality provider (I assume this is possible in Java).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Pryor</title>
		<link>http://boris.kirzner.info/blog/archives/2006/10/01/hashsetcontains-does-your-busket-contain-something/comment-page-1/#comment-13</link>
		<dc:creator>Jonathan Pryor</dc:creator>
		<pubDate>Mon, 02 Oct 2006 13:57:23 +0000</pubDate>
		<guid isPermaLink="false">http://kbh.co.il/wordpress/?p=18#comment-13</guid>
		<description></description>
		<content:encoded><![CDATA[<p>&#8220;How’s that solved in .NET?&#8221;</p>
<p>It isn&#8217;t.  Or it&#8217;s &#8220;solved&#8221; by documenting the limitations:</p>
<p>From: <a href="http://www.go-mono.com/docs/index.aspx?tlink=8@ecma%3a147%23Hashtable%2f" rel="nofollow">http://www.go-mono.com/docs/index.aspx?tlink=8@ecma%3a147%23Hashtable%2f</a></p>
<p>&#8220;Objects used as keys in a Hashtable is required to either implement both System.Object.GetHashCode and System.Object.Equals(System.Object) or neither. Furthermore, for a particular key, these methods are required to produce the same results when called with the same parameters while that key exists in a particular Hashtable . Keys cannot be mutated while they are used in the table.&#8221;</p>
<p>If you think about it, it&#8217;s really the only sane way to go (for precisely the reasons Rentar specifies): if your hash value changes when members change (as it should!), if you change the hash value of an existing key within a hashtable it will no longer be in the right &#8220;bucket&#8221; of the hashtable, or in the correct position for RBL trees, etc.  Meaning that you can never find that entry again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rentar</title>
		<link>http://boris.kirzner.info/blog/archives/2006/10/01/hashsetcontains-does-your-busket-contain-something/comment-page-1/#comment-12</link>
		<dc:creator>Rentar</dc:creator>
		<pubDate>Mon, 02 Oct 2006 09:00:59 +0000</pubDate>
		<guid isPermaLink="false">http://kbh.co.il/wordpress/?p=18#comment-12</guid>
		<description>Disclaimer: I&#039;m doing professional Java development for some time now, so I&#039;m probably biased.

How else would you like it to compute a hash value? The only alternative I can think of would be to use some kind of identity-based hash code (such as produced by System.identityHashCode() or the default implementation of Object.hashCode()). But then you could never check wether the HashSet contains an object that equal()s another object you&#039;ve got (or you could only check that by calling equal() on each object in the set, which kind of defeats the purpose of a HashSet).

You&#039;ve also got the same problem with the keys in a HashMap: they must not change or the behaviour is unspecified. But I&#039;ve never found that to be a problem ...

How&#039;s that solved in .NET?

(I agree that the documentation could be a bit clearer, but as the Bugreport mentions the documentation is in Object.hashCode() and .equals() and clearly specified in their contract).</description>
		<content:encoded><![CDATA[<p>Disclaimer: I&#8217;m doing professional Java development for some time now, so I&#8217;m probably biased.</p>
<p>How else would you like it to compute a hash value? The only alternative I can think of would be to use some kind of identity-based hash code (such as produced by System.identityHashCode() or the default implementation of Object.hashCode()). But then you could never check wether the HashSet contains an object that equal()s another object you&#8217;ve got (or you could only check that by calling equal() on each object in the set, which kind of defeats the purpose of a HashSet).</p>
<p>You&#8217;ve also got the same problem with the keys in a HashMap: they must not change or the behaviour is unspecified. But I&#8217;ve never found that to be a problem &#8230;</p>
<p>How&#8217;s that solved in .NET?</p>
<p>(I agree that the documentation could be a bit clearer, but as the Bugreport mentions the documentation is in Object.hashCode() and .equals() and clearly specified in their contract).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

