Sets
RedBlack.RBSet
($\S{3.3}$)
PureFun.RedBlack.RBSet
— TypeRBSet{O,T} where O
RBSet{O,T}(ord=Base.Order.Forward)
RBSet(iter, o=Base.Order.Forward)
An immutable ordered set. All major operations are $\mathcal{O}(\log{}n)$. Note the ordering parameter, the RBDict iterates in sorted order according to the ordering O
. In addition to the main PFDict
methods, RBDict
implements delete
, popmin
, and popmax
.
Examples
julia> using PureFun, PureFun.RedBlack
julia> s1 = RedBlack.RBSet(1:10)
1
2
3
⋮
8
9
10
julia> s2 = RedBlack.RBSet(1:10, Base.Order.Reverse)
10
9
8
⋮
3
2
1
julia> 1 ∈ s1, 1 ∈ s2
(true, true)
julia> 17 ∈ s1, 17 ∈ s2
(false, false)
julia> 1 ∈ popmin(s1)
false
julia> 17 ∈ push(s2, 17)
true
Use any dictionary as a set: PureFun.@dict2set
PureFun.@dict2set
— Macro@dict2set Name DictType
Given a dictionary implementation, without any extra overhead we can implement a set by mapping every key to nothing
and defining the set methods appropriately. That's what @dict2set
does.
Examples
julia> PureFun.Tries.@trie MyDictionary PureFun.Association.List
julia> PureFun.@dict2set MySet MyDictionary
julia> s = MySet([1,2,2,3,4])
4-element MySet{Int64}
4
3
2
1
julia> push(s, 99)
5-element MySet{Int64}
99
4
3
2
1
julia> 3 ∈ s
true
julia> intersect(s, [1,2,3])
3-element MySet{Int64}
3
2
1