Class Map4<K,V>

java.lang.Object
components.map.MapSecondary<K,V>
components.map.Map4<K,V>
Type Parameters:
K - type of Map domain (key) entries
V - type of Map range (associated value) entries
All Implemented Interfaces:
Map<K,V>, MapKernel<K,V>, Standard<Map<K,V>>, Iterable<Map.Pair<K,V>>

public class Map4<K,V> extends MapSecondary<K,V>
Map represented as a hash table using Maps for the buckets, with implementations of primary methods.
Representation Invariant (concrete invariant of $this):
|$this.hashTable| > 0  and
for all i: integer, pf: PARTIAL_FUNCTION, x: K
   where (0 <= i  and  i < |$this.hashTable|  and
          <pf> = $this.hashTable[i, i+1)  and
          x is in DOMAIN(pf))
 ([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, pf: PARTIAL_FUNCTION
   where (0 <= i  and  i < |$this.hashTable|  and
          <pf> = $this.hashTable[i, i+1))
 (|pf|)
Abstraction Relation (interpretation mapping between $this and this):
this = union i: integer, pf: PARTIAL_FUNCTION
          where (0 <= i  and  i < |$this.hashTable|  and
                 <pf> = $this.hashTable[i, i+1))
        (pf)
  • Nested Class Summary

    Nested classes/interfaces inherited from class MapSecondary

    MapSecondary.SimplePair<K,V>

    Nested classes/interfaces inherited from interface Map

    Map.Pair<K,V>
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    final void
    add(K key, V value)
    Adds the pair (key, value) to this.
    final void
    Resets this to an initial value.
    final boolean
    hasKey(K key)
    Reports whether there is a pair in this whose first component is key.
     
    final Map<K,V>
    Returns a new object with the same dynamic type as this, having an initial value.
    final Map.Pair<K,V>
    remove(K key)
    Removes the pair whose first component is key and returns it.
    final Map.Pair<K,V>
    Removes and returns an arbitrary pair from this.
    final V
    replaceValue(K key, V value)
    Replaces the value associated with key in this with value and returns the old value.
    final int
    Reports size of this.
    final void
    transferFrom(Map<K,V> 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.
    final V
    value(K key)
    Reports the value associated with key in this.

    Methods inherited from class Object

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

    Methods inherited from interface Iterable

    forEach, spliterator
  • Constructor Details

    • Map4

      public Map4()
      No-argument constructor.
    • Map4

      public Map4(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 Map<K,V> 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(Map<K,V> 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(K key, V value)
      Description copied from interface: MapKernel
      Adds the pair (key, value) to this.
      Parameters:
      key - the key to be added
      value - the associated value to be added
    • remove

      public final Map.Pair<K,V> remove(K key)
      Description copied from interface: MapKernel
      Removes the pair whose first component is key and returns it.
      Parameters:
      key - the key to be removed
      Returns:
      the pair removed
    • removeAny

      public final Map.Pair<K,V> removeAny()
      Description copied from interface: MapKernel
      Removes and returns an arbitrary pair from this.
      Returns:
      the pair removed from this
    • value

      public final V value(K key)
      Description copied from interface: MapKernel
      Reports the value associated with key in this.
      Parameters:
      key - the key whose associated value is to be reported
      Returns:
      the value associated with key
    • hasKey

      public final boolean hasKey(K key)
      Description copied from interface: MapKernel
      Reports whether there is a pair in this whose first component is key.
      Parameters:
      key - the key to be checked
      Returns:
      true iff there is a pair in this whose first component is key
    • size

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

      public final Iterator<Map.Pair<K,V>> iterator()
    • replaceValue

      public final V replaceValue(K key, V value)
      Description copied from interface: Map
      Replaces the value associated with key in this with value and returns the old value.
      Specified by:
      replaceValue in interface Map<K,V>
      Overrides:
      replaceValue in class MapSecondary<K,V>
      Parameters:
      key - the key whose associated value is replaced
      value - the value replacing the old one
      Returns:
      the old value associated with the given key