Small bit sets
SmallCollections.SmallBitSet — TypeSmallBitSet{U<:Unsigned} <: AbstractSet{Int}
SmallBitSet{U}([iter])
SmallBitSet([iter])SmallBitSet{U} is an immutable set that can hold integers between 1 and the bit length of U. The argument iter can be any iterator giving such values. If U is omitted, then UInt is taken. Called without an argument, the constructor returns an empty set.
All non-mutating functions for sets are supported. The non-mutating analogs push, pop and delete of the corresponding !-functions are also provided.
Examples
julia> SmallBitSet((1, 3, 5))
SmallBitSet{UInt64} with 3 elements:
1
3
5
julia> s = SmallBitSet{UInt8}(2*k for k in 1:3)
SmallBitSet{UInt8} with 3 elements:
2
4
6
julia> first(s), last(s)
(2, 6)
julia> 4.0 in s
true
julia> SmallBitSet{UInt32}(s)
SmallBitSet{UInt32} with 3 elements:
2
4
6SmallCollections.bits — Methodbits(s::SmallBitSet{U}) where U -> UReturn the bit mask used internally to store the elements of the set s.
See also convert(::Type{SmallBitSet}, ::Integer).
Base.convert — Methodconvert(::Type{SmallBitSet{U}}, mask::Integer) where U -> SmallBitSet{U}
convert(::Type{SmallBitSet}, mask::Integer) -> SmallBitSet{UInt}Convert a bit mask to a SmallBitSet of the given type. This is the inverse operation to bits.
See also bits.
Examples
julia> s = SmallBitSet{UInt16}([1, 5, 6]);
julia> u = bits(s)
0x0031
julia> convert(SmallBitSet, u)
SmallBitSet{UInt64} with 3 elements:
1
5
6SmallCollections.capacity — Methodcapacity(::Type{<:SmallBitSet}) -> Int
capacity(s::SmallBitSet) -> IntReturn the largest number that the given set or SmallBitSet type can store.
SmallCollections.smallbitsettype — Functionsmallbitsettype(::Val{N}) where N -> Type{<:SmallBitSet}Returns a type SmallBitSet{U} where U <: Unsigned has at least N bits.
Examples
julia> smallbitsettype(Val(30))
SmallBitSet{UInt32}
julia> smallbitsettype(Val(200))
SmallBitSet{BitIntegers.UInt256}SmallCollections.fasthash — Methodfasthash(s::SmallBitSet [, h0::UInt]) -> UIntReturn a hash for s that can be computed fast. This hash is consistent across all SmallBitSets, but it is not compatible with the hash used for sets.
See also Base.hash.
Examples
julia> s = SmallBitSet(1:3);
julia> fasthash(s)
0x828a4cc485149963
julia> fasthash(s) == hash(s)
false
julia> t = SmallBitSet{UInt16}(s);
julia> fasthash(s) == fasthash(t)
trueBase.empty — Methodempty(s::S) where S <: SmallBitSet -> SReturn an empty SmallBitSet of the same type as s.
SmallCollections.first_as_set — Functionfirst_as_set(s::S) where S <: SmallBitSet -> SReturns the smallest element of s as a singleton. If s is empty, then an empty set is returned.
See also Base.first.
Examples
julia> s = SmallBitSet{UInt8}(3:5);
julia> first_as_set(s)
SmallBitSet{UInt8} with 1 element:
3
julia> first_as_set(empty(s))
SmallBitSet{UInt8}([])SmallCollections.push — Methodpush(s::S, xs...) where S <: SmallBitSet -> SReturn the SmallBitSet obtained from s by adding the other arguments xs.
See also Base.push!, BangBang.push!!, SmallCollections.unsafe_push.
SmallCollections.pop — Methodpop(s::S) where S <: SmallBitSet -> Tuple{S, Int}Return the pair (t, x) where x is the smallest element from s and t is the set s with x deleted. The set s must be non-empty.
See also Base.pop!, BangBang.pop!!.
SmallCollections.pop — Methodpop(s::S, x) where S <: SmallBitSet -> Tuple{S, Int}Return the pair (t, Int(x)) where t is the set s with x deleted. The set s must contain x.
See also Base.pop!, BangBang.pop!!.
SmallCollections.pop — Methodpop(s::S, x, default::T) where S <: SmallBitSet -> Tuple{S, Union{Int,T}}If s contains x, return the pair (t, Int(x)) where t is the set s with x deleted. Otherwise return (s, default)
See also Base.pop!, BangBang.pop!!.
SmallCollections.delete — Methoddelete(s::S, x) where S <: SmallBitSet -> SIf s contains x, return the set obtained by deleting that element. Otherwise return s.
See also Base.delete!, BangBang.delete!!, SmallCollections.unsafe_delete.
SmallCollections.exchange — Functionexchange(s::S, i::Integer, j::Integer) where S <: SmallBitSet -> SReturn the set s with the element i, if present, replaced by j and vice versa. If i equals j, then the set is not modified.
This function is faster than the equivalent replace(s, i => j, j => i).
See also Base.replace.
Examples
julia> s = SmallBitSet((1, 2)); exchange(s, 1, 2)
SmallBitSet{UInt64} with 2 elements:
1
2
julia> s = SmallBitSet((1, 2)); exchange(s, 2, 3)
SmallBitSet{UInt64} with 2 elements:
1
3
julia> s = SmallBitSet((1, 2)); exchange(s, 3, 4)
SmallBitSet{UInt64} with 2 elements:
1
2
julia> s = SmallBitSet((1, 2)); exchange(s, 1, 1)
SmallBitSet{UInt64} with 2 elements:
1
2Base.any — Methodany(f::Function, s::SmallBitSet{U}; [style::MapStyle]) where U
all(f::Function, s::SmallBitSet{U}; [style::MapStyle]) where U
count(f, s::SmallBitSet{U}; init = 0, [style::MapStyle]) where U
filter(f, s::SmallBitSet{U}; [style::MapStyle]) where UWith a SmallBitSet s as second argument, these functions accept the additional keyword argument style. If it equals LazyStyle(), then the function f is only evaluated for elements of s. For any other value of style, f is evaluated on all numbers between 1 and the bit size of U. This is often faster for simple functions.
As discussed under MapStyle, the default value for style is based on a list of known functions.
See also SmallCollections.MapStyle.
Base.checkbounds — Functioncheckbounds(::Type{Bool}, v::Union{AbstractFixedVector, AbstractSmallVector, PackedVector}, s::SmallBitSet) -> BoolReturns true if all elements of s are inbounds for v.
See alse Base.checkbounds.
Examples
julia> v = SmallVector{8,Int8}(1:3)
3-element SmallVector{8, Int8}:
1
2
3
julia> s = SmallBitSet{UInt8}((1, 4))
SmallBitSet{UInt8} with 2 elements:
1
4
julia> checkbounds(Bool, v, s)
false
julia> checkbounds(v, s)
ERROR: BoundsError: attempt to access 3-element SmallVector{8, Int8} at index [SmallBitSet{UInt8}([1, 4])]Orderings
The following orderings are available to compare one SmallBitSet to another.
Base.isless — Methodisless(s::SmallBitSet, t::SmallBitSet) -> BoolCompares s and t in the colexicographic ordering.
Currently, sorting with the default ordering given by isless is significantly faster than specifiying one of the other orderings (including Colex).
See also SmallCollections.Colex.
SmallCollections.Lex — ConstantSmallCollections.Lex <: Base.Order.OrderingThe lexicographic ordering for SmallBitSet. This is the slowest among the available orderings.
See also SmallCollections.Colex, SmallCollections.GradedLex.
SmallCollections.Colex — ConstantSmallCollections.Colex <: Base.Order.OrderingThe colexicographic ordering for SmallBitSet.
See also SmallCollections.Lex, SmallCollections.GradedColex.
SmallCollections.GradedLex — ConstantSmallCollections.GradedLex <: Base.Order.OrderingThe graded lexicographic ordering for SmallBitSet. A smaller set either has smaller size, or for equal size it is smaller in the lexicographic ordering.
See also SmallCollections.Lex, SmallCollections.GradedColex.
SmallCollections.GradedColex — ConstantSmallCollections.GradedColex <: Base.Order.OrderingThe graded colexicographic ordering for SmallBitSet. A smaller set either has smaller size, or for equal size it is smaller in the colexicographic ordering.
See also SmallCollections.GradedLex, SmallCollections.Colex.