public interface DirectBitSet extends ReferenceCounted
java.util.BitSet
is that DirectBitSet
has a rigid size()
,
attempts to get(long)
, set(long)
or clear(long)
bits at indices
exceeding the size cause IndexOutOfBoundsException
. There is also
a setAll()
method to set all bits within the size.
java.util.BitSet
doesn't have such rigid capacity.BitSet
Modifier and Type | Interface and Description |
---|---|
static interface |
DirectBitSet.Bits
An iteration of bits in a bit set.
|
Modifier and Type | Field and Description |
---|---|
static long |
NOT_FOUND
Returned if no entry is found
|
Modifier and Type | Method and Description |
---|---|
DirectBitSet |
and(long longIndex,
long value)
Performs a logical AND of the long at the specified index in this
bit set with the argument long value.
|
DirectBitSet |
andNot(long longIndex,
long value)
Clears all of the bits in the long at the specified index in this
DirectBitSet whose corresponding bit is set in the specified
long value. |
long |
cardinality()
Returns the number of bits set to
true in this DirectBitSet . |
DirectBitSet |
clear()
Sets all of the bits in this BitSet to
false . |
DirectBitSet |
clear(long bitIndex)
Sets the bit specified by the index to
false . |
DirectBitSet |
clear(long fromIndex,
long toIndex)
Sets the bits from the specified
fromIndex (inclusive) to the
specified toIndex (exclusive) to false . |
boolean |
clearIfSet(long bitIndex)
Clears the bit at the specified index (sets it to
false ). |
long |
clearNextNContinuousSetBits(long fromIndex,
int numberOfBits)
Finds the next
numberOfBits consecutive bits set to true ,
starting from the specified fromIndex . |
long |
clearNextSetBit(long fromIndex)
Finds and clears the first bit that is set to
true
that occurs on or after the specified starting index. |
long |
clearPreviousNContinuousSetBits(long fromIndex,
int numberOfBits)
Finds the previous
numberOfBits consecutive bits
set to true , starting from the specified fromIndex . |
long |
clearPreviousSetBit(long fromIndex)
Finds and clears the nearest bit that is set to
true
that occurs on or before the specified starting index. |
DirectBitSet |
flip(long bitIndex)
Sets the bit at the specified index to the complement of its
current value.
|
DirectBitSet |
flip(long fromIndex,
long toIndex)
Sets each bit from the specified
fromIndex (inclusive) to the
specified toIndex (exclusive) to the complement of its current
value. |
boolean |
get(long bitIndex)
Returns the value of the bit with the specified index.
|
long |
getLong(long longIndex)
Returns the value of the long with the specified long index.
|
boolean |
isClear(long bitIndex)
Synonym of
!get(long) . |
boolean |
isSet(long bitIndex)
Synonym of
get(long) . |
long |
nextClearBit(long fromIndex)
Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index. |
long |
nextClearLong(long fromLongIndex)
Returns the index of the first long that contains a bit is set to
false
that occurs on or after the specified starting index. |
long |
nextSetBit(long fromIndex)
Returns the index of the first bit that is set to
true
that occurs on or after the specified starting index. |
long |
nextSetLong(long fromLongIndex)
Returns the index of the first long that contains a bit set to
true
that occurs on or after the specified starting index. |
DirectBitSet |
or(long longIndex,
long value)
Performs a logical OR of the long at the specified index in this
bit set with the argument long value.
|
long |
previousClearBit(long fromIndex)
Returns the index of the nearest bit that is set to
false
that occurs on or before the specified starting index. |
long |
previousClearLong(long fromLongIndex)
Returns the index of the nearest long that contains a bit set to
false
that occurs on or before the specified starting index. |
long |
previousSetBit(long fromIndex)
Returns the index of the nearest bit that is set to
true
that occurs on or before the specified starting index. |
long |
previousSetLong(long fromLongIndex)
Returns the index of the nearest long that contains a bit set to
true
that occurs on or before the specified starting index. |
DirectBitSet |
set(long bitIndex)
Sets the bit at the specified index to
true . |
DirectBitSet |
set(long bitIndex,
boolean value)
Sets the bit at the specified index to the specified value.
|
DirectBitSet |
set(long fromIndex,
long toIndex)
Sets the bits from the specified
fromIndex (inclusive) to the
specified toIndex (exclusive) to true . |
DirectBitSet |
set(long fromIndex,
long toIndex,
boolean value)
Sets the bits from the specified
fromIndex (inclusive) to the
specified toIndex (exclusive) to the specified value. |
DirectBitSet |
setAll()
Sets all bits,
bs.setAll() is equivalent
of bs.set(0, bs.size() . |
DirectBitSet.Bits |
setBits()
Returns an iteration of set bits in direct order
(from 0 to the end of the bit set).
|
boolean |
setIfClear(long bitIndex)
Sets the bit at the specified index to
true . |
long |
setNextClearBit(long fromIndex)
Finds and sets to
true the first bit that is set to false
that occurs on or after the specified starting index. |
long |
setNextNContinuousClearBits(long fromIndex,
int numberOfBits)
Finds the next
numberOfBits consecutive bits set to false ,
starting from the specified fromIndex . |
long |
setPreviousClearBit(long fromIndex)
Finds and sets to
true the nearest bit that is set
to false that occurs on or before the specified starting index. |
long |
setPreviousNContinuousClearBits(long fromIndex,
int numberOfBits)
Finds the previous
numberOfBits consecutive bits
set to false , starting from the specified fromIndex . |
long |
size()
Returns the number of bits of space actually in use by this BitSet to represent bit values.
|
DirectBitSet |
xor(long longIndex,
long value)
Performs a logical XOR of the long at the specified index in this
bit set with the argument long value.
|
refCount, release, reserve
static final long NOT_FOUND
DirectBitSet flip(long bitIndex)
bitIndex
- the index of the bit to flipDirectBitSet
backIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
DirectBitSet flip(long fromIndex, long toIndex)
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to the complement of its current
value.fromIndex
- index of the first bit to fliptoIndex
- index after the last bit to flipDirectBitSet
backIndexOutOfBoundsException
- if fromIndex
is negative,
or fromIndex
is larger than toIndex
,
or toIndex
is larger or equal to size()
DirectBitSet set(long bitIndex)
true
.bitIndex
- a bit indexDirectBitSet
backIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
boolean setIfClear(long bitIndex)
true
.bitIndex
- a bit indexIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
boolean clearIfSet(long bitIndex)
false
).bitIndex
- a bit indexIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
DirectBitSet set(long bitIndex, boolean value)
bitIndex
- a bit indexvalue
- a boolean value to setDirectBitSet
backIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
DirectBitSet set(long fromIndex, long toIndex)
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to true
.fromIndex
- index of the first bit to be settoIndex
- index after the last bit to be setDirectBitSet
backIndexOutOfBoundsException
- if fromIndex
is negative,
or fromIndex
is larger than toIndex
,
or toIndex
is larger or equal to size()
DirectBitSet setAll()
bs.setAll()
is equivalent
of bs.set(0, bs.size()
.DirectBitSet set(long fromIndex, long toIndex, boolean value)
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to the specified value.fromIndex
- index of the first bit to be settoIndex
- index after the last bit to be setvalue
- value to set the selected bits toDirectBitSet
backIndexOutOfBoundsException
- if fromIndex
is negative,
or fromIndex
is larger than toIndex
,
or toIndex
is larger or equal to size()
DirectBitSet clear(long bitIndex)
false
.bitIndex
- the index of the bit to be clearedDirectBitSet
backIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
DirectBitSet clear(long fromIndex, long toIndex)
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to false
.fromIndex
- index of the first bit to be clearedtoIndex
- index after the last bit to be clearedDirectBitSet
backIndexOutOfBoundsException
- if fromIndex
is negative,
or fromIndex
is larger than toIndex
,
or toIndex
is larger or equal to size()
DirectBitSet clear()
false
.DirectBitSet
backboolean get(long bitIndex)
true
if the bit with the index bitIndex
is currently set in this DirectBitSet
; otherwise, the result
is false
.bitIndex
- the bit indexIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
boolean isSet(long bitIndex)
get(long)
.bitIndex
- the bit indexIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
boolean isClear(long bitIndex)
!get(long)
.bitIndex
- the bit indextrue
is the bit at the specified index is clear in this
bit set; if the bit is set to true
then returns false
IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
long getLong(long longIndex)
longIndex
- the bit indexIndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size() / 64)
long nextSetBit(long fromIndex)
true
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.
To iterate over the true
bits in a DirectBitSet
,
use the following loop:
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
// operate on index i here
}
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitIndexOutOfBoundsException
- if the specified index is negativeclearNextSetBit(long)
long nextSetLong(long fromLongIndex)
true
that occurs on or after the specified starting index. The index is the number of longs.
If no such bit exists then -1
is returned.fromLongIndex
- the index to start checking from (inclusive)-1
if there
is no such longIndexOutOfBoundsException
- if the specified index is negativelong nextClearBit(long fromIndex)
false
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.fromIndex
- the index to start checking from (inclusive)-1
if there is no such bitIndexOutOfBoundsException
- if the specified index is negativesetNextClearBit(long)
long nextClearLong(long fromLongIndex)
false
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.fromLongIndex
- the index to start checking from (inclusive)-1
if there is no such longIndexOutOfBoundsException
- if the specified index is negativelong previousSetBit(long fromIndex)
true
that occurs on or before the specified starting index.
If no such bit exists, or if -1
is given as the
starting index, then -1
is returned.
To iterate over the true
bits in a DirectBitSet
,
use the following loop:
for (int i = bs.size(); (i = bs.previousSetBit(i-1)) >= 0; ) {
// operate on index i here
}
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitIndexOutOfBoundsException
- if the specified index is less
than -1
clearPreviousSetBit(long)
long previousSetLong(long fromLongIndex)
true
that occurs on or before the specified starting index.
If no such bit exists, or if -1
is given as the
starting index, then -1
is returned.fromLongIndex
- the index to start checking from (inclusive)-1
if there is no such longIndexOutOfBoundsException
- if the specified index is less
than -1
long previousClearBit(long fromIndex)
false
that occurs on or before the specified starting index.
If no such bit exists, or if -1
is given as the
starting index, then -1
is returned.fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitIndexOutOfBoundsException
- if the specified index is less
than -1
setPreviousClearBit(long)
long previousClearLong(long fromLongIndex)
false
that occurs on or before the specified starting index.
If no such bit exists, or if -1
is given as the
starting index, then -1
is returned.fromLongIndex
- the index to start checking from (inclusive)-1
if there is no such longIndexOutOfBoundsException
- if the specified index is less
than -1
long size()
size() - 1
.long cardinality()
true
in this DirectBitSet
.true
in this DirectBitSet
DirectBitSet and(long longIndex, long value)
longIndex
- of long to ANDvalue
- of long to ANDDirectBitSet
backDirectBitSet or(long longIndex, long value)
longIndex
- of long to ORvalue
- of long to ORDirectBitSet
backDirectBitSet xor(long longIndex, long value)
longIndex
- of long to XORvalue
- of long to XORDirectBitSet
backDirectBitSet andNot(long longIndex, long value)
DirectBitSet
whose corresponding bit is set in the specified
long value.longIndex
- of long to AND NOTvalue
- of long to AND NOTDirectBitSet
backlong setNextClearBit(long fromIndex)
true
the first bit that is set to false
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.fromIndex
- the index to start checking from (inclusive)-1
if there is no such bitIndexOutOfBoundsException
- if the specified index is negativenextClearBit(long)
long clearNextSetBit(long fromIndex)
true
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitIndexOutOfBoundsException
- if the specified index is negativenextSetBit(long)
long setPreviousClearBit(long fromIndex)
true
the nearest bit that is set
to false
that occurs on or before the specified starting index.
If no such bit exists, or if -1
is given as the
starting index, then -1
is returned.fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitIndexOutOfBoundsException
- if the specified index is less
than -1
previousClearBit(long)
long clearPreviousSetBit(long fromIndex)
true
that occurs on or before the specified starting index.
If no such bit exists, or if -1
is given as the
starting index, then -1
is returned.fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitIndexOutOfBoundsException
- if the specified index is less
than -1
previousSetBit(long)
long setNextNContinuousClearBits(long fromIndex, int numberOfBits)
numberOfBits
consecutive bits set to false
,
starting from the specified fromIndex
. Then all bits of the found
range are set to true
. The first index of the found block
is returned. If there is no such range of clear bits, -1
is returned.
fromIndex
could be the first index of the found range, thus
setNextNContinuousClearBits(i, 1)
is exact equivalent of
setNextClearBit(i)
.
fromIndex
- the index to start checking from (inclusive)numberOfBits
- how many continuous clear bits to search and set-1
if there is no such rangeIndexOutOfBoundsException
- if fromIndex
is negativeIllegalArgumentException
- if numberOfBits <= 0
long clearNextNContinuousSetBits(long fromIndex, int numberOfBits)
numberOfBits
consecutive bits set to true
,
starting from the specified fromIndex
. Then all bits of the found
range are set to false
. The first index of the found block
is returned. If there is no such range of true
bits, -1
is returned.
fromIndex
could be the first index of the found range, thus
clearNextNContinuousSetBits(i, 1)
is exact equivalent of
clearNextSetBit(i)
.
fromIndex
- the index to start checking from (inclusive)numberOfBits
- how many continuous set bits to search and cleartrue
bits, or -1
if there is no such rangeIndexOutOfBoundsException
- if fromIndex
is negativeIllegalArgumentException
- if numberOfBits <= 0
long setPreviousNContinuousClearBits(long fromIndex, int numberOfBits)
numberOfBits
consecutive bits
set to false
, starting from the specified fromIndex
.
Then all bits of the found range are set to true
.
The first index of the found block is returned. If there is no such
range of clear bits, or if -1
is given as the starting index,
-1
is returned.
fromIndex
could be the last index of the found range, thus
setPreviousNContinuousClearBits(i, 1)
is exact equivalent of
setPreviousClearBit(i)
.
fromIndex
- the index to start checking from (inclusive)numberOfBits
- how many continuous clear bits to search and set-1
if there is no such rangeIndexOutOfBoundsException
- if fromIndex
is less
than -1
IllegalArgumentException
- if numberOfBits <= 0
long clearPreviousNContinuousSetBits(long fromIndex, int numberOfBits)
numberOfBits
consecutive bits
set to true
, starting from the specified fromIndex
.
Then all bits of the found range are set to false
.
The first index of the found block is returned. If there is no such
range of true
bits, or if -1
is given as the starting
index, -1
is returned.
fromIndex
could be the last index of the found range, thus
clearPreviousNContinuousSetBits(i, 1)
is exact equivalent of
clearPreviousSetBit(i)
.
fromIndex
- the index to start checking from (inclusive)numberOfBits
- how many continuous set bits to search and cleartrue
bits, or -1
if there is no such rangeIndexOutOfBoundsException
- if fromIndex
is less
than -1
IllegalArgumentException
- if numberOfBits <= 0
DirectBitSet.Bits setBits()
Copyright © 2019. All rights reserved.