Class Array<D>

java.lang.Object
  extended by Array<D>
Type Parameters:
D - The type of the data stored in an array.
Direct Known Subclasses:
OArray

public class Array<D>
extends java.lang.Object

An array is more convenient class of the built-in arrays. It can be used with generic data of type D, and it is size adjusting.

Author:
Rossmanith

Constructor Summary
Array()
          Creates an empty array with default capacity.
Array(int s)
          Creates an empty array with capacity s.
 
Method Summary
 D get(int i)
          Gets the i-th element of this array (in constant time).
 boolean isempty()
          Checks whether this array is empty (constant time)
 SimpleIterator<D> iterator()
          Delivers an iterator over the objects stored in this array.
 void permute_randomly(java.util.Random r)
          Permutes this array randomly using the given random number generator r.
 void print()
          Prints this array to stdout.
 void resize(int s)
          Ensures that after this call this array can access all elements with index i ≤ s in constant time and sets the size to s.
 void set(int i, D d)
          Sets the i-th element of this array to d.
 int size()
          Returns the size of this array (constant time)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Array

public Array(int s)
Creates an empty array with capacity s.

Parameters:
s - The initial capacity of the array, must be non-negative.

Array

public Array()
Creates an empty array with default capacity.

Method Detail

size

public int size()
Returns the size of this array (constant time)


isempty

public boolean isempty()
Checks whether this array is empty (constant time)


resize

public void resize(int s)
Ensures that after this call this array can access all elements with index i ≤ s in constant time and sets the size to s.

Parameters:
s - Resize the array to have at least capacity s, if the current capacity is not high enough.

set

public void set(int i,
                D d)
Sets the i-th element of this array to d. (Constant time, if the capacity is high enough, or linear time, otherwise)

Parameters:
i - The index of element that should be returned, must be non-negative.
d - The datum that should be stored at the i-th position of this array.

get

public D get(int i)
Gets the i-th element of this array (in constant time).

Parameters:
i - The index of element that should be returned, must be non-negative.

permute_randomly

public void permute_randomly(java.util.Random r)
Permutes this array randomly using the given random number generator r.

Parameters:
r - The random number generator.

print

public void print()
Prints this array to stdout.


iterator

public SimpleIterator<D> iterator()
Delivers an iterator over the objects stored in this array.