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. Called without an argument, it returns an empty set. If U is omitted, then UInt is taken.
All non-mutating functions for sets are supported. The non-mutating analogs push, pop and delete of the corresponding !-functions are also provided.
SmallCollections.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.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.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.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, x) where 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, default::T) where S <: SmallBitSet -> Tuple{S, Union{Int,T}}If s contains x, return the pair (t, 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.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.