Package components.map
Class Map4<K,V>
java.lang.Object
components.map.MapSecondary<K,V>
components.map.Map4<K,V>
- Type Parameters:
K- type ofMapdomain (key) entriesV- type ofMaprange (associated value) entries
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 components.map.MapSecondary
MapSecondary.SimplePair<K,V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds the pair (key,value) to this.final voidclear()Resetsthisto an initial value.final booleanReports whether there is a pair inthiswhose first component iskey.iterator()Returns a new object with the same dynamic type asthis, having an initial value.Removes the pair whose first component iskeyand returns it.Removes and returns an arbitrary pair fromthis.final VreplaceValue(K key, V value) Replaces the value associated withkeyinthiswithvalueand returns the old value.final intsize()Reports size ofthis.final voidtransferFrom(Map<K, V> source) Setsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis.final VReports the value associated withkeyinthis.Methods inherited from class components.map.MapSecondary
combineWith, equals, hashCode, hasValue, key, sharesKeyWith, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Map4
public Map4()No-argument constructor. -
Map4
Constructor resulting in a hash table of sizehashTableSize.- Parameters:
hashTableSize- size of hash table- Requires:
hashTableSize > 0- Ensures:
this = {}
-
-
Method Details
-
newInstance
Description copied from interface:StandardReturns a new object with the same dynamic type asthis, having an initial value. If the typeThas a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT. IfTdoes 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 initializethis.- Returns:
- new object "like"
thiswith an initial value
-
clear
Description copied from interface:StandardResetsthisto an initial value. If the typeThas a no-argument constructor, thenthissatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thenthissatisfies the contract of the constructor call that was used to initialize#this. -
transferFrom
Description copied from interface:StandardSetsthisto the incoming value ofsource, and resetssourceto an initial value; the declaration notwithstanding, the dynamic type ofsourcemust be the same as the dynamic type ofthis. If the typeThas a no-argument constructor, thensourcesatisfies the contract of the no-argument constructor forT. IfTdoes not have a no-argument constructor, thensourcesatisfies the contract of the constructor call that was used to initialize#source.- Parameters:
source- object whose value is to be transferred
-
add
Description copied from interface:MapKernelAdds the pair (key,value) to this.- Parameters:
key- the key to be addedvalue- the associated value to be added
-
remove
Description copied from interface:MapKernelRemoves the pair whose first component iskeyand returns it.- Parameters:
key- the key to be removed- Returns:
- the pair removed
-
removeAny
Description copied from interface:MapKernelRemoves and returns an arbitrary pair fromthis.- Returns:
- the pair removed from
this
-
value
Description copied from interface:MapKernelReports the value associated withkeyinthis.- Parameters:
key- the key whose associated value is to be reported- Returns:
- the value associated with key
-
hasKey
Description copied from interface:MapKernelReports whether there is a pair inthiswhose first component iskey.- Parameters:
key- the key to be checked- Returns:
- true iff there is a pair in this whose first component is
key
-
size
Description copied from interface:MapKernelReports size ofthis.- Returns:
- the number of pairs in
this
-
iterator
-
replaceValue
Description copied from interface:MapReplaces the value associated withkeyinthiswithvalueand returns the old value.- Specified by:
replaceValuein interfaceMap<K,V> - Overrides:
replaceValuein classMapSecondary<K,V> - Parameters:
key- the key whose associated value is replacedvalue- the value replacing the old one- Returns:
- the old value associated with the given key
-