{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/20744","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/20744/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/20744/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/20744/events","html_url":"https://github.com/JuliaLang/julia/issues/20744","id":209580005,"number":20744,"title":"Hash function is invariant to reversal of arrays of symbols","user":{"login":"NickMcNutt","id":3084546,"avatar_url":"https://avatars.githubusercontent.com/u/3084546?v=3","gravatar_id":"","url":"https://api.github.com/users/NickMcNutt","html_url":"https://github.com/NickMcNutt","followers_url":"https://api.github.com/users/NickMcNutt/followers","following_url":"https://api.github.com/users/NickMcNutt/following{/other_user}","gists_url":"https://api.github.com/users/NickMcNutt/gists{/gist_id}","starred_url":"https://api.github.com/users/NickMcNutt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickMcNutt/subscriptions","organizations_url":"https://api.github.com/users/NickMcNutt/orgs","repos_url":"https://api.github.com/users/NickMcNutt/repos","events_url":"https://api.github.com/users/NickMcNutt/events{/privacy}","received_events_url":"https://api.github.com/users/NickMcNutt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-02-22T21:02:39Z","updated_at":"2017-02-23T19:35:50Z","closed_at":null,"body":"```\r\nJulia Version 0.6.0-dev.2893\r\nCommit 33f464ed25* (2017-02-21 17:48 UTC)\r\nPlatform Info:\r\n  OS: macOS (x86_64-apple-darwin16.5.0)\r\n  CPU: Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz\r\n  WORD_SIZE: 64\r\n  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)\r\n  LAPACK: libopenblas64_\r\n  LIBM: libopenlibm\r\n  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)\r\n```\r\n\r\nFrom the manual for `hash`\r\n\r\n> Compute an integer hash code such that isequal(x,y) implies hash(x)==hash(y).\r\n\r\nWhile the converse of this statement isn't strictly implied, I think it would be a reasonable thing to expect from a hash function (barring adversarial hash collisions), and this isn't the case for vectors of symbols:\r\n\r\n```julia\r\nisequal([1, 2, 3], [3, 2, 1]) # false\r\nhash([1, 2, 3]) == hash([3, 2, 1]) # false\r\n\r\nisequal([:a, :b, :c], [:c, :b, :a]) # false\r\nhash([:a, :b, :c]) == hash([:c, :b, :a]) # true\r\n```\r\n\r\nWould it be possible to modify the `hash` function so that it is no longer invariant to commonly used object transformations?"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/282096806","html_url":"https://github.com/JuliaLang/julia/issues/20744#issuecomment-282096806","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/20744","id":282096806,"user":{"login":"stevengj","id":2913679,"avatar_url":"https://avatars.githubusercontent.com/u/2913679?v=3","gravatar_id":"","url":"https://api.github.com/users/stevengj","html_url":"https://github.com/stevengj","followers_url":"https://api.github.com/users/stevengj/followers","following_url":"https://api.github.com/users/stevengj/following{/other_user}","gists_url":"https://api.github.com/users/stevengj/gists{/gist_id}","starred_url":"https://api.github.com/users/stevengj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevengj/subscriptions","organizations_url":"https://api.github.com/users/stevengj/orgs","repos_url":"https://api.github.com/users/stevengj/repos","events_url":"https://api.github.com/users/stevengj/events{/privacy}","received_events_url":"https://api.github.com/users/stevengj/received_events","type":"User","site_admin":false},"created_at":"2017-02-23T19:35:49Z","updated_at":"2017-02-23T19:35:49Z","body":"I can confirm that using the old `bitmix` function fixes the problem:\r\n```jl\r\njulia> int64hash(x) = ccall(:int64hash, UInt, (UInt,), x)\r\nint64hash (generic function with 1 method)\r\n\r\njulia> bitmix(a, b) = int64hash(xor(a, bswap(b)))\r\nbitmix (generic function with 1 method)\r\n\r\njulia> myhash(x::Symbol, h::UInt) = bitmix(object_id(x), h)\r\nmyhash (generic function with 1 method)\r\n\r\njulia> myhash(:c, myhash(:b, myhash(:a, zero(UInt)))) == myhash(:a, myhash(:b, myhash(:c, zero(UInt))))\r\nfalse\r\n```"}}
{"actor":{"display_login":"stevengj"}}