# \#set

**URL:** https://discourse.julialang.org/tag/set/355.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Set theoretic semantics of the type system](https://discourse.julialang.org/t/set-theoretic-semantics-of-the-type-system/136772)

<div class="topic-metadata">

**Author:** [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Replies:** 7\
**Last updated:** [April 22, 2026, 8:33am UTC](https://discourse.julialang.org/t/set-theoretic-semantics-of-the-type-system/136772 "2026-04-22T08:33:56Z")

</div>

Not sure if I should post under Offtopic but anyway… In Bezanson’s PhD thesis in 2015, he mentions that Set-theoretic types are a natural basis for such a system. A set-theoretic type is a symbolic expression that den…

---

## [\[ANN\] SmallCollections.jl: fast small vectors, sets and dictionaries](https://discourse.julialang.org/t/ann-smallcollections-jl-fast-small-vectors-sets-and-dictionaries/128787)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 9\
**Last updated:** [November 7, 2025, 1:01pm UTC](https://discourse.julialang.org/t/ann-smallcollections-jl-fast-small-vectors-sets-and-dictionaries/128787 "2025-11-07T13:01:55Z")

</div>

The standard container types in Julia (Vector, Set, Dict) can hold an arbitrary number of elements. If the size is known in advance, one can use dedicated types like SVector or MVector from StaticArrays.jl that are much …

---

## [Receive the success status of \`pop!(Set, element)\`](https://discourse.julialang.org/t/receive-the-success-status-of-pop-set-element/131089)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 6\
**Last updated:** [July 29, 2025, 7:54am UTC](https://discourse.julialang.org/t/receive-the-success-status-of-pop-set-element/131089 "2025-07-29T07:54:44Z")

</div>

Continuing the discussion from Receive the success status of \`push!(Set, element)\`: The following defined method # collect \`e\` into \`S\`, return success status collect!(S, e) = !in!(e, S) should have an inverse, which …

---

## [Receive the success status of \`push!(Set, element)\`](https://discourse.julialang.org/t/receive-the-success-status-of-push-set-element/130988)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 24\
**Last updated:** [July 25, 2025, 8:21am UTC](https://discourse.julialang.org/t/receive-the-success-status-of-push-set-element/130988 "2025-07-25T08:21:15Z")

</div>

I can push! an element to a Set. julia\> S = Set(); julia\> e = 1; julia\> push!(S, e) Set{Any} with 1 element: 1 But I am not aware of a straightforward way to understand if the element e was new to S. Therefore I w…

---

## [Get an equal element of a set/get an equal key of a dictionary](https://discourse.julialang.org/t/get-an-equal-element-of-a-set-get-an-equal-key-of-a-dictionary/128779)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 4\
**Last updated:** [May 7, 2025, 3:52pm UTC](https://discourse.julialang.org/t/get-an-equal-element-of-a-set-get-an-equal-key-of-a-dictionary/128779 "2025-05-07T15:52:26Z")

</div>

Suppose I have x and s::AbstractSet and I know x ∈ s. How to get the element of s, say e, such that x == e? I could iterate through all elements like this, but surely there should be a simpler and more efficient solution…

---

## [Create a set with custom hash and isequal](https://discourse.julialang.org/t/create-a-set-with-custom-hash-and-isequal/127862)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 7\
**Last updated:** [April 9, 2025, 7:31pm UTC](https://discourse.julialang.org/t/create-a-set-with-custom-hash-and-isequal/127862 "2025-04-09T19:31:09Z")

</div>

Is it possible to create a Set{MyType} that uses a custom hash and isequal functions s.t. it is essentially a set of equivalence classes w.r.t the equivalence relation defined by my hash and isequal? I want to do this wi…

---

## [\[ANN\] EnumSets.jl](https://discourse.julialang.org/t/ann-enumsets-jl/123671)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 6\
**Last updated:** [December 11, 2024, 3:57pm UTC](https://discourse.julialang.org/t/ann-enumsets-jl/123671 "2024-12-11T15:57:52Z")

</div>

I am pleased to announce EnumSets.jl. From the readme: EnumSets This packages allows to create a very fast immutable type that represents a set of enum values. julia\> using EnumSets julia\> @enum Lang Python Julia …

---

## [Can I speed up this recursive set implementation?](https://discourse.julialang.org/t/can-i-speed-up-this-recursive-set-implementation/113917)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 38\
**Last updated:** [May 10, 2024, 7:37am UTC](https://discourse.julialang.org/t/can-i-speed-up-this-recursive-set-implementation/113917 "2024-05-10T07:37:37Z")

</div>

Hey there! I come to you with another performance nerdsnipe, whose solution could have a big impact on the autodiff ecosystem (via SparseConnectivityTracer.jl and DifferentiationInterface.jl). You may remember my first…

---

## [Best data structure for fast unions of large sets of integers](https://discourse.julialang.org/t/best-data-structure-for-fast-unions-of-large-sets-of-integers/113785)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 56\
**Last updated:** [May 6, 2024, 6:23pm UTC](https://discourse.julialang.org/t/best-data-structure-for-fast-unions-of-large-sets-of-integers/113785 "2024-05-06T18:23:10Z")

</div>

Nerdsnipe alert In the SparseConnectivityTracer.jl project, @hill and I need to efficiencly compute unions of non-disjoint sets of integers, which can be very large (thousands, even millions). The default Set{Int} is …

---

## [Unexpected behavior of loop over set](https://discourse.julialang.org/t/unexpected-behavior-of-loop-over-set/104371)

<div class="topic-metadata">

**Author:** [@Yly](https://discourse.julialang.org/u/Yly)\
**Replies:** 1\
**Last updated:** [September 29, 2023, 1:34am UTC](https://discourse.julialang.org/t/unexpected-behavior-of-loop-over-set/104371 "2023-09-29T01:34:09Z")

</div>

I have the following (minimized, but perhaps not minimal) code snippet which is intended to group nodes of graph components. The surprising thing is that it seems to imply that elements of a set are not in the set. ns …

---

## [Why are the items in Julia's Sets mutable, but there is no immutable version of the latter?](https://discourse.julialang.org/t/why-are-the-items-in-julias-sets-mutable-but-there-is-no-immutable-version-of-the-latter/102898)

<div class="topic-metadata">

**Author:** [@ARCJ137442](https://discourse.julialang.org/u/ARCJ137442)\
**Replies:** 1\
**Last updated:** [August 17, 2023, 10:05am UTC](https://discourse.julialang.org/t/why-are-the-items-in-julias-sets-mutable-but-there-is-no-immutable-version-of-the-latter/102898 "2023-08-17T10:05:50Z")

</div>

Background First, clarify a point: a set in Julia is an “immutable type”, but in its definition (’ set.jl ‘), a set is represented as a “wrapper around a Dict”, and this “immutability” is represented as "you cannot chan…

---

## [Getting a specific item from a Set](https://discourse.julialang.org/t/getting-a-specific-item-from-a-set/88786)

<div class="topic-metadata">

**Author:** [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)\
**Replies:** 7\
**Last updated:** [October 15, 2022, 11:06pm UTC](https://discourse.julialang.org/t/getting-a-specific-item-from-a-set/88786 "2022-10-15T23:06:55Z")

</div>

Hi, I have a set filled with custom objects. How can I get a specific item from the set equal to another object? For example, I have a set of points. Then, I add a new point pp1. If pp1 already exists in the set, I wa…

---

## [(Efficiently) construct a Dictionary from a Set](https://discourse.julialang.org/t/efficiently-construct-a-dictionary-from-a-set/83896)

<div class="topic-metadata">

**Author:** [@April-Hannah-Lena](https://discourse.julialang.org/u/April-Hannah-Lena)\
**Replies:** 15\
**Last updated:** [July 14, 2022, 11:24am UTC](https://discourse.julialang.org/t/efficiently-construct-a-dictionary-from-a-set/83896 "2022-07-14T11:24:27Z")

</div>

In our package we have some data structures that act as wrappers around Set{Int} to keep track of various index sets. We now want to insert a ‘weight’ for each item in the set, ie construct a Dict{Int,Float64}, and we wa…

---

## [Edge case in Sets with Floats](https://discourse.julialang.org/t/edge-case-in-sets-with-floats/78787)

<div class="topic-metadata">

**Author:** [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Replies:** 6\
**Last updated:** [March 31, 2022, 12:25pm UTC](https://discourse.julialang.org/t/edge-case-in-sets-with-floats/78787 "2022-03-31T12:25:00Z")

</div>

Hi Julia Community, recently I was approached by a colleague who just got started with Julia and ran into a problem that took him ages to debug. We then seat down together and could come up with the following MWE: juli…

---

## [Create a user-type set](https://discourse.julialang.org/t/create-a-user-type-set/75420)

<div class="topic-metadata">

**Author:** [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Replies:** 2\
**Last updated:** [January 29, 2022, 6:31pm UTC](https://discourse.julialang.org/t/create-a-user-type-set/75420 "2022-01-29T18:31:41Z")

</div>

hellow, how to create a user type set? # 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 # bu…

---

## [Clear dict?](https://discourse.julialang.org/t/clear-dict/74742)

<div class="topic-metadata">

**Author:** [@unis](https://discourse.julialang.org/u/unis)\
**Replies:** 2\
**Last updated:** [January 20, 2022, 5:58am UTC](https://discourse.julialang.org/t/clear-dict/74742 "2022-01-20T05:58:33Z")

</div>

In Python, one may a clear a dict as follows d = {1:'a'} d.clear() In Julia, I’d have expected a similar workflow along the lines of d = Dict(1=\>'a') clear!(d) To my surprise, there seems to be no such function clear…

---

## [Find the intersection of elements of powerset one by one](https://discourse.julialang.org/t/find-the-intersection-of-elements-of-powerset-one-by-one/72763)

<div class="topic-metadata">

**Author:** [@XLVII](https://discourse.julialang.org/u/XLVII)\
**Replies:** 3\
**Last updated:** [December 8, 2021, 3:02pm UTC](https://discourse.julialang.org/t/find-the-intersection-of-elements-of-powerset-one-by-one/72763 "2021-12-08T15:02:57Z")

</div>

Let S = { trigon, tetragon , pentagon , ... ,... } is a set of polygons How to calculate intersection of subsets of (every element actually) Powerset(S) Powerset(S) =\[ {} , {trigon} , {tetragon} , {pentagon} , {trigon,…

---

## [How to create multidimensional sets in JuMP/Julia as in GAMS](https://discourse.julialang.org/t/how-to-create-multidimensional-sets-in-jump-julia-as-in-gams/55581)

<div class="topic-metadata">

**Author:** [@GraceMabele](https://discourse.julialang.org/u/GraceMabele)\
**Replies:** 5\
**Last updated:** [February 20, 2021, 10:49am UTC](https://discourse.julialang.org/t/how-to-create-multidimensional-sets-in-jump-julia-as-in-gams/55581 "2021-02-20T10:49:38Z")

</div>

In GAMS, we can create multidimensional sets as follows Set i "mining regions" / china, ghana, ee+ussr, s-leone / n "ports" / accra, freetown, leningrad, shanghai / in(i,n) "mines to…

---

## [Struct equality seems weird inside Sets](https://discourse.julialang.org/t/struct-equality-seems-weird-inside-sets/51283)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 6\
**Last updated:** [December 5, 2020, 12:52am UTC](https://discourse.julialang.org/t/struct-equality-seems-weird-inside-sets/51283 "2020-12-05T00:52:53Z")

</div>

Can someone help me understand this behavior? So I define a struct. To define what equality means for the struct, I define the == function for the struct, and also a hash() function. Note the println() statements i…

---

## [In operator for set of sets](https://discourse.julialang.org/t/in-operator-for-set-of-sets/50474)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 5\
**Last updated:** [November 20, 2020, 11:40am UTC](https://discourse.julialang.org/t/in-operator-for-set-of-sets/50474 "2020-11-20T11:40:53Z")

</div>

Can I get some help with explaining this behaviour? At first it seems that you can find the existence of a set within a set of sets, but after I make a modification to the set I cannot do so?

---

## [In what way are Julia sets immutable?](https://discourse.julialang.org/t/in-what-way-are-julia-sets-immutable/49009)

<div class="topic-metadata">

**Author:** [@Mark\_Graph](https://discourse.julialang.org/u/Mark_Graph)\
**Replies:** 5\
**Last updated:** [October 26, 2020, 9:46am UTC](https://discourse.julialang.org/t/in-what-way-are-julia-sets-immutable/49009 "2020-10-26T09:46:32Z")

</div>

If I create a set in Julia, then Julia will tell me that the set is immutable. julia\> pets = Set(\["dog", "cat", "budgerigar"\]) Set{String} with 3 elements: "cat" "budgerigar" "dog" julia\> ismutable(pets) false N…

---

## [How to save Set to file?](https://discourse.julialang.org/t/how-to-save-set-to-file/35506)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 2\
**Last updated:** [March 4, 2020, 8:35am UTC](https://discourse.julialang.org/t/how-to-save-set-to-file/35506 "2020-03-04T08:35:05Z")

</div>

How to save Set ? julia\> Sunikalne Set(\[“WYMYŚLA”, “PRZEPRZĘGAJĄCE”\]) julia\> typeof(Sunikalne) Set{String} julia\> eltype(Sunikalne) String julia\> write(“Sunikalne.txt”,Sunikalne) ERROR: MethodError: no method mat…

---

## [Best way to convert a NTuple to a Set](https://discourse.julialang.org/t/best-way-to-convert-a-ntuple-to-a-set/27532)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 2\
**Last updated:** [August 14, 2019, 8:48pm UTC](https://discourse.julialang.org/t/best-way-to-convert-a-ntuple-to-a-set/27532 "2019-08-14T20:48:51Z")

</div>

I did: julia\> ntup = (1, 2, 3, 4, 5, 6), NTuple{6, Int} julia\> Set(ntup) Set(Any\[(1, 2, 3, 4, 5, 6), NTuple{6,Int64}\]) But I want to get a set of Int64. How can I achieve that?
