kodkod.util.ints
Class ArrayIntVector

java.lang.Object
  extended by kodkod.util.ints.AbstractIntCollection
      extended by kodkod.util.ints.AbstractIntVector
          extended by kodkod.util.ints.ArrayIntVector
All Implemented Interfaces:
IntCollection, IntVector

public final class ArrayIntVector
extends AbstractIntVector

A mutable implementation of the IntVector interface. Implements all optional IntVector operations. In addition to implementing the IntVector interface, this class provides methods to manipulate the size of the array that is used internally to store the elements of the IntVector.

The size, isEmpty, get, set, and iterator operations run in constant time. The insert operations run in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking).

Each MutableIntVector instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to a MutableIntVector, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.

An application can increase the capacity of an MutableIntVector instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.

This impementation is not synchronized and its iterators are not fail-fast.

Author:
Emina Torlak

Constructor Summary
ArrayIntVector()
          Constructs an empty MutableIntVector with an initial capacity of ten.
ArrayIntVector(int initialCapacity)
          Constructs an empty MutableIntVector with the specified initial capacity.
ArrayIntVector(int[] array)
          Constructs a MutableIntVector containing the elements of the specified array, in proper sequence.
 
Method Summary
 boolean add(int element)
          Calls this.add(this.size(), element)
 void add(int index, int element)
          Throws UnsupportedOperationException
 boolean addAll(int index, IntCollection c)
          Throws an UnsupportedOperationException.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this MutableIntVector instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 int get(int index)
          Returns the element at the specified position in this vector.
 int removeAt(int index)
          Throws an UnsupportedOperationException.
 int set(int index, int element)
          Throws UnsupportedOperationException.
 int size()
          Returns the number of elements in this collection.
 int[] toArray(int[] array)
          Copies the elements of this collection into the specified array, provided that it is large enough, and returns it. If the array is not large enough, the effect of this method is the same as calling IntCollection.toArray().
 void trimToSize()
          Trims the capacity of this MutableIntVector instance to be the list's current size.
 
Methods inherited from class kodkod.util.ints.AbstractIntVector
addAll, contains, equals, hashCode, indexOf, iterator, iterator, lastIndexOf, toString
 
Methods inherited from class kodkod.util.ints.AbstractIntCollection
clear, containsAll, isEmpty, remove, removeAll, retainAll, toArray
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface kodkod.util.ints.IntVector
clear, isEmpty, remove, removeAll, retainAll, toArray
 
Methods inherited from interface kodkod.util.ints.IntCollection
containsAll
 

Constructor Detail

ArrayIntVector

public ArrayIntVector(int initialCapacity)
Constructs an empty MutableIntVector with the specified initial capacity.

Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

ArrayIntVector

public ArrayIntVector()
Constructs an empty MutableIntVector with an initial capacity of ten.


ArrayIntVector

public ArrayIntVector(int[] array)
Constructs a MutableIntVector containing the elements of the specified array, in proper sequence. The MutableIntVector instance has an initial capacity of 110% the size of the specified collection.

Throws:
java.lang.NullPointerException - if the specified array is null.
Method Detail

trimToSize

public void trimToSize()
Trims the capacity of this MutableIntVector instance to be the list's current size. An application can use this operation to minimize the storage of an MutableIntVector instance.


ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this MutableIntVector instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.


get

public int get(int index)
Returns the element at the specified position in this vector.

Returns:
this.elements[index]
See Also:
IntVector.get(int)

size

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

Returns:
number of elements in this collection.
See Also:
IntVector.size()

set

public int set(int index,
               int element)
Throws UnsupportedOperationException.

Specified by:
set in interface IntVector
Overrides:
set in class AbstractIntVector
Returns:
this.elements[index]
See Also:
IntVector.set(int, int)

add

public boolean add(int element)
Calls this.add(this.size(), element)

Specified by:
add in interface IntCollection
Specified by:
add in interface IntVector
Overrides:
add in class AbstractIntVector
Returns:
true if this collection has changed as a result of the call
See Also:
IntVector.add(int)

add

public void add(int index,
                int element)
Throws UnsupportedOperationException

Specified by:
add in interface IntVector
Overrides:
add in class AbstractIntVector
See Also:
IntVector.add(int, int)

addAll

public boolean addAll(int index,
                      IntCollection c)
Throws an UnsupportedOperationException.

Specified by:
addAll in interface IntVector
Overrides:
addAll in class AbstractIntVector
Returns:
this.elements != this.elements
See Also:
IntVector.addAll(int, kodkod.util.ints.IntCollection)

removeAt

public int removeAt(int index)
Throws an UnsupportedOperationException.

Specified by:
removeAt in interface IntVector
Overrides:
removeAt in class AbstractIntVector
Returns:
this.elements[index]
See Also:
AbstractIntVector.removeAt(int)

toArray

public int[] toArray(int[] array)
Copies the elements of this collection into the specified array, provided that it is large enough, and returns it. If the array is not large enough, the effect of this method is the same as calling IntCollection.toArray().

Specified by:
toArray in interface IntCollection
Specified by:
toArray in interface IntVector
Overrides:
toArray in class AbstractIntCollection
Returns:
the given array, filled with the elements from this collection, if the it is large enough; otherwise a new array containing all of the elements in this collection.
See Also:
AbstractIntCollection.toArray(int[])