org.opencores.JLex
Class SparseBitSet

java.lang.Object
  |
  +--org.opencores.JLex.SparseBitSet

final class SparseBitSet
extends java.lang.Object
implements java.lang.Cloneable

A set of bits. The set automatically grows as more bits are needed.


Inner Class Summary
private static interface SparseBitSet.BinOp
           
 
Field Summary
private static SparseBitSet.BinOp AND
           
(package private)  long[] bits
          Array of bit-blocks; each holding BITS bits.
private static int BITS
          Number of bits in a block.
private static int BITS_M1
          BITS-1, using the identity: x % BITS == x & (BITS-1)
private static int LG_BITS
          log base 2 of BITS, for the identity: x/BITS == x >> LG_BITS
(package private)  int[] offs
          Sorted array of bit-block offsets.
private static SparseBitSet.BinOp OR
           
(package private)  int size
          Number of blocks currently in use.
private static SparseBitSet.BinOp XOR
           
 
Constructor Summary
SparseBitSet()
          Creates an empty set.
SparseBitSet(int nbits)
          Creates an empty set with the specified size.
SparseBitSet(SparseBitSet set)
          Creates an empty set with the same size as the given set.
 
Method Summary
 void and(SparseBitSet set)
          Logically ANDs this bit set with the specified set of bits.
private static void binop(SparseBitSet a, SparseBitSet b, SparseBitSet.BinOp op)
           
private  int bsearch(int bnum)
           
 void clear(int bit)
          Clears a bit.
 void clearAll()
          Clears all bits.
 java.lang.Object clone()
          Clones the SparseBitSet.
 java.util.Enumeration elements()
          Return an Enumeration of Integers which represent set bit indices in this SparseBitSet.
 boolean equals(java.lang.Object obj)
          Compares this object against the specified object.
static boolean equals(SparseBitSet a, SparseBitSet b)
          Compares two SparseBitSets for equality.
 boolean get(int bit)
          Gets a bit.
 int hashCode()
          Gets the hashcode.
private  void insert_block(int idx, int bnum)
           
private  boolean isValid()
          Check validity.
static void main(java.lang.String[] args)
          Self-test.
private  void new_block(int bnum)
           
private  void new_block(int idx, int bnum)
           
 void or(SparseBitSet set)
          Logically ORs this bit set with the specified set of bits.
 void set(int bit)
          Sets a bit.
 int size()
          Calculates and returns the set's size
 java.lang.String toString()
          Converts the SparseBitSet to a String.
 void xor(SparseBitSet set)
          Logically XORs this bit set with the specified set of bits.
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

offs

int[] offs
Sorted array of bit-block offsets.

bits

long[] bits
Array of bit-blocks; each holding BITS bits.

size

int size
Number of blocks currently in use.

LG_BITS

private static final int LG_BITS
log base 2 of BITS, for the identity: x/BITS == x >> LG_BITS

BITS

private static final int BITS
Number of bits in a block.

BITS_M1

private static final int BITS_M1
BITS-1, using the identity: x % BITS == x & (BITS-1)

AND

private static final SparseBitSet.BinOp AND

OR

private static final SparseBitSet.BinOp OR

XOR

private static final SparseBitSet.BinOp XOR
Constructor Detail

SparseBitSet

public SparseBitSet()
Creates an empty set.

SparseBitSet

public SparseBitSet(int nbits)
Creates an empty set with the specified size.
Parameters:
nbits - the size of the set

SparseBitSet

public SparseBitSet(SparseBitSet set)
Creates an empty set with the same size as the given set.
Method Detail

new_block

private void new_block(int bnum)

new_block

private void new_block(int idx,
                       int bnum)

insert_block

private void insert_block(int idx,
                          int bnum)

bsearch

private int bsearch(int bnum)

set

public void set(int bit)
Sets a bit.
Parameters:
bit - the bit to be set

clear

public void clear(int bit)
Clears a bit.
Parameters:
bit - the bit to be cleared

clearAll

public void clearAll()
Clears all bits.

get

public boolean get(int bit)
Gets a bit.
Parameters:
bit - the bit to be gotten

and

public void and(SparseBitSet set)
Logically ANDs this bit set with the specified set of bits.
Parameters:
set - the bit set to be ANDed with

or

public void or(SparseBitSet set)
Logically ORs this bit set with the specified set of bits.
Parameters:
set - the bit set to be ORed with

xor

public void xor(SparseBitSet set)
Logically XORs this bit set with the specified set of bits.
Parameters:
set - the bit set to be XORed with

binop

private static final void binop(SparseBitSet a,
                                SparseBitSet b,
                                SparseBitSet.BinOp op)

hashCode

public int hashCode()
Gets the hashcode.
Overrides:
hashCode in class java.lang.Object

size

public int size()
Calculates and returns the set's size

equals

public boolean equals(java.lang.Object obj)
Compares this object against the specified object.
Parameters:
obj - the object to commpare with
Returns:
true if the objects are the same; false otherwise.
Overrides:
equals in class java.lang.Object

equals

public static boolean equals(SparseBitSet a,
                             SparseBitSet b)
Compares two SparseBitSets for equality.
Returns:
true if the objects are the same; false otherwise.

clone

public java.lang.Object clone()
Clones the SparseBitSet.
Overrides:
clone in class java.lang.Object

elements

public java.util.Enumeration elements()
Return an Enumeration of Integers which represent set bit indices in this SparseBitSet.

toString

public java.lang.String toString()
Converts the SparseBitSet to a String.
Overrides:
toString in class java.lang.Object

isValid

private boolean isValid()
Check validity.

main

public static void main(java.lang.String[] args)
Self-test.