Pf::BitSet(I)
Inherits Struct / Value / Object
An immutable set of integers backed by a fixed-width integer of type I.
For BitSet(I), the maximum value is bit_width(I) - 1. For example,
for BitSet8, you can store values 0-7, and for BitSet128, 0-127.
I must be one of UInt8..UInt128. You are advised however to use
one of the aliases BitSet8..BitSet128 instead of dealing with this
struct directly.
NOTE: For consistency, most methods accept and return I. This may
require a few casts here and there on your end. A notable exception is
size: almost everything in Crystal expects its return result to be
an Int32, so we cast it on our end. For similar reasons, we do not
include Enumerable and/or Indexable here: its methods (such as includes?),
which are less constrained, will conflict with our policy of accepting
I only, resulting in spooky suboptimal performance (Enumerable's includes?
is O(N) whereas we're O(1); even though both will end up constant-time
in effect, the former is still slower). Instead, we provide ix, which
gives you an Indexable over the values in the set.
Constructors
Class methods
Instance methods
Yields values in this set along with their index (0, 1, 2, etc.; do not
confuse with bit index).
Returns true if this and other sets have one or more values in common.
Returns the minimum excluded value of this set.
- Mex of an empty set is
0 - Mex of a full set is the bit width of
I(e.g. 64 forBitSet64). Note how the mex itself is outside of the set.
Returns true if all elements of this set are also elements of
a larger other set.
Returns true if this set includes all elements from a strictly
smaller other set.
Returns the nth value in this set. Returns nil if n is out of bounds.
Returns true if all elements of this set are also elements of
the other set.
Returns true if this set includes all elements from the other set.