# Create a user-type set

**URL:** <https://discourse.julialang.org/t/create-a-user-type-set/75420>\
**Category:** General Usage\
**Tags:** type, set, hash\
**Created:** [January 29, 2022, 4:06pm UTC](https://discourse.julialang.org/t/create-a-user-type-set/75420 "2022-01-29T16:06:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [January 29, 2022, 4:06pm UTC](https://discourse.julialang.org/t/create-a-user-type-set/75420/1 "2022-01-29T16:06:29Z")

</div>

hellow, how to create a user type set?

```julia
# i do
mutable struct UserType
    id::Int
end
Base.:(==)(a::UserType, b::UserType) = a.id == b.id
set = Set((UserType(1), UserType(2),))
UserType(1) == UserType(1) # -> true
# but i have
push!(set, UserType(1)) # -> Set{UserType} with 3 elements

```

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 29, 2022, 4:31pm UTC](https://discourse.julialang.org/t/create-a-user-type-set/75420/2 "2022-01-29T16:31:46Z")

</div>

You need to implement `hash` as well as a Set is based on a Dict. See about hashing here [Performance issues when working with dict - #4 by mauro3](https://discourse.julialang.org/t/performance-issues-when-working-with-dict/74565/4)

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [January 29, 2022, 6:31pm UTC](https://discourse.julialang.org/t/create-a-user-type-set/75420/3 "2022-01-29T18:31:41Z")

</div>

The AuthHashEquals.jl README has this warning… probably not a good idea to use mutable objects in a Set (or as keys in a Dict).

> If you use this macro for a mutable type, then the hash depends on the contents of that type, so changing the contents changes the hash. Such types should not be stored in a hash table (Dict) and then mutated, because the objects will be “lost” (as the hash table _assumes_ that hash is constant).
