Class Set4<T>
java.lang.Object
components.set.SetSecondary<T>
components.set.Set4<T>
- Type Parameters:
T- type ofSetelements
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 -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAddsxto this.final voidclear()Resetsthisto an initial value.final booleanReports whetherxis inthis.iterator()Returns a new object with the same dynamic type asthis, having an initial value.final TRemovesxfrom this, and returns it.final TRemoves and returns an arbitrary element fromthis.final intsize()Reports size (cardinality) ofthis.final voidtransferFrom(Set<T> 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.Methods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
Set4
public Set4()No-argument constructor, resulting in a hash table of default size. -
Set4
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
-
remove
-
removeAny
-
contains
-
size
-
iterator
-