kodkod.util.ints
Interface IntSet

All Superinterfaces:
java.lang.Cloneable, IntCollection
All Known Implementing Classes:
AbstractIntSet, ArrayIntSet, IntBitSet, IntTreeSet

public interface IntSet
extends IntCollection, java.lang.Cloneable

An ordered set of integers.

Author:
Emina Torlak
specfield:
ints: set int

Method Summary
 boolean add(int i)
          Adds the given integer to this set if not already present and returns true.
 boolean addAll(IntCollection c)
          Adds all of the elements in the specified collection to this set if they're not already present.
 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.
 IntSet clone()
          Returns a copy of this IntSet.
 boolean contains(int i)
          Returns true if i is in this set.
 boolean containsAll(IntCollection c)
          Returns true if the elements of c are a subset of this set.
 boolean equals(java.lang.Object o)
          Compares the specified object with this set for equality.
 int floor(int i)
          Returns the largest element in this set that is smaller than or equal to i.
 int hashCode()
          Returns the hash code value for this set.
 boolean isEmpty()
          Returns true if this set has no elements; otherwise returns false.
 IntIterator iterator()
          Returns an iterator over the integers in this set, in the ascending element order.
 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.
 boolean removeAll(IntCollection c)
          Removes from this set all of its elements that are contained in the specified set.
 boolean retainAll(IntCollection c)
          Retains only the elements in this set that are contained in the specified set.
 int size()
          Returns the cardinality of this set.
 int[] toArray()
          Returns an array containing all of the elements in this set in the ascending order.
 int[] toArray(int[] array)
          Copies the elements of this set into the specified array, in the ascending order, provided that the array is large enough.
 

Method Detail

size

int size()
Returns the cardinality of this set.

Specified by:
size in interface IntCollection
Returns:
#this.ints

isEmpty

boolean isEmpty()
Returns true if this set has no elements; otherwise returns false.

Specified by:
isEmpty in interface IntCollection
Returns:
no this.ints

contains

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

Specified by:
contains in interface IntCollection
Returns:
i in this.ints

min

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

Returns:
min(this.ints)
Throws:
java.util.NoSuchElementException - - no this.ints

max

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

Returns:
max(this.ints)
Throws:
java.util.NoSuchElementException - - no this.ints

floor

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.

Returns:
{j: this.ints | j <= i && no k: this.ints - j | k > j && k <= i}
Throws:
java.util.NoSuchElementException - - no this.ints || i < this.min()

ceil

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.

Returns:
{j: this.ints | j >= i && no k: this.ints - j | k < j && k >= i}
Throws:
java.util.NoSuchElementException - - no this.ints || i > this.max()

iterator

IntIterator iterator()
Returns an iterator over the integers in this set, in the ascending element order.

Specified by:
iterator in interface IntCollection
Returns:
an IntIterator over the integers in this set.

iterator

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.

Returns:
an iterator over the elements in this set that are in the closed range [from..to].

add

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
Returns:
i in this.ints'
Throws:
java.lang.IllegalArgumentException - - this is a bounded set and i is out of bounds
effects:
this.ints' = this.ints + i

remove

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
Returns:
i !in this.ints'
effects:
this.ints' = this.ints - i

containsAll

boolean containsAll(IntCollection c)
Returns true if the elements of c are a subset of this set.

Specified by:
containsAll in interface IntCollection
Returns:
{ i: int | c.contains(i) } in this.ints
Throws:
java.lang.NullPointerException - - c = null

addAll

boolean addAll(IntCollection c)
Adds all of the elements in the specified collection to this set if they're not already present.

Specified by:
addAll in interface IntCollection
Returns:
this.ints' != this.ints
Throws:
java.lang.NullPointerException - - c = null
java.lang.UnsupportedOperationException - - this is an unmodifiable set
java.lang.IllegalArgumentException - - some aspect of an element of the specified collection prevents it from being added to this collection.
effects:
this.ints' = this.ints + { i: int | c.contains(i) }

removeAll

boolean removeAll(IntCollection c)
Removes from this set all of its elements that are contained in the specified set.

Specified by:
removeAll in interface IntCollection
Returns:
this.ints' != this.ints
Throws:
java.lang.NullPointerException - - s = null
java.lang.UnsupportedOperationException - - this is an unmodifiable set
effects:
this.ints' = this.ints - { i: int | c.contains(i) }

retainAll

boolean retainAll(IntCollection c)
Retains only the elements in this set that are contained in the specified set.

Specified by:
retainAll in interface IntCollection
Returns:
this.ints' != this.ints
Throws:
java.lang.NullPointerException - - s = null
java.lang.UnsupportedOperationException - - this is an unmodifiable set
effects:
this.ints' = this.ints & { i: int | c.contains(i) }

clear

void clear()
Removes all elements from this set.

Specified by:
clear in interface IntCollection
effects:
no this.ints'

clone

IntSet clone()
             throws java.lang.CloneNotSupportedException
Returns a copy of this IntSet. The copy is independent of this IntSet unless this is a singleton or an immutable set, in which case clone() may return this. An implementing class that does not support cloning may throw a CloneNotSupportedException.

Returns:
a copy of this IntSet.
Throws:
java.lang.CloneNotSupportedException - - this is not cloneable

toArray

int[] toArray()
Returns an array containing all of the elements in this set in the ascending order.

Specified by:
toArray in interface IntCollection
Returns:
an array containing all of the elements in this set in the ascending order.

toArray

int[] toArray(int[] array)
Copies the elements of this set into the specified array, in the ascending order, provided that the array is large enough. If the array is not large enough, the effect of this method is the same as calling toArray().

Specified by:
toArray in interface IntCollection
Returns:
array.length>=this.size() => array' else this.toArray()
Throws:
java.lang.NullPointerException - - array = null
effects:
array.length>=this.size() => all i: [0..this.size()) | array'[i] in this.ints and #{e: this.ints | e < array'[i]} = i

equals

boolean equals(java.lang.Object o)
Compares the specified object with this set for equality. Returns true if the specified object is also an IntSet, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the IntSet interface.

Overrides:
equals in class java.lang.Object
Returns:
o instanceof IntSet and o.size() = this.size() and this.containsAll(o)

hashCode

int hashCode()
Returns the hash code value for this set. The hash code of a set is defined to be the Ints.superFastHash(int[]) of the elements in the set, taken in the ascending order of values. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two IntSets s1 and s2, as required by the general contract of the Object.hashCode method.

Overrides:
hashCode in class java.lang.Object
Returns:
Ints.superFastHash(this.toArray())