Package components.set
Class Set4<T>
java.lang.Object
components.set.SetSecondary<T>
components.set.Set4<T>
- Type Parameters:
T
- type ofSet
elements
Set
represented as a hash table using Set
s 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
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Addsx
to this.final void
clear()
Resetsthis
to an initial value.final boolean
Reports whetherx
is inthis
.iterator()
Returns a new object with the same dynamic type asthis
, having an initial value.final T
Removesx
from this, and returns it.final T
Removes and returns an arbitrary element fromthis
.final int
size()
Reports size (cardinality) ofthis
.final void
transferFrom
(Set<T> source) Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
.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
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:Standard
Returns a new object with the same dynamic type asthis
, having an initial value. If the typeT
has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT
. IfT
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 initializethis
.- Returns:
- new object "like"
this
with an initial value
-
clear
Description copied from interface:Standard
Resetsthis
to an initial value. If the typeT
has a no-argument constructor, thenthis
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thenthis
satisfies the contract of the constructor call that was used to initialize#this
. -
transferFrom
Description copied from interface:Standard
Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
. If the typeT
has a no-argument constructor, thensource
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thensource
satisfies 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:SetKernel
Addsx
to this.- Parameters:
x
- the element to be added
-
remove
Description copied from interface:SetKernel
Removesx
from this, and returns it.- Parameters:
x
- the element to be removed- Returns:
- the element removed
-
removeAny
Description copied from interface:SetKernel
Removes and returns an arbitrary element fromthis
.- Returns:
- the element removed from
this
-
contains
Description copied from interface:SetKernel
Reports whetherx
is inthis
.- Parameters:
x
- the element to be checked- Returns:
- true iff element is in
this
-
size
Description copied from interface:SetKernel
Reports size (cardinality) ofthis
.- Returns:
- the number of elements in
this
-
iterator
-