# Hash(1) change between 1.5 and 1.6

**URL:** <https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101>\
**Category:** General Usage\
**Created:** [February 25, 2022, 10:28pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101 "2022-02-25T22:28:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Barker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jon_barker/32/18997_2.png) [@Jon\_Barker](https://discourse.julialang.org/u/Jon_Barker)\
**Post date:** [February 25, 2022, 10:28pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/1 "2022-02-25T22:28:28Z")

</div>

Hi all, I’m trying to recreate the `Hash(1)` value from Julia 1.1 in our Julia 1.6 codebase.

`Hash(1)` Julia 1.5: `0x02011ce34bce797f`  
`Hash(1)` Julia 1.6: `0x5bca7c69b794f8ce`

I’ve delved deep into the c code, without a lot of success. Maybe someone who understands it better than me can advise: **What code is required to create a J1.5 Hash function so we can produce the same hashes in J1.6?**

The hashing.c file doesn’t appear to have any material changes between the two versions  
`release-1.1/src/support/hashing.c` and `release-1.6/src/support/hashing.c`

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [February 25, 2022, 11:00pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/2 "2022-02-25T23:00:12Z")

</div>

This isn’t in c code — it’s all Julia. So you want to look at hashing.jl and not hashing.c. Here’s the change:

[https://github.com/JuliaLang/julia/pull/38031](https://github.com/JuliaLang/julia/pull/38031)

Fortunately, this also makes it really easy to get the old behavior back:

```julia
julia> hash(1)
0x5bca7c69b794f8ce

julia> hx(a::UInt64, h::UInt) = Base.hash_uint64((3a + reinterpret(UInt64,Float64(a))) - h)
hx (generic function with 1 method)

julia> hx(x::Int64) = hx(UInt64(x), UInt(0))
hx (generic function with 2 methods)

julia> hx(1)
0x02011ce34bce797f

```

---

<div class="post-metadata">

**Author:** ![Jon\_Barker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jon_barker/32/18997_2.png) [@Jon\_Barker](https://discourse.julialang.org/u/Jon_Barker)\
**Post date:** [February 25, 2022, 11:03pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/3 "2022-02-25T23:03:39Z")

</div>

I knew I should have just posted here first. Spent all day on this.

Oh well, thanks!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [February 25, 2022, 11:11pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/4 "2022-02-25T23:11:13Z")

</div>

Just for the future, I identified this by just looking at `@less hash(1, UInt(0))` on both 1.1 and 1.7. From there it’s pretty easy to see how the codepaths diverge and — fortunately! — `Base.hash_uint64` still exists on 1.7 so it’s a short one-liner. Even if it didn’t, though, you could’ve just grabbed its old definition.

---

<div class="post-metadata">

**Author:** ![Jon\_Barker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jon_barker/32/18997_2.png) [@Jon\_Barker](https://discourse.julialang.org/u/Jon_Barker)\
**Post date:** [February 25, 2022, 11:25pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/5 "2022-02-25T23:25:09Z")

</div>

Super useful - I had no idea about the `@less` macro.

I also need to make the code work for tuples `hash((1,2,3))` on 1.7 but I should be able to do that myself via `@less`

Thanks again

---

<div class="post-metadata">

**Author:** ![Jon\_Barker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jon_barker/32/18997_2.png) [@Jon\_Barker](https://discourse.julialang.org/u/Jon_Barker)\
**Post date:** [February 25, 2022, 11:42pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/6 "2022-02-25T23:42:53Z")

</div>

Unfortunately stuck again, as my code below I adapted

`hash_J11(@nospecialize(a), h::UInt) = Base.hash_uint64((3a + reinterpret(UInt64,Float64(a))) - h)`

doesn’t like the `reinterpret` of tuple types:  
e.g.  
`hash_J11((1,"2"), UInt(0))`

![image](https://global.discourse-cdn.com/julialang/original/3X/5/e/5ec58efa58d37d3c8bdb1282f3136222effdfb85.png)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 26, 2022, 2:17am UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/7 "2022-02-26T02:17:45Z")

</div>

Note that in general, you shouldn’t expect `hash` to be stable across versions. If you want a stable `hash`, you shouldn’t use `Base.hash`.

---

<div class="post-metadata">

**Author:** ![Jon\_Barker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jon_barker/32/18997_2.png) [@Jon\_Barker](https://discourse.julialang.org/u/Jon_Barker)\
**Post date:** [February 28, 2022, 3:08pm UTC](https://discourse.julialang.org/t/hash-1-change-between-1-5-and-1-6/77101/8 "2022-02-28T15:08:48Z")

</div>

> [@Oscar\_Smith](#):
>
> `Base.hash` .

Yes - i’m aware of that. I’m not complaining about the hash changing, I’m just attempting to re-create the code that existed under J1.1 in order to attain the same hash.
