dk.netarkivet.common.utils
Class SparseBitSet

java.lang.Object
  extended by java.util.BitSet
      extended by dk.netarkivet.common.utils.SparseBitSet
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class SparseBitSet
extends java.util.BitSet

A sparse implementation of a BitSet, that does not require memory linear to the largest index. This is done at the cost of performance, but should be fairly efficient on few set bits.

See Also:
Serialized Form

Constructor Summary
SparseBitSet()
          Initialise the bitset.
 
Method Summary
 void and(java.util.BitSet set)
           
 void andNot(java.util.BitSet set)
           
 int cardinality()
           
 void clear()
           
 void clear(int bitIndex)
           
 void clear(int fromIndex, int toIndex)
           
 java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
          Two SparseBitSets are considered equal if they contain the same bits.
 void flip(int bitIndex)
           
 void flip(int fromIndex, int toIndex)
           
 boolean get(int bitIndex)
           
 java.util.BitSet get(int fromIndex, int toIndex)
           
 int hashCode()
          A hash code for this bit set.
 boolean intersects(java.util.BitSet set)
           
 boolean isEmpty()
           
 int length()
           
 int nextClearBit(int fromIndex)
           
 int nextSetBit(int fromIndex)
           
 void or(java.util.BitSet set)
           
 void set(int bitIndex)
           
 void set(int bitIndex, boolean value)
           
 void set(int fromIndex, int toIndex)
           
 void set(int fromIndex, int toIndex, boolean value)
           
 int size()
          In contrast with BitSet.size() this does not return the size in bytes used to represent this set.
 java.lang.String toString()
           
 void xor(java.util.BitSet set)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SparseBitSet

public SparseBitSet()
Initialise the bitset.

Method Detail

flip

public void flip(int bitIndex)
Overrides:
flip in class java.util.BitSet

flip

public void flip(int fromIndex,
                 int toIndex)
Overrides:
flip in class java.util.BitSet

set

public void set(int bitIndex)
Overrides:
set in class java.util.BitSet

set

public void set(int bitIndex,
                boolean value)
Overrides:
set in class java.util.BitSet

set

public void set(int fromIndex,
                int toIndex)
Overrides:
set in class java.util.BitSet

set

public void set(int fromIndex,
                int toIndex,
                boolean value)
Overrides:
set in class java.util.BitSet

clear

public void clear(int bitIndex)
Overrides:
clear in class java.util.BitSet

clear

public void clear(int fromIndex,
                  int toIndex)
Overrides:
clear in class java.util.BitSet

clear

public void clear()
Overrides:
clear in class java.util.BitSet

get

public boolean get(int bitIndex)
Overrides:
get in class java.util.BitSet

get

public java.util.BitSet get(int fromIndex,
                            int toIndex)
Overrides:
get in class java.util.BitSet

nextSetBit

public int nextSetBit(int fromIndex)
Overrides:
nextSetBit in class java.util.BitSet

nextClearBit

public int nextClearBit(int fromIndex)
Overrides:
nextClearBit in class java.util.BitSet

length

public int length()
Overrides:
length in class java.util.BitSet

isEmpty

public boolean isEmpty()
Overrides:
isEmpty in class java.util.BitSet

intersects

public boolean intersects(java.util.BitSet set)
Overrides:
intersects in class java.util.BitSet

cardinality

public int cardinality()
Overrides:
cardinality in class java.util.BitSet

and

public void and(java.util.BitSet set)
Overrides:
and in class java.util.BitSet

or

public void or(java.util.BitSet set)
Overrides:
or in class java.util.BitSet

xor

public void xor(java.util.BitSet set)
Overrides:
xor in class java.util.BitSet

andNot

public void andNot(java.util.BitSet set)
Overrides:
andNot in class java.util.BitSet

hashCode

public int hashCode()
A hash code for this bit set. Note: The hash codes are not implemented to be compatible with java.util.BitSet#hashCode(). Implementing that algorithm would be difficult and inefficient on the current implementation.

Overrides:
hashCode in class java.util.BitSet
Returns:
A hashcode.

size

public int size()
In contrast with BitSet.size() this does not return the size in bytes used to represent this set. Instead, it returns the same as length() for compatibility with BitSet. The actual space used is a hashset of size cardinality().

Overrides:
size in class java.util.BitSet
Returns:
the same as length()

equals

public boolean equals(java.lang.Object obj)
Two SparseBitSets are considered equal if they contain the same bits. Note: A SparseBitSet is never considered equal to a BitSet. This would be impossible to implement in a way so equality is symmetric, since BitSet.equals(Object) is implemented using its private fields to determine equality.

Overrides:
equals in class java.util.BitSet
Parameters:
obj - The object to compare for equality.
Returns:
true, if obj is a SparseBitSet and contains the same bits as this object.

clone

public java.lang.Object clone()
Overrides:
clone in class java.util.BitSet

toString

public java.lang.String toString()
Overrides:
toString in class java.util.BitSet