public class AntlrBitSet
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
protected long[] |
bits
The actual data bits
|
protected static int |
MOD_MASK
A precomputed mod mask.
|
Constructor and Description |
---|
AntlrBitSet()
Constructs a bitset of size one word (64 bits)
|
AntlrBitSet(byte[] bytes)
Constructor that converts and sets this bitset
|
AntlrBitSet(int nbits)
Constructs a bitset of given size
|
AntlrBitSet(long[] bits_)
Constructs a clone of the static array of longs
|
Modifier and Type | Method and Description |
---|---|
void |
add(int el)
Adds an element to this set using OR operator; set grows as necessary to accommodate
|
AntlrBitSet |
and(AntlrBitSet a)
Performs AND operation
|
void |
andInPlace(AntlrBitSet a)
Performs AND operation
|
void |
clear()
Clears all elements in this bitset
|
void |
clear(int el)
Clears the given element in this bitset
|
AntlrBitSet |
clone()
Creates and returns a copy of this antlrBitSet
|
int |
degree()
Returns the degree of this bitset
|
int |
degreeOfDifference(byte[] bytes)
Returns the number of bits that differ between the AntlrBitSet and the provided byte[] bitset
|
int |
degreeOfSimilarity(byte[] bytes)
Returns the number of bits that are the same between the antlrBitSet and the provided byte[] bitset
|
boolean |
equals(java.lang.Object obj)
Returns true if the
obj is a bit set that contains exactly the same elements as this bit set,
otherwise false. |
void |
growToInclude(int bit)
Grows the set to a larger number of bits
|
int |
hashCode()
Returns a hash code value for this bit set.
|
int |
lengthInLongWords()
Returns the amount of space being used by the bits array (not the number of member bits on)
|
boolean |
member(int el)
Provides whether the provided integer is a member of this bitset
|
boolean |
nil()
Returns whether this bitset is empty
|
AntlrBitSet |
not()
Provides the bitwise complement of this bitset
|
void |
notInPlace()
Performs a bitwise complement to invert the bits in this bitset
|
void |
notInPlace(int maxBit)
Performs a bitwise complement to invert the bits from zero to maxBit
|
void |
notInPlace(int minBit,
int maxBit)
Performs a bitwise complement to invert the bits from minBit to maxBit
|
static AntlrBitSet |
of(int el)
Creates a antlrBitSet with the given element
|
AntlrBitSet |
or(AntlrBitSet a)
Performs OR operation
|
void |
orInPlace(AntlrBitSet a)
Performs OR operation
|
void |
remove(int el)
Removes the given element from this set
|
int |
size()
Provides the size of this bit set
|
boolean |
subset(AntlrBitSet a)
Returns whether this bitset is contained within a
|
void |
subtractInPlace(AntlrBitSet a)
Subtracts the elements of the given antlrBitSet from this bitset in-place (turn off all bits of this bitset that
are in the given antlrBitSet)
|
int[] |
toArray()
Provides an array of integers
|
byte[] |
toBytes()
Converts this bitset to an array of bytes
|
java.lang.String |
toHex()
Converts this bitset to a hexadecimal string
|
long[] |
toPackedArray()
Creates and returns a copy of this antlrBitSet's bitset
|
java.lang.String |
toString()
Transform a bit set into a string separated by commas by formatting each element as an integer
|
java.lang.String |
toString(java.lang.String separator)
Transform a bit set into a string by formatting each element as an integer
|
java.lang.String |
toString(java.lang.String separator,
java.util.List<java.lang.String> vocabulary)
Creates a string representation where instead of integer elements, the ith element of a list of strings is
displayed
|
java.lang.String |
toStringOfHalfWords()
Dumps a comma-separated list of the words making up the bit set; Splits each 64 bit number into two more manageable
32 bit numbers; Generates a comma-separated list of C++-like unsigned long constants
|
java.lang.String |
toStringOfWords()
Provides a comma-separated list of Java-like long int constants that make up the bit set
|
void |
xorInPlace(AntlrBitSet a)
Performs XOR operation
|
protected static final int MOD_MASK
protected long[] bits
public AntlrBitSet()
public AntlrBitSet(long[] bits_)
bits_
- the static array of longspublic AntlrBitSet(int nbits)
nbits
- the int
size of the bitset in bitspublic AntlrBitSet(byte[] bytes)
bytes
- the array of bytes to convert and setpublic void add(int el)
el
- the int
element to addpublic AntlrBitSet and(AntlrBitSet a)
a
- the antlrBitSet to perform AND operation withpublic void andInPlace(AntlrBitSet a)
a
- the antlrBitSet to perform AND operation withpublic void clear()
public void clear(int el)
el
- the element to clearpublic AntlrBitSet clone()
clone
in class java.lang.Object
public int degree()
int
degreepublic boolean equals(java.lang.Object obj)
obj
is a bit set that contains exactly the same elements as this bit set,
otherwise false.
Code "inherited" from java.util.BitSetequals
in class java.lang.Object
obj
- the object to compare toboolean
whether obj equals this bit setpublic int hashCode()
bits
, in such a
manner that bit k
is set in the BitSet (for non-negative values of k
) if and only if
((k/64) < bits.length)
&& ((bits[k/64] & (1L << (bit % 64))) != 0)
Then the following definition of the hashCode method would be a correct implementation of the actual algorithm:
Code "inherited" from java.util.BitSethashCode
in class java.lang.Object
public void growToInclude(int bit)
bit
- the element that must fit in setpublic boolean member(int el)
el
- the int
value to checkboolean
whether the value is presentpublic boolean nil()
boolean
whether the bitset contains all zerospublic AntlrBitSet not()
public void notInPlace()
public void notInPlace(int maxBit)
maxBit
- the maximum bit to complementpublic void notInPlace(int minBit, int maxBit)
minBit
- the minumum bit to complementmaxBit
- the maximum bit to complementpublic static AntlrBitSet of(int el)
el
- the int
element to addpublic AntlrBitSet or(AntlrBitSet a)
a
- the antlrBitSet to perform OR operation withpublic void orInPlace(AntlrBitSet a)
a
- the antlrBitSet to perform OR operation withpublic void remove(int el)
el
- the int
element to removepublic int size()
int
size of the bit setpublic int lengthInLongWords()
public boolean subset(AntlrBitSet a)
a
- the antlrBitSet to checkboolean
whether this bitset is in the provided antlrBitSetpublic void subtractInPlace(AntlrBitSet a)
a
- the antlrBitSet to subtract the element frompublic int[] toArray()
public long[] toPackedArray()
long
array containing a clone of this bitsetpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String separator)
separator
- the string to put in between elementspublic java.lang.String toString(java.lang.String separator, java.util.List<java.lang.String> vocabulary)
separator
- the string to put in between elementsvocabulary
- the list of display elementspublic java.lang.String toStringOfHalfWords()
public java.lang.String toStringOfWords()
public java.lang.String toHex()
public byte[] toBytes()
public int degreeOfSimilarity(byte[] bytes)
bytes
- the array of bytes to compareint
number of different bits; returns 0 if the lengths of the two bitsets are differentpublic int degreeOfDifference(byte[] bytes)
bytes
- the array of bytes to compareint
number of different bits; returns 0 if the lengths of the two bitsets are differentpublic void xorInPlace(AntlrBitSet a)
a
- the antlrBitSet to perform XOR operation with