public class OpenBitSet extends java.lang.Object implements IBitSet
An "open" BitSet implementation that allows direct access to the arrays of words storing the bits. Derived from Lucene's OpenBitSet, but with a paged backing array (see bits delaration, below).
Unlike java.util.bitset, the fact that bits are packed into an array of longs is part of the interface. This allows efficient implementation of other algorithms by someone other than the author. It also allows one to efficiently implement alternate serialization or interchange formats.
OpenBitSet
is faster than java.util.BitSet
in most operations
and *much* faster at calculating cardinality of sets and results of set operations.
It can also handle sets of larger cardinality (up to 64 * 2**32-1)
The goals of OpenBitSet
are the fastest implementation possible, and
maximum code reuse. Extra safety and encapsulation
may always be built on top, but if that's built in, the cost can never be removed (and
hence people re-implement their own version in order to get better performance).
If you want a "safe", totally encapsulated (and slower and limited) BitSet
class, use java.util.BitSet
.
Constructor and Description |
---|
OpenBitSet() |
OpenBitSet(long numBits)
Constructs an OpenBitSet large enough to hold numBits.
|
Modifier and Type | Method and Description |
---|---|
void |
addTo(Ref.IdentityCollection identities) |
void |
and(OpenBitSet other) |
static long |
bits2words(long numBits)
returns the number of 64 bit words it would take to hold numBits
|
long |
capacity()
Returns the current capacity in bits (1 greater than the index of the last bit)
|
long |
cardinality() |
void |
clear() |
void |
clear(int index)
clears a bit.
|
void |
clear(int startIndex,
int endIndex)
Clears a range of bits.
|
void |
clear(long index)
clears a bit.
|
void |
clear(long startIndex,
long endIndex)
Clears a range of bits.
|
void |
close() |
static OpenBitSet |
deserialize(java.io.DataInput in) |
boolean |
equals(java.lang.Object o)
returns true if both sets have the same bits set
|
boolean |
get(int index)
Returns true or false for the specified bit index.
|
boolean |
get(long index)
Returns true or false for the specified bit index.
|
int |
getNumWords()
Expert: gets the number of longs in the array that are in use
|
long[] |
getPage(int pageIdx) |
int |
getPageCount() |
int |
getPageSize() |
int |
hashCode() |
void |
intersect(OpenBitSet other)
this = this AND other
|
boolean |
isEmpty()
Returns true if there are no set bits
|
long |
length() |
long |
offHeapSize()
Returns the amount of memory in bytes used off heap.
|
void |
serialize(java.io.DataOutput out) |
long |
serializedSize() |
void |
set(int index)
Sets the bit at the specified index.
|
void |
set(long index)
Sets the bit at the specified index.
|
long |
size()
Returns the current capacity of this set.
|
void |
trimTrailingZeros()
Lowers numWords, the number of words in use,
by checking for trailing zero words.
|
public OpenBitSet(long numBits)
numBits
- public OpenBitSet()
public int getPageSize()
public int getPageCount()
public long[] getPage(int pageIdx)
public long capacity()
public long offHeapSize()
IBitSet
offHeapSize
in interface IBitSet
public void addTo(Ref.IdentityCollection identities)
public long size()
cardinality()
public long length()
public boolean isEmpty()
public int getNumWords()
public boolean get(int index)
public boolean get(long index)
public void set(long index)
public void set(int index)
public void clear(int index)
public void clear(long index)
public void clear(int startIndex, int endIndex)
startIndex
- lower indexendIndex
- one-past the last bit to clearpublic void clear(long startIndex, long endIndex)
startIndex
- lower indexendIndex
- one-past the last bit to clearpublic long cardinality()
public void intersect(OpenBitSet other)
public void and(OpenBitSet other)
public void trimTrailingZeros()
public static long bits2words(long numBits)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void close()
public void serialize(java.io.DataOutput out) throws java.io.IOException
public long serializedSize()
serializedSize
in interface IBitSet
public static OpenBitSet deserialize(java.io.DataInput in) throws java.io.IOException
java.io.IOException
Copyright © 2016 The Apache Software Foundation