Class Set4<T>

Type Parameters:
T - type of Set elements
All Implemented Interfaces:
Set<T>, SetKernel<T>, Standard<Set<T>>, Iterable<T>

public class Set4<T> extends SetSecondary<T>
Set represented as a hash table using Sets for the buckets, with implementations of primary methods.
Representation Invariant (concrete invariant of $this):
|$this.hashTable| > 0  and
for all i: integer, s: finite set of T, x: T
    where (0 <= i  and  i < |$this.hashTable|  and
           <s> = $this.hashTable[i, i+1)  and
           x is in s)
  ([computed result of x.hashCode()] mod |$this.hashTable| = i)  and
for all i: integer
    where (0 <= i  and  i < |$this.hashTable|)
  ([entry at position i in $this.hashTable is not null])  and
$this.size = sum i: integer, s: finite set of T
    where (0 <= i  and  i < |$this.hashTable|  and
           <s> = $this.hashTable[i, i+1))
  (|s|)
Abstraction Relation (interpretation mapping between $this and this):
this = union i: integer, s: finite set of T
           where (0 <= i  and  i < |$this.hashTable|  and
                  <s> = $this.hashTable[i, i+1))
         (s)
  • Constructor Summary

    Constructors
    Constructor
    Description
    No-argument constructor, resulting in a hash table of default size.
    Set4(int hashTableSize)
    Constructor resulting in a hash table of size hashTableSize.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    add(T x)
    Adds x to this.
    final void
    Resets this to an initial value.
    final boolean
    Reports whether x is in this.
    final Iterator<T>
     
    final Set<T>
    Returns a new object with the same dynamic type as this, having an initial value.
    final T
    remove(T x)
    Removes x from this, and returns it.
    final T
    Removes and returns an arbitrary element from this.
    final int
    Reports size (cardinality) of this.
    final void
    transferFrom(Set<T> source)
    Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this.

    Methods inherited from class components.set.SetSecondary

    add, equals, hashCode, isSubset, remove, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • Set4

      public Set4()
      No-argument constructor, resulting in a hash table of default size.
    • Set4

      public Set4(int hashTableSize)
      Constructor resulting in a hash table of size hashTableSize.
      Parameters:
      hashTableSize - size of hash table
      Requires:
      hashTableSize > 0
      Ensures:
      this = {}
  • Method Details

    • newInstance

      public final Set<T> newInstance()
      Description copied from interface: Standard
      Returns a new object with the same dynamic type as this, having an initial value. If the type T has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initialize this .
      Returns:
      new object "like" this with an initial value
    • clear

      public final void clear()
      Description copied from interface: Standard
      Resets this to an initial value. If the type T has a no-argument constructor, then this satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then this satisfies the contract of the constructor call that was used to initialize #this.
    • transferFrom

      public final void transferFrom(Set<T> source)
      Description copied from interface: Standard
      Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this. If the type T has a no-argument constructor, then source satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then source satisfies the contract of the constructor call that was used to initialize #source.
      Parameters:
      source - object whose value is to be transferred
    • add

      public final void add(T x)
      Description copied from interface: SetKernel
      Adds x to this.
      Parameters:
      x - the element to be added
    • remove

      public final T remove(T x)
      Description copied from interface: SetKernel
      Removes x from this, and returns it.
      Parameters:
      x - the element to be removed
      Returns:
      the element removed
    • removeAny

      public final T removeAny()
      Description copied from interface: SetKernel
      Removes and returns an arbitrary element from this.
      Returns:
      the element removed from this
    • contains

      public final boolean contains(T x)
      Description copied from interface: SetKernel
      Reports whether x is in this.
      Parameters:
      x - the element to be checked
      Returns:
      true iff element is in this
    • size

      public final int size()
      Description copied from interface: SetKernel
      Reports size (cardinality) of this.
      Returns:
      the number of elements in this
    • iterator

      public final Iterator<T> iterator()