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
See Also:
BitSet.flip(int)

flip

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

set

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

set

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

set

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

set

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

clear

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

clear

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

clear

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

get

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

get

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

nextSetBit

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

nextClearBit

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

length

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

isEmpty

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

intersects

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

cardinality

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

and

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

or

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

xor

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

andNot

public void andNot(java.util.BitSet set)
Overrides:
andNot in class java.util.BitSet
See Also:
BitSet.andNot(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

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
See Also:
BitSet.clone()

toString

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