Class Set<K>

java.lang.Object
  extended by Set<K>
Type Parameters:
K - The type of the elements in the set.

public class Set<K>
extends java.lang.Object

A set is like a Map without data, i.e. it is a collection of elements without duplicates. (Where Object.equals(Object) is used to compare elements). Internally, the keys of a Map are used to store the elements of the set. Note that it depends on the Map whether null is supported as element.

Author:
Rossmanith

Constructor Summary
Set()
          Creates a new empty set.
Set(Map<K,?> m)
          Creates a set where the elements are the keys of the given map.
 
Method Summary
 Array<K> array()
          Creates a new array which stores all elements of this set.
 void delete(K k)
          Deletes an element k from the set if it is present in the set.
 void insert(K k)
          Inserts an element k into the set.
 boolean iselement(K k)
          Checks whether the given element is in the set.
 SimpleIterator<K> iterator()
          Gives an iterator over all elements in the set.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Set

public Set()
Creates a new empty set. (Here a Hashtable is used to store the elements)


Set

public Set(Map<K,?> m)
Creates a set where the elements are the keys of the given map. Note that changes to this set will have impact on the map m and vice versa!

Parameters:
m - The map which defines this set.
Method Detail

insert

public void insert(K k)
Inserts an element k into the set.

Parameters:
k - The element to insert.

delete

public void delete(K k)
Deletes an element k from the set if it is present in the set.

Parameters:
k - The element to delete.

iselement

public boolean iselement(K k)
Checks whether the given element is in the set.

Parameters:
k - The element to check.
Returns:
true, if k is in the set, false, otherwise.

iterator

public SimpleIterator<K> iterator()
Gives an iterator over all elements in the set.


array

public Array<K> array()
Creates a new array which stores all elements of this set.

Returns:
An array containing exactly the elements of this set.