public class SingleThreadedDirectBitSet extends Object implements DirectBitSet
DirectBitSet.Bits
Modifier and Type | Field and Description |
---|---|
static long |
ALL_ONES |
NOT_FOUND
Constructor and Description |
---|
SingleThreadedDirectBitSet(Bytes bytes) |
Modifier and Type | Method and Description |
---|---|
boolean |
allClear(long fromIndex,
long exclusiveToIndex)
Checks if each bit from the specified
fromIndex (inclusive) to the specified exclusiveToIndex is set to false . |
boolean |
allSet(long fromIndex,
long exclusiveToIndex)
Checks if each bit from the specified
fromIndex (inclusive) to the specified exclusiveToIndex is set to true . |
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 exclusiveToIndex)
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 exclusiveToIndex)
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
DirectBitSet.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. |
int |
refCount() |
boolean |
release() |
void |
reserve() |
void |
reuse(Bytes bytes) |
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 exclusiveToIndex)
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.
|
String |
toString() |
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.
|
public static final long ALL_ONES
public SingleThreadedDirectBitSet(Bytes bytes)
public void reuse(Bytes bytes)
public void reserve()
reserve
in interface ReferenceCounted
public boolean release()
release
in interface ReferenceCounted
public int refCount()
refCount
in interface ReferenceCounted
public DirectBitSet flip(long bitIndex)
DirectBitSet
flip
in interface DirectBitSet
bitIndex
- the index of the bit to flipDirectBitSet
backpublic DirectBitSet flip(long fromIndex, long exclusiveToIndex)
DirectBitSet
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to the complement of its current
value.flip
in interface DirectBitSet
fromIndex
- index of the first bit to flipexclusiveToIndex
- index after the last bit to flipDirectBitSet
backpublic DirectBitSet set(long bitIndex)
DirectBitSet
true
.set
in interface DirectBitSet
bitIndex
- a bit indexDirectBitSet
backpublic boolean setIfClear(long bitIndex)
DirectBitSet
true
.setIfClear
in interface DirectBitSet
bitIndex
- a bit indexpublic DirectBitSet set(long bitIndex, boolean value)
DirectBitSet
set
in interface DirectBitSet
bitIndex
- a bit indexvalue
- a boolean value to setDirectBitSet
backpublic DirectBitSet set(long fromIndex, long exclusiveToIndex)
DirectBitSet
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to true
.set
in interface DirectBitSet
fromIndex
- index of the first bit to be setexclusiveToIndex
- index after the last bit to be setDirectBitSet
backpublic DirectBitSet setAll()
DirectBitSet
bs.setAll()
is equivalent
of bs.set(0, bs.size()
.setAll
in interface DirectBitSet
public DirectBitSet set(long fromIndex, long toIndex, boolean value)
DirectBitSet
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to the specified value.set
in interface DirectBitSet
fromIndex
- index of the first bit to be settoIndex
- index after the last bit to be setvalue
- value to set the selected bits toDirectBitSet
backpublic DirectBitSet clear(long bitIndex)
DirectBitSet
false
.clear
in interface DirectBitSet
bitIndex
- the index of the bit to be clearedDirectBitSet
backpublic boolean clearIfSet(long bitIndex)
DirectBitSet
false
).clearIfSet
in interface DirectBitSet
bitIndex
- a bit indexpublic DirectBitSet clear(long fromIndex, long exclusiveToIndex)
DirectBitSet
fromIndex
(inclusive) to the
specified toIndex
(exclusive) to false
.clear
in interface DirectBitSet
fromIndex
- index of the first bit to be clearedexclusiveToIndex
- index after the last bit to be clearedDirectBitSet
backpublic boolean allSet(long fromIndex, long exclusiveToIndex)
fromIndex
(inclusive) to the specified exclusiveToIndex
is set to true
.fromIndex
- index of the first bit to checkexclusiveToIndex
- index after the last bit to checktrue
if all bits in the specified range are set to true
, false
otherwiseIndexOutOfBoundsException
- if fromIndex
is negative, or fromIndex
is
larger than toIndex
, or exclusiveToIndex
is
larger or equal to size()
public boolean allClear(long fromIndex, long exclusiveToIndex)
fromIndex
(inclusive) to the specified exclusiveToIndex
is set to false
.fromIndex
- index of the first bit to checkexclusiveToIndex
- index after the last bit to checktrue
if all bits in the specified range are set to false
, false
otherwiseIndexOutOfBoundsException
- if fromIndex
is negative, or fromIndex
is
larger than toIndex
, or exclusiveToIndex
is
larger or equal to size()
public DirectBitSet clear()
DirectBitSet
false
.clear
in interface DirectBitSet
DirectBitSet
backpublic boolean get(long bitIndex)
DirectBitSet
true
if the bit with the index bitIndex
is currently set in this DirectBitSet
; otherwise, the result
is false
.get
in interface DirectBitSet
bitIndex
- the bit indexpublic boolean isSet(long bitIndex)
DirectBitSet
DirectBitSet.get(long)
.isSet
in interface DirectBitSet
bitIndex
- the bit indexpublic boolean isClear(long bitIndex)
DirectBitSet
!get(long)
.isClear
in interface DirectBitSet
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
public long getLong(long longIndex)
DirectBitSet
getLong
in interface DirectBitSet
longIndex
- the bit indexpublic long nextSetBit(long fromIndex)
DirectBitSet
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
}
nextSetBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitDirectBitSet.clearNextSetBit(long)
public DirectBitSet.Bits setBits()
DirectBitSet
setBits
in interface DirectBitSet
public long clearNextSetBit(long fromIndex)
DirectBitSet
true
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.clearNextSetBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitDirectBitSet.nextSetBit(long)
public long nextSetLong(long fromLongIndex)
DirectBitSet
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.nextSetLong
in interface DirectBitSet
fromLongIndex
- the index to start checking from (inclusive)-1
if there
is no such longpublic long nextClearBit(long fromIndex)
DirectBitSet
false
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.nextClearBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there is no such bitDirectBitSet.setNextClearBit(long)
public long setNextClearBit(long fromIndex)
DirectBitSet
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.setNextClearBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there is no such bitDirectBitSet.nextClearBit(long)
public long nextClearLong(long fromLongIndex)
DirectBitSet
false
that occurs on or after the specified starting index. If no such
bit exists then -1
is returned.nextClearLong
in interface DirectBitSet
fromLongIndex
- the index to start checking from (inclusive)-1
if there is no such longpublic long previousSetBit(long fromIndex)
DirectBitSet
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
}
previousSetBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitDirectBitSet.clearPreviousSetBit(long)
public long clearPreviousSetBit(long fromIndex)
DirectBitSet
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.clearPreviousSetBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitDirectBitSet.previousSetBit(long)
public long previousSetLong(long fromLongIndex)
DirectBitSet
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.previousSetLong
in interface DirectBitSet
fromLongIndex
- the index to start checking from (inclusive)-1
if there is no such longpublic long previousClearBit(long fromIndex)
DirectBitSet
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.previousClearBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitDirectBitSet.setPreviousClearBit(long)
public long setPreviousClearBit(long fromIndex)
DirectBitSet
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.setPreviousClearBit
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)-1
if there
is no such bitDirectBitSet.previousClearBit(long)
public long previousClearLong(long fromLongIndex)
DirectBitSet
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.previousClearLong
in interface DirectBitSet
fromLongIndex
- the index to start checking from (inclusive)-1
if there is no such longpublic long size()
DirectBitSet
size() - 1
.size
in interface DirectBitSet
public long cardinality()
DirectBitSet
true
in this DirectBitSet
.cardinality
in interface DirectBitSet
true
in this DirectBitSet
public DirectBitSet and(long longIndex, long value)
DirectBitSet
and
in interface DirectBitSet
longIndex
- of long to ANDvalue
- of long to ANDDirectBitSet
backpublic DirectBitSet or(long longIndex, long value)
DirectBitSet
or
in interface DirectBitSet
longIndex
- of long to ORvalue
- of long to ORDirectBitSet
backpublic DirectBitSet xor(long longIndex, long value)
DirectBitSet
xor
in interface DirectBitSet
longIndex
- of long to XORvalue
- of long to XORDirectBitSet
backpublic DirectBitSet andNot(long longIndex, long value)
DirectBitSet
DirectBitSet
whose corresponding bit is set in the specified
long value.andNot
in interface DirectBitSet
longIndex
- of long to AND NOTvalue
- of long to AND NOTDirectBitSet
backpublic long setNextNContinuousClearBits(long fromIndex, int numberOfBits)
DirectBitSet
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)
.
setNextNContinuousClearBits
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)numberOfBits
- how many continuous clear bits to search and set-1
if there is no such rangeIllegalArgumentException
- if numberOfBits
is negativepublic long clearNextNContinuousSetBits(long fromIndex, int numberOfBits)
DirectBitSet
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)
.
clearNextNContinuousSetBits
in interface DirectBitSet
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 rangeIllegalArgumentException
- if numberOfBits
is out of range 0 <
numberOfBits && numberOfBits <= 64
public long setPreviousNContinuousClearBits(long fromIndex, int numberOfBits)
DirectBitSet
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)
.
setPreviousNContinuousClearBits
in interface DirectBitSet
fromIndex
- the index to start checking from (inclusive)numberOfBits
- how many continuous clear bits to search and set-1
if there is no such rangeIllegalArgumentException
- if numberOfBits
is out of range 0 <
numberOfBits && numberOfBits <= 64
public long clearPreviousNContinuousSetBits(long fromIndex, int numberOfBits)
DirectBitSet
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)
.
clearPreviousNContinuousSetBits
in interface DirectBitSet
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 rangeIllegalArgumentException
- if numberOfBits
is out of range 0 <
numberOfBits && numberOfBits <= 64
Copyright © 2019. All rights reserved.