10: Sets
( \newcommand{\kernel}{\mathrm{null}\,}\)
Sets are helpful tools in a software application where, just as in mathematics, similar abstract objects are aggregated into collections. A mathematical set has a fairly simple interface and can be implemented in a surprising number of ways.
Set<item-type>
ADT
contains(test-item:item-type):Boolean
True if test-item is contained in the Set.
insert(new-item:item-type)
Adds new-item into the set.
remove(item:item-type)
Removes item from the set. If item wasn't in the set, this method does nothing.
remove(item-iter:List Iterator<item-type>)
Removes the item referred to by item-iter from the set.
get-begin():List Iterator<item-type>
Allows iteration over the elements in the Set.
get-end():List Iterator<item-type>
Also allows iteration over the elements in the Set.
union(other:Set<item-type>):Set<item-type>
Returns a set containing all elements in either this or the other set. Has a default implementation.
intersect(other:Set<item-type>):Set<item-type>
Returns a set containing all elements in both this and the other set. Has a default implementation.
subtract(other:Set<item-type>):Set<item-type>
Returns a set containing all elements in this but not the other set. Has a default implementation.
is-empty():Boolean
True if no more items can be popped and there is no top item.
get-size():Integer
Returns the number of elements in the set.
All operations can be performed in O(N) time.