Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

JLex
Class SparseBitSet  view SparseBitSet download SparseBitSet.java

java.lang.Object
  extended byJLex.SparseBitSet
All Implemented Interfaces:
java.lang.Cloneable

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

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

Version:
1.00, 25 Jul 1999

Nested 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, 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

See Also:
Constant Field Values

BITS

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

See Also:
Constant Field Values

BITS_M1

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

See Also:
Constant Field Values

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.


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.


clear

public void clear(int bit)
Clears a bit.


clearAll

public void clearAll()
Clears all bits.


get

public boolean get(int bit)
Gets a bit.


and

public void and(SparseBitSet set)
Logically ANDs this bit set with the specified set of bits.


or

public void or(SparseBitSet set)
Logically ORs this bit set with the specified set of bits.


xor

public void xor(SparseBitSet set)
Logically XORs this bit set with the specified set of bits.


binop

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

hashCode

public int hashCode()
Gets the hashcode.


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.


equals

public static boolean equals(SparseBitSet a,
                             SparseBitSet b)
Compares two SparseBitSets for equality.


clone

public java.lang.Object clone()
Clones the SparseBitSet.


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.


isValid

private boolean isValid()
Check validity.


main

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