Set은 다음과 같은 특징을 가진 항목들의 모음이에요:
Set() 생성자로 만들 수 있고, 매개변수로는 아무 이터레이터나 넘겨주면 돼요.
julia> s1 = Set(1:4)
Set{Int64} with 4 elements:
4
2
3
1
새 원소는 push!()로 추가하고(배열과 같아요), delete!()로 제거해요.
julia> push!(s1, 5)
Set{Int64} with 5 elements:
5
4
2
3
1
# Duplicates are ignored
julia> push!(s1, 3)
Set{Int64} with 5 elements:
5
4
2
3
1
julia> delete!(s1, 5)
Set{Int64} with 4 elements:
4
2
3
1
julia> length(s1) # length counts entries, despite the non-sequential type
4
다른 여러 컬렉션 타입과 마찬가지로, in이나 ∈ 연산자로 원소가 들어 있는지 확인해요 (기호는 \in을 입력한 뒤 탭을 눌러요).
julia> 3 ∈ s1
true
다음은 두 집합 사이에서 지원되는 연산들이에요 (괄호 안은 연산자 기호를 입력하는 단축키예요).
union(A, B) 또는 A ∪ B (\cup): A 또는 B, 또는 둘 다에 있는 모든 항목.intersect(A, B) 또는 A ∩ B (\cap): A와 B 모두에 있는 모든 항목.setdiff(A, B) (기호 없음): A에는 있지만 B에는 없는 항목.symdiff(A, B) (기호 없음): A 또는 B 중 한쪽에만 있는 항목.issubset(A, B) 또는 A ⊆ B (\subseteq) 또는 B ⊇ A (\supseteq): A의 모든 항목이 B에도 있으면 true.issetequal(A, B) (기호 없음): A와 B가 정확히 같은 항목을 담고 있으면 true.isdisjoint(A, B) (기호 없음): A와 B가 공통으로 가진 항목이 없으면 true (즉 교집합이 비어 있어요).s1 = Set(1:4)
s2 = Set(3:6)
julia> s1 ∪ s2 # union
Set{Int64} with 6 elements:
5
4
6
2
3
1
julia> s1 ∩ s2 # intersect
Set{Int64} with 2 elements:
4
3
julia> setdiff(s1, s2)
Set{Int64} with 2 elements:
2
1
julia> symdiff(s1, s2)
Set{Int64} with 4 elements:
5
6
2
1
julia> s1 ⊇ s2 # issubset
false
이 중 많은 연산에는 함수 이름 끝에 !가 붙은, 값을 직접 바꾸는 버전도 있어요.
전체 함수 목록은 매뉴얼에서 볼 수 있어요.