# Failure to match a set element

**URL:** https://discourse.julialang.org/t/failure-to-match-a-set-element/107478
**Category:** Internals & Design
**Tags:** potential-bug
**Created:** [December 12, 2023, 5:57am UTC](https://discourse.julialang.org/t/failure-to-match-a-set-element/107478 "2023-12-12T05:57:45Z")
**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: [December 12, 2023, 1:54pm UTC](https://discourse.julialang.org/t/failure-to-match-a-set-element/107478/4 "2023-12-12T13:54:20Z")

</div>

> [@canthonissen](#):
>
> Mutating set elements (or dictionary key) screws up the indexing mechanics and is very likely to cause the membership check on that element to fail.

Right. See also

- [Modifying object dict keys](https://discourse.julialang.org/t/modifying-object-dict-keys/59266)
- [Unable to access value in dict via known keys](https://discourse.julialang.org/t/unable-to-access-value-in-dict-via-known-keys/103434)
- [Dictionary with multiple identical keys](https://discourse.julialang.org/t/dictionary-with-multiple-identical-keys/4269)
- [Potential confusing behaviour with mutable-key Dict · Issue #33176 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/33176)

An alternative is to use [`IdDict`](https://docs.julialang.org/en/v1/base/collections/#Base.IdDict), which hashes based on object identity. A set is simply based on a dictionary whose values are `nothing`. (In fact, there is an [undocumented `Base.IdSet`](https://github.com/JuliaLang/julia/blob/9374e49f2121457a08ee6b5eefcbb4af6868c5a9/base/idset.jl) that implements this, but doesn’t cover the whole `Set` API.)

---

_[View the full topic](https://discourse.julialang.org/t/failure-to-match-a-set-element/107478)._
