Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Julia's `hash()` function guaranteed to have a stable output across sessions, platforms and versions?

Tags:

julia

I tried running the following code in multiple different Julia REPL sessions, on MacOSX and Linux, and I always got the exact same outputs:

julia> hash(123), hash("123"), hash([1,2,3]), hash((1,2,3)), hash(Set([1,2,3])), hash(:123)
(0x54657e9dbfd649e5, 0xb4e92987fa06fcab, 0xecc5186e7be222c6, 0xafc764e9c2b7cde5, 0x66406071c4c9b92a,
0x54657e9dbfd649e5)

Question: is this behavior guaranteed by the language? Or can the outputs vary (like they do in Python, across sessions, platforms and versions)?

Note: this question is related to my other question about the stability of the order of hash-based collections such as Set and Dict (it's closely related, but different).

like image 686
MiniQuark Avatar asked Jun 19 '20 01:06

MiniQuark


1 Answers

They are not stable and can change from version to version or platforms. They are already different between systems with different word sizes.

like image 73
StefanKarpinski Avatar answered Oct 17 '22 15:10

StefanKarpinski