net.sf.molae.pipe.hash
Class SetBasedBitSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by net.sf.molae.pipe.hash.SetBasedBitSet<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
ListBasedBitSet

public class SetBasedBitSet<E>
extends AbstractSet<E>

A set based on a set and a bit set that determines which elements are contained in the set. If a lot of subsets of the same base sets are needed and each element in the base set has a unique hash code, subsets can be implemented using a bit map, where a bit is set if the element with the corresponding hash code is contained in the subset.


Constructor Summary
SetBasedBitSet(Collection<E> base)
          Constructs a SetBasedBitSet object.
 
Method Summary
 boolean add(E o)
          Ensures that this collection contains the specified element (optional operation).
 boolean addAll(Collection<? extends E> c)
          Adds all of the elements in the specified collection to this collection (optional operation).
 void clear()
          Removes all of the elements from this collection (optional operation).
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
          Returns true if this collection contains all of the elements in the specified collection.
protected  Collection<E> getBase()
          Returns the underlying base object.
protected  BigInteger getMask()
          Returns the underlying bit set.
 boolean isEmpty()
           
 Iterator<E> iterator()
          Returns an iterator over the elements contained in this collection.
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
          Removes from this collection all of its elements that are contained in the specified collection (optional operation).
 boolean retainAll(Collection<?> c)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
toArray, toArray
 

Constructor Detail

SetBasedBitSet

public SetBasedBitSet(Collection<E> base)
Constructs a SetBasedBitSet object.

Parameters:
base - the base set of which this set is a subset.
Method Detail

getBase

protected Collection<E> getBase()
Returns the underlying base object.

Returns:
the underlying base object

getMask

protected BigInteger getMask()
Returns the underlying bit set.

Returns:
the underlying bit set

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>
Specified by:
size in class AbstractCollection<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>
Overrides:
isEmpty in class AbstractCollection<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>
Overrides:
contains in class AbstractCollection<E>

iterator

public Iterator<E> iterator()
Returns an iterator over the elements contained in this collection. This implementation returns a set based iterator, that iterates over the entries of the base set, using the bitmap as a filter.

Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Specified by:
iterator in class AbstractCollection<E>
Returns:
an iterator over the elements contained in this collection.

add

public boolean add(E o)
Ensures that this collection contains the specified element (optional operation).

Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class AbstractCollection<E>
Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if the collection changed as a result of the call.
Throws:
IllegalArgumentException - if the specified element is not in the base set of this set.

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>
Overrides:
remove in class AbstractCollection<E>

containsAll

public boolean containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection. If the specified collection is an instanceof this class and has the same base as this class, the operation is directly performed on the bitmap, otherwise the default implementation of AbstractSet is used.

Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface Set<E>
Overrides:
containsAll in class AbstractCollection<E>
Parameters:
c - collection to be checked for containment in this collection.
Returns:
true if this collection contains all of the elements in the specified collection.

addAll

public boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection (optional operation). If the specified collection is an instanceof this class and has the same base as this class, the operation is directly performed on the bitmap, otherwise the default implementation of AbstractSet is used.

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface Set<E>
Overrides:
addAll in class AbstractCollection<E>
Parameters:
c - collection whose elements are to be added to this collection.
Returns:
true if this collection changed as a result of the call.

retainAll

public boolean retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). If the specified collection is an instanceof this class and has the same base as this class, the operation is directly performed on the bitmap, otherwise the default implementation of AbstractSet is used.

Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface Set<E>
Overrides:
retainAll in class AbstractCollection<E>
Parameters:
c - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call.

removeAll

public boolean removeAll(Collection<?> c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation). If the specified collection is an instanceof this class and has the same base as this class, the operation is directly performed on the bitmap, otherwise the default implementation of AbstractSet is used.

Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface Set<E>
Overrides:
removeAll in class AbstractSet<E>
Parameters:
c - elements to be removed from this collection.
Returns:
true if this collection changed as a result of the call.

clear

public void clear()
Removes all of the elements from this collection (optional operation).

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface Set<E>
Overrides:
clear in class AbstractCollection<E>