javatools.datatypes
Class IntSet

java.lang.Object
  extended by javatools.datatypes.IntSet
All Implemented Interfaces:
java.lang.Iterable<java.lang.Integer>, java.util.Collection<java.lang.Integer>, java.util.Set<java.lang.Integer>
Direct Known Subclasses:
IdPriorityQueue

public class IntSet
extends java.lang.Object
implements java.util.Set<java.lang.Integer>

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class implements a space-efficient integer set. All operations are linear time, though...


Constructor Summary
IntSet()
          Creates a new IntSet
IntSet(java.util.BitSet copy)
          Creates a new IntSet by copying the given bit set
IntSet(int capacity)
          Creates a new IntSet with an initial capacity
IntSet(IntSet copy)
          Creates a new IntSet by copying the given set
 
Method Summary
 boolean add(int v)
          Adds the element
 boolean add(java.lang.Integer e)
          Adds the element
 boolean add(long i)
          Adds this element
 boolean add(java.lang.Number e)
          Adds this element
 boolean addAll(java.util.BitSet s)
          Adds all elements
 boolean addAll(java.util.Collection<? extends java.lang.Integer> c)
          Adds all elements
 boolean addAll(IntSet s)
          Adds all elements
 void addTo(java.util.BitSet s)
          Adds all elements of this set to s
 void clear()
          Removes all elements
 void clear(int capacity)
           
 boolean contains(int i)
          TRUE if the set contains i
 boolean contains(long i)
          TRUE if the set contains i
 boolean contains(java.lang.Object o)
          TRUE if the set contains o
 boolean containsAll(java.util.Collection<?> c)
          TRUE if the set contains all elements of c
 IntSet enhancedBy(int addMe)
          Adds addMe, returns THIS
 IntSet enhancedBy(IntSet addMe)
          Adds all elements, returns THIS
 boolean isEmpty()
          TRUE if the set is empty
 PeekIterator<java.lang.Integer> iterator()
           
static void main(java.lang.String[] args)
          Test method
static IntSet of(int... initial)
          Creates a new IntSet from initial values.
 int poll()
           
 boolean remove(int i)
          Removes one element, returns TRUE if the set was modified
 boolean remove(long i)
          Removes one element, returns TRUE if the set was modified
 boolean remove(java.lang.Object o)
          Removes one element (has to be a number), returns TRUE if the set was modified
 boolean removeAll(java.util.BitSet s)
          Removes all elements of s from this set
 boolean removeAll(java.util.Collection<?> c)
          Removes all elements in c
 boolean removeAll(IntSet c)
          Removes all elements in c
 boolean retainAll(java.util.Collection<?> c)
          Removes all elements that are not in c
 void setTo(IntSet copy)
          Overwrites the current IntSet with the given one
 IntSet shrunkBy(int addMe)
          Removes the given element, returns THIS
 IntSet shrunkBy(IntSet addMe)
          Removes the given elements, returns THIS
 int size()
           
 java.lang.Object[] toArray()
          Returns an array of the elements of this set
<T> T[]
toArray(T[] a)
          Not supported
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

IntSet

public IntSet(IntSet copy)
Creates a new IntSet by copying the given set


IntSet

public IntSet(java.util.BitSet copy)
Creates a new IntSet by copying the given bit set


IntSet

public IntSet()
Creates a new IntSet


IntSet

public IntSet(int capacity)
Creates a new IntSet with an initial capacity

Method Detail

iterator

public PeekIterator<java.lang.Integer> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.Integer>
Specified by:
iterator in interface java.util.Collection<java.lang.Integer>
Specified by:
iterator in interface java.util.Set<java.lang.Integer>

add

public boolean add(int v)
Adds the element


clear

public void clear(int capacity)

poll

public int poll()

of

public static IntSet of(int... initial)
Creates a new IntSet from initial values.


setTo

public void setTo(IntSet copy)
Overwrites the current IntSet with the given one


retainAll

public boolean retainAll(java.util.Collection<?> c)
Removes all elements that are not in c

Specified by:
retainAll in interface java.util.Collection<java.lang.Integer>
Specified by:
retainAll in interface java.util.Set<java.lang.Integer>

remove

public boolean remove(int i)
Removes one element, returns TRUE if the set was modified


remove

public boolean remove(long i)
Removes one element, returns TRUE if the set was modified


remove

public boolean remove(java.lang.Object o)
Removes one element (has to be a number), returns TRUE if the set was modified

Specified by:
remove in interface java.util.Collection<java.lang.Integer>
Specified by:
remove in interface java.util.Set<java.lang.Integer>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Removes all elements in c

Specified by:
removeAll in interface java.util.Collection<java.lang.Integer>
Specified by:
removeAll in interface java.util.Set<java.lang.Integer>

removeAll

public boolean removeAll(IntSet c)
Removes all elements in c


toArray

public java.lang.Object[] toArray()
Returns an array of the elements of this set

Specified by:
toArray in interface java.util.Collection<java.lang.Integer>
Specified by:
toArray in interface java.util.Set<java.lang.Integer>

toArray

public <T> T[] toArray(T[] a)
Not supported

Specified by:
toArray in interface java.util.Collection<java.lang.Integer>
Specified by:
toArray in interface java.util.Set<java.lang.Integer>

toString

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

size

public int size()
Specified by:
size in interface java.util.Collection<java.lang.Integer>
Specified by:
size in interface java.util.Set<java.lang.Integer>

add

public boolean add(long i)
Adds this element


add

public boolean add(java.lang.Number e)
Adds this element


addAll

public boolean addAll(java.util.Collection<? extends java.lang.Integer> c)
Adds all elements

Specified by:
addAll in interface java.util.Collection<java.lang.Integer>
Specified by:
addAll in interface java.util.Set<java.lang.Integer>

addAll

public boolean addAll(IntSet s)
Adds all elements


addAll

public boolean addAll(java.util.BitSet s)
Adds all elements


removeAll

public boolean removeAll(java.util.BitSet s)
Removes all elements of s from this set


addTo

public void addTo(java.util.BitSet s)
Adds all elements of this set to s


enhancedBy

public IntSet enhancedBy(IntSet addMe)
Adds all elements, returns THIS


enhancedBy

public IntSet enhancedBy(int addMe)
Adds addMe, returns THIS


shrunkBy

public IntSet shrunkBy(IntSet addMe)
Removes the given elements, returns THIS


shrunkBy

public IntSet shrunkBy(int addMe)
Removes the given element, returns THIS


contains

public boolean contains(int i)
TRUE if the set contains i


contains

public boolean contains(long i)
TRUE if the set contains i


contains

public boolean contains(java.lang.Object o)
TRUE if the set contains o

Specified by:
contains in interface java.util.Collection<java.lang.Integer>
Specified by:
contains in interface java.util.Set<java.lang.Integer>

containsAll

public boolean containsAll(java.util.Collection<?> c)
TRUE if the set contains all elements of c

Specified by:
containsAll in interface java.util.Collection<java.lang.Integer>
Specified by:
containsAll in interface java.util.Set<java.lang.Integer>

isEmpty

public boolean isEmpty()
TRUE if the set is empty

Specified by:
isEmpty in interface java.util.Collection<java.lang.Integer>
Specified by:
isEmpty in interface java.util.Set<java.lang.Integer>

clear

public void clear()
Removes all elements

Specified by:
clear in interface java.util.Collection<java.lang.Integer>
Specified by:
clear in interface java.util.Set<java.lang.Integer>

add

public boolean add(java.lang.Integer e)
Adds the element

Specified by:
add in interface java.util.Collection<java.lang.Integer>
Specified by:
add in interface java.util.Set<java.lang.Integer>

main

public static void main(java.lang.String[] args)
Test method