public interface BitSequence extends Iterable<Boolean>
BitSet
except it provides
better API for navigating the bits like a stream (of arbitrarily sized chunks) and less API for
general bit-fiddling. Unlike BitSet
, a BitSequence
is immutable.
Since the sequence is immutable, all attempts to remove elements using
Iterator
s will result in an UnsupportedOperationException
being thrown.
Modifier and Type | Interface and Description |
---|---|
static class |
BitSequence.BitOrder
Indicates how bits are ordered when extracting bits into numeric types.
|
Modifier and Type | Method and Description |
---|---|
default BitStream |
bitStream()
Returns a stream, for consuming bits in arbitrary amounts with each fetch.
|
BitStream |
bitStream(int startIndex)
Returns a stream, for consuming bits in arbitrary amounts with each fetch.
|
default PrimitiveIterator.OfLong |
bitTupleIterator(int tupleSize)
Returns an iterator over arbitrarily-sized chunks in the sequence.
|
default PrimitiveIterator.OfLong |
bitTupleIterator(int tupleSize,
BitSequence.BitOrder order)
Returns an iterator over arbitrarily-sized chunks in the sequence.
|
default PrimitiveIterator.OfLong |
bitTupleIterator(int tupleSize,
int startIndex)
Returns an iterator over arbitrarily-sized chunks in the sequence.
|
PrimitiveIterator.OfLong |
bitTupleIterator(int tupleSize,
int startIndex,
BitSequence.BitOrder order)
Returns an iterator over arbitrarily-sized chunks in the sequence.
|
default LongStream |
bitTupleStream(int tupleSize)
Creates a
LongStream over arbitrarily-sized chunks of bits. |
default LongStream |
bitTupleStream(int tupleSize,
BitSequence.BitOrder bitOrder)
Creates a
LongStream over arbitrarily-sized chunks of bits. |
boolean |
equals(Object o)
Returns true if the specified object is a
BitSequence with the same contents and in
the same order as this sequence. |
int |
hashCode()
Returns a hash code for the sequence.
|
default BooleanIterator |
iterator()
Returns an iterator over the values in the sequence.
|
BooleanIterator |
iterator(int startIndex)
Returns an iterator over the values in the sequence starting at the specified index.
|
int |
length()
Gets the length of the sequence.
|
default BitSequence |
subSequence(int start,
int end)
Returns a view of a portion of this sequence.
|
forEach, spliterator
int length()
default BooleanIterator iterator()
Iterable.iterator()
so that iteration can be done over un-boxed primitives.BooleanIterator iterator(int startIndex)
startIndex
- the starting index (inclusive) for iterationIndexOutOfBoundsException
- if the specified index is negative or is greater than the
length of the sequencedefault PrimitiveIterator.OfLong bitTupleIterator(int tupleSize, BitSequence.BitOrder order)
LSB
order,
the zero bits are on the more significant end of the value. But for MSB
order, the zero bits are on the less significant end, which means the last value is
effectively shifted left by the number of bits absent from the sequence.tupleSize
- the number of bits of each chunkorder
- the order of bits in the returned valueIllegalArgumentException
- if the specified tuple size is less than one or greater than
sixty-four.BitStream.next(int, BitSequence.BitOrder)
default PrimitiveIterator.OfLong bitTupleIterator(int tupleSize)
bitSequence.bitTupleIterator(tupleSize, BitOrder.LSB);
tupleSize
- the number of bits of each chunkIllegalArgumentException
- if the specified tuple size is less than one or greater than
sixty-four.bitTupleIterator(int, BitOrder)
PrimitiveIterator.OfLong bitTupleIterator(int tupleSize, int startIndex, BitSequence.BitOrder order)
tupleSize
- the number of bits of each chunkstartIndex
- an offset into the sequence from which the tuples will startorder
- the order of bits in the returned valueIllegalArgumentException
- if the specified tuple size is less than one or greater than
sixty-four.bitTupleIterator(int, BitOrder)
default PrimitiveIterator.OfLong bitTupleIterator(int tupleSize, int startIndex)
bitSequence.bitTupleIterator(tupleSize, startIndex, BitOrder.LSB);
tupleSize
- the number of bits of each chunkstartIndex
- an offset into the sequence from which the tuples will startIllegalArgumentException
- if the specified tuple size is less than one or greater than
sixty-four.bitTupleIterator(int, int, BitOrder)
default BitSequence subSequence(int start, int end)
start
- the starting position of the portion of interest, inclusiveend
- the end position of the portion of interest, exclusiveBitSequence
default BitStream bitStream()
BitStream bitStream(int startIndex)
startIndex
- an offset into the sequence from which the stream will startdefault LongStream bitTupleStream(int tupleSize)
LongStream
over arbitrarily-sized chunks of bits. This is similar to
bitTupleIterator(int)
but allowing functional operations on the stream of values.tupleSize
- the number of bits of each chunkdefault LongStream bitTupleStream(int tupleSize, BitSequence.BitOrder bitOrder)
LongStream
over arbitrarily-sized chunks of bits. This is similar to
bitTupleIterator(int, BitOrder)
but allowing functional operations on the stream of
values.tupleSize
- the number of bits of each chunkbitOrder
- the order of bits in the returned valuebitTupleIterator(int, BitOrder)
int hashCode()
hash code = length of the sequence XOR hash code of corresponding list of longsThe corresponding list of longs means a
List
of Long
s whose length
is exactly enough to contain all of the bits in the sequence, whose first element represents
the first 64 bits of the sequence (least significant bit first), and whose last element
represents the last 1 to 64 bits (least significant bit first) with any superfluous (most
significant) bits zeroed out when the sequence length is not a multiple of 64.
The second term in the hash code happens to be the same as calculated by
Arrays.hashCode(long[])
with an array whose contents correspond to the bits
in the sequence (in the same manner described above).
boolean equals(Object o)
BitSequence
with the same contents and in
the same order as this sequence.