public class SparseBitSet extends LongSet.Base implements LongSortedSet
log(n)
performance for accessing
individual bits. Memory usage is roughly proportional to bitCount()
. The bit set can set any bit between
0
and Long.MAX_VALUE
, inclusive. However, the maximum number of sparse 64-bit words in use by the
set bits in the bit set is limited by the int length limit of arrays.LongSortedSet.SubSet
LongSet.Base
Constructor and Description |
---|
SparseBitSet()
Construct a
SparseBitSet . |
SparseBitSet(int capacity)
Construct a
SparseBitSet with the given initial capacity. |
SparseBitSet(long... values)
Construct a
SparseBitSet with the given values. |
Modifier and Type | Method and Description |
---|---|
boolean |
addLong(long x) |
long |
bitCount() |
void |
clear()
Reset this
SparseBitSet to the empty state, i.e. with no bits set. |
boolean |
clear(long i)
Clear the bit at index
i . |
boolean |
containsLong(long x) |
LongIterator |
descendingIterator() |
long |
firstLong() |
boolean |
get(long i)
Get the bit at index
i . |
boolean |
isEmpty() |
LongIterator |
iterator() |
long |
lastLong() |
boolean |
removeLong(long x) |
boolean |
set(long i)
Set the bit at index
i . |
boolean |
set(long i,
boolean value)
Set the bit at index
i to the given value . |
int |
size() |
java.lang.String |
toString() |
equals, hashCode
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
comparator, create, create, first, headSet, headSet, last, spliterator, subSet, subSet, tailSet, tailSet
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
addAllLongs, addAllLongs, removeIf, toLongArray
containsAllLongs, containsAllLongs, containsAnyLongs, containsAnyLongs, forEach, forEachLong, from, from, longStream, of, once, once, parallelLongStream, removeAllLongs, removeAllLongs, removeLongsIf, retainAllLongs, retainAllLongs, sequence
public SparseBitSet()
SparseBitSet
.public SparseBitSet(long... values)
SparseBitSet
with the given values.public SparseBitSet(int capacity)
SparseBitSet
with the given initial capacity.public boolean addLong(long x)
addLong
in interface LongCollection
public boolean containsLong(long x)
containsLong
in interface LongIterable
public boolean removeLong(long x)
removeLong
in interface LongIterable
public boolean set(long i)
i
.true
if this bit set changed as a result of setting the bit, i.e. the bit was clear,
false
otherwise.public boolean clear(long i)
i
.true
if this bit set changed as a result of setting the bit, i.e. the bit was set,
false
otherwise.public boolean set(long i, boolean value)
i
to the given value
.true
if this bit set changed as a result of changing the bit, false otherwise.public boolean get(long i)
i
.true
if the bit at index i
is set, false otherwise.public long bitCount()
SparseBitSet
.public int size()
size
in interface java.util.Collection<java.lang.Long>
size
in interface java.util.Set<java.lang.Long>
SparseBitSet
, i.e. the number of set bits.bitCount()
public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.Long>
isEmpty
in interface java.util.Set<java.lang.Long>
isEmpty
in interface LongCollection
isEmpty
in interface LongIterable
isEmpty
in interface LongSet
SparseBitSet
contains no set bits, false otherwise.public void clear()
SparseBitSet
to the empty state, i.e. with no bits set.clear
in interface java.util.Collection<java.lang.Long>
clear
in interface java.util.Set<java.lang.Long>
clear
in interface LongCollection
clear
in interface LongIterable
clear
in interface LongSet
public long firstLong()
firstLong
in interface LongSortedSet
public long lastLong()
lastLong
in interface LongSortedSet
public LongIterator iterator()
iterator
in interface java.lang.Iterable<java.lang.Long>
iterator
in interface java.util.Collection<java.lang.Long>
iterator
in interface java.util.Set<java.lang.Long>
iterator
in interface LongIterable
LongIterator
over the bits in this SparseBitSet
, from lowest to highest.
All LongIterator
methods are constant time. Iterator.remove()
is supported.public LongIterator descendingIterator()
LongIterator
over the bits in this SparseBitSet
, from highest to lowest.
All LongIterator
methods are constant time. Iterator.remove()
is supported.public java.lang.String toString()
toString
in class LongCollection.Base
BitSet
in the same format as BitSet.toString()
, e.g.
the indices of all the set bits in ascending order surrounded by curly brackets "{}"
.