# Dictionary with custom hash function

**URL:** <https://discourse.julialang.org/t/dictionary-with-custom-hash-function/49168>\
**Category:** General Usage\
**Tags:** question, dictionary, hash\
**Created:** [October 28, 2020, 9:50am UTC](https://discourse.julialang.org/t/dictionary-with-custom-hash-function/49168 "2020-10-28T09:50:54Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 28, 2020, 12:04pm UTC](https://discourse.julialang.org/t/dictionary-with-custom-hash-function/49168/4 "2020-10-28T12:04:39Z")

</div>

> [@tisztamo](#):
>
> I was not able to quickly find a package that allows that. Is there any?

Just wrap your keys in a new type:

```julia
struct MyKey
    val::UInt
end
Base.hash(a::MyKey, h::UInt) = xor(a.val, h)
Base.(==)(a::MyKey, b::MyKey) = a.val == b.val

```

---

_[View the full topic](https://discourse.julialang.org/t/dictionary-with-custom-hash-function/49168)._
