Clarify identical hash() return values due to collisions

(cherry picked from commit 08541fe11d)
This commit is contained in:
Hugo Locurcio 2022-02-12 22:17:35 +01:00 committed by Rémi Verschelde
parent 48f3237477
commit 5ca3a360d1
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 6 additions and 4 deletions

View file

@ -221,8 +221,8 @@
<method name="hash"> <method name="hash">
<return type="int" /> <return type="int" />
<description> <description>
Returns a hashed integer value representing the array and its contents. Returns a hashed 32-bit integer value representing the array and its contents.
[b]Note:[/b] Arrays with equal contents can still produce different hashes. Only the exact same arrays will produce the same hashed integer value. [b]Note:[/b] [Array]s with equal content will always produce identical hash values. However, the reverse is not true. Returning identical hash values does [i]not[/i] imply the arrays are equal, because different arrays can have identical hash values due to hash collisions.
</description> </description>
</method> </method>
<method name="insert"> <method name="insert">

View file

@ -147,7 +147,7 @@
<method name="hash"> <method name="hash">
<return type="int" /> <return type="int" />
<description> <description>
Returns a hashed integer value representing the dictionary contents. This can be used to compare dictionaries by value: Returns a hashed 32-bit integer value representing the dictionary contents. This can be used to compare dictionaries by value:
[codeblock] [codeblock]
var dict1 = {0: 10} var dict1 = {0: 10}
var dict2 = {0: 10} var dict2 = {0: 10}
@ -155,6 +155,7 @@
print(dict1.hash() == dict2.hash()) print(dict1.hash() == dict2.hash())
[/codeblock] [/codeblock]
[b]Note:[/b] Dictionaries with the same keys/values but in a different order will have a different hash. [b]Note:[/b] Dictionaries with the same keys/values but in a different order will have a different hash.
[b]Note:[/b] Dictionaries with equal content will always produce identical hash values. However, the reverse is not true. Returning identical hash values does [i]not[/i] imply the dictionaries are equal, because different dictionaries can have identical hash values due to hash collisions.
</description> </description>
</method> </method>
<method name="keys"> <method name="keys">

View file

@ -351,7 +351,8 @@
<method name="hash"> <method name="hash">
<return type="int" /> <return type="int" />
<description> <description>
Hashes the string and returns a 32-bit integer. Returns the 32-bit hash value representing the string's contents.
[b]Note:[/b] [String]s with equal content will always produce identical hash values. However, the reverse is not true. Returning identical hash values does [i]not[/i] imply the strings are equal, because different strings can have identical hash values due to hash collisions.
</description> </description>
</method> </method>
<method name="hex_to_int"> <method name="hex_to_int">