{"id":32983,"date":"2005-12-14T10:00:15","date_gmt":"2005-12-14T10:00:15","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/12\/14\/on-the-ambiguity-of-uniqueness\/"},"modified":"2005-12-14T10:00:15","modified_gmt":"2005-12-14T10:00:15","slug":"on-the-ambiguity-of-uniqueness","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20051214-15\/?p=32983","title":{"rendered":"On the ambiguity of uniqueness"},"content":{"rendered":"<p>The <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/cpref\/html\/frlrfsystemobjectclassgethashcodetopic.asp\"> MSDN documentation for <code>System.Object.GetHashCode<\/code><\/a> says<\/p>\n<blockquote class=\"q\"><p> [T]he implementation of GetHashCode provided by the String class returns unique hash codes for unique string values. <\/p><\/blockquote>\n<p> This is another case of ambiguous use of the word &#8220;unique&#8221;. The intended meaning is &#8220;for each string value, the same hash code is returned&#8221;. <\/p>\n<p> Even though &#8220;unique&#8221; means &#8220;one and only one&#8221;, the domain in which the term applies is often left unsaid, as here, where the domain of comparison is &#8220;all the hash codes returned for a specific string value&#8221;. If you instead misinterpreted the domain as &#8220;all the hash codes returned for all string values&#8221;, then you end up erroneously concluding that no two strings hash to the same value. <\/p>\n<p> Another conflicting sense of &#8220;unique&#8221; is &#8220;you get the same one each time&#8221; as opposed to &#8220;you get a different one each time&#8221;. <\/p>\n<ul>\n<li><code>GetCurrentProcessId<\/code> returns a unique value that identifies the process. You get the same one each time. <\/li>\n<li> <code>CoCreateGuid<\/code> returns a unique GUID. You get a different one each time. <\/li>\n<\/ul>\n<p> In the original C standard, <code>malloc(0)<\/code> is permitted to return <code>NULL<\/code> or &#8220;a unique pointer&#8221;. What does &#8220;unique&#8221; mean here? Does it mean that the non-<code>NULL<\/code> return value is always the same? Can I <code>assert(malloc(0) == malloc(0))<\/code>? Or does it mean that the non-<code>NULL<\/code> return value is a value distinct from any other return value from <code>malloc()<\/code>? <\/p>\n<p> In Technical Corrigendum&nbsp;1, this ambiguity was resolved by removing the word &#8220;unique&#8221;. Instead, the specification says &#8220;as if the size were some nonzero value&#8221; which makes it clear that it is the second interpretation that is intended. <\/p>\n<p> My suggestion: Don&#8217;t use the word &#8220;unique&#8221;. It&#8217;s too ambiguous. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The MSDN documentation for System.Object.GetHashCode says [T]he implementation of GetHashCode provided by the String class returns unique hash codes for unique string values. This is another case of ambiguous use of the word &#8220;unique&#8221;. The intended meaning is &#8220;for each string value, the same hash code is returned&#8221;. Even though &#8220;unique&#8221; means &#8220;one and only [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-32983","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The MSDN documentation for System.Object.GetHashCode says [T]he implementation of GetHashCode provided by the String class returns unique hash codes for unique string values. This is another case of ambiguous use of the word &#8220;unique&#8221;. The intended meaning is &#8220;for each string value, the same hash code is returned&#8221;. Even though &#8220;unique&#8221; means &#8220;one and only [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=32983"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32983\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=32983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=32983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=32983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}