Question about the implementation of GetHashCode

http://msdn.microsoft.com/en-us/library/system.object.gethashcode(VS.80).aspx says:

For best performance, the hash function should generate a random distribution for all input.

Does this have any performance impact or is it okay to use a function (like return this.Id) that doesn't give a "random distribution" but doesn't cause more conflicts?

+3
source share
5 answers

this.Id . , , . , - "mod x", x - -, ( ).

(1, 2, 3, 4...), . , , , .

+1

return this.Id ( Id ) - , . - Id 27 , ?

, GetHashCode Equals .

+3

, ... , , - " " int ( .net, , , ), .

: , - 1 10. - , 100, 10 . , , .

0

, . hashtables, ( ). , , , , -, hash_code%buckets .

0

this.Id.GetHashCode();

, , , Id.

0
source

Source: https://habr.com/ru/post/1702759/


All Articles