kodkod.util.ints
Class IntTreeSet

java.lang.Object
  extended by kodkod.util.ints.AbstractIntCollection
      extended by kodkod.util.ints.AbstractIntSet
          extended by kodkod.util.ints.IntTreeSet
All Implemented Interfaces:
java.lang.Cloneable, IntCollection, IntSet

public final class IntTreeSet
extends AbstractIntSet
implements java.lang.Cloneable

An implementation of the IntTreeSet interface based on a balanced binary search tree.

Author:
Emina Torlak
specfield:
ints: set int

Constructor Summary
IntTreeSet()
          Constructs an empty int set.
IntTreeSet(IntSet s)
          Constructs a new int set containing the elements in the specified set.
 
Method Summary
 boolean add(int i)
          Adds the given integer to this set if not already present and returns true.
 int ceil(int i)
          Returns the smallest element in this set that is greater than or equal to i.
 void clear()
          Removes all elements from this set.
 IntTreeSet clone()
          Returns a copy of this int tree set.
 boolean contains(int i)
          Returns true if i is in this set.
 boolean containsAll(IntCollection other)
          Returns true if this collection contains all of the elements in the specified collection.
 int floor(int i)
          Returns the largest element in this set that is smaller than or equal to i.
 IntIterator iterator(int from, int to)
          Returns an iterator over the elements of this set that are in the closed range [from..to].
 int max()
          Returns the largest element in this set.
 int min()
          Returns the smallest element in this set.
 boolean remove(int i)
          Removes the given integer from this set if already present and returns true.
 int size()
          Returns the number of elements in this collection.
 
Methods inherited from class kodkod.util.ints.AbstractIntSet
equals, hashCode, iterator, toString
 
Methods inherited from class kodkod.util.ints.AbstractIntCollection
addAll, isEmpty, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface kodkod.util.ints.IntSet
addAll, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

IntTreeSet

public IntTreeSet()
Constructs an empty int set.

effects:
no this.ints'

IntTreeSet

public IntTreeSet(IntSet s)
Constructs a new int set containing the elements in the specified set.

Throws:
java.lang.NullPointerException - - s = null
effects:
this.ints' = s.ints
Method Detail

iterator

public IntIterator iterator(int from,
                            int to)
Returns an iterator over the elements of this set that are in the closed range [from..to]. If from < to, the elements are returned in the ascending order. Otherwise, they are returned in the descending order.

Specified by:
iterator in interface IntSet
Returns:
an iterator over the elements in this set that are in the closed range [from..to].
See Also:
IntSet.iterator(int,int)

size

public int size()
Returns the number of elements in this collection.

Specified by:
size in interface IntCollection
Specified by:
size in interface IntSet
Returns:
number of elements in this collection.
See Also:
IntSet.size()

contains

public boolean contains(int i)
Returns true if i is in this set.

Specified by:
contains in interface IntCollection
Specified by:
contains in interface IntSet
Overrides:
contains in class AbstractIntCollection
Returns:
i in this.ints
See Also:
IntSet.contains(int)

min

public int min()
Returns the smallest element in this set. Throws a NoSuchElementException if this set is empty.

Specified by:
min in interface IntSet
Overrides:
min in class AbstractIntSet
Returns:
min(this.ints)
Throws:
java.util.NoSuchElementException - - no this.ints
See Also:
IntSet.min()

max

public int max()
Returns the largest element in this set. Throws a NoSuchElementException if this set is empty.

Specified by:
max in interface IntSet
Overrides:
max in class AbstractIntSet
Returns:
max(this.ints)
Throws:
java.util.NoSuchElementException - - no this.ints
See Also:
IntSet.max()

floor

public int floor(int i)
Returns the largest element in this set that is smaller than or equal to i. If this is emtpy or i is less than this.min(), NoSuchElementException is thrown.

Specified by:
floor in interface IntSet
Returns:
{j: this.ints | j <= i && no k: this.ints - j | k > j && k <= i}
See Also:
IntSet.floor(int)

ceil

public int ceil(int i)
Returns the smallest element in this set that is greater than or equal to i. If this is emtpy or i is greater than this.max(), NoSuchElementException is thrown.

Specified by:
ceil in interface IntSet
Returns:
{j: this.ints | j >= i && no k: this.ints - j | k < j && k >= i}
See Also:
IntSet.ceil(int)

add

public boolean add(int i)
Adds the given integer to this set if not already present and returns true. Otherwise does nothing and returns false.

Specified by:
add in interface IntCollection
Specified by:
add in interface IntSet
Overrides:
add in class AbstractIntCollection
Returns:
i in this.ints'
See Also:
IntSet.add(int)
effects:
this.ints' = this.ints + i

remove

public boolean remove(int i)
Removes the given integer from this set if already present and returns true. Otherwise does nothing and returns false.

Specified by:
remove in interface IntCollection
Specified by:
remove in interface IntSet
Overrides:
remove in class AbstractIntCollection
Returns:
i !in this.ints'
See Also:
IntSet.remove(int)
effects:
this.ints' = this.ints - i

containsAll

public boolean containsAll(IntCollection other)
Returns true if this collection contains all of the elements in the specified collection.

Specified by:
containsAll in interface IntCollection
Specified by:
containsAll in interface IntSet
Overrides:
containsAll in class AbstractIntCollection
Returns:
true if this collection contains all of the elements in the specified collection.
See Also:
IntSet.containsAll(kodkod.util.ints.IntCollection)

clear

public void clear()
Removes all elements from this set.

Specified by:
clear in interface IntCollection
Specified by:
clear in interface IntSet
Overrides:
clear in class AbstractIntCollection
See Also:
IntCollection.clear()
effects:
no this.ints'

clone

public IntTreeSet clone()
Returns a copy of this int tree set. The copy is independent of this IntSet.

Specified by:
clone in interface IntSet
Overrides:
clone in class AbstractIntSet
Returns:
a copy of this IntSet.
See Also:
IntSet.clone()