Click or drag to resize
SETKey Class

The SET class represents an ordered set of comparable keys. It supports the usual Add, Contains, and Delete methods. It also provides ordered methods for finding the Minimum, Maximum, Floor, and Ceiling and set methods for Union, Intersection, and Equality.

Even though this implementation include the method Equals(), it does not support the method GetHashCode() because sets are mutable.

This implementation requires that the key type implements the Comparable interface and calls the CompareTo() and method to compare two keys. It does not call either Equals() or GetHashCode(). The Add, Contains, Delete, Minimum, Maximum, Ceiling, and Floor methods take logarithmic time in the worst case. The Count, and IsEmpty operations take constant time. Construction takes constant time.

Inheritance Hierarchy
SystemObject
  Algs4NetSETKey

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class SET<Key> : IEquatable<SET<Key>>, 
	IEnumerable<Key>, IEnumerable
where Key : Object, IComparable<Key>

Type Parameters

Key

The SETKey type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Returns the number of keys in this set.
Public propertyIsEmpty
Returns true if this set is empty.
Public propertyMax
Returns the largest key in this set.
Public propertyMin
Returns the smallest key in this set.
Top
Methods
  NameDescription
Public methodAdd
Adds the key to this set (if it is not already present).
Public methodCeiling
Returns the smallest key in this set greater than or equal to key.
Public methodContains
Returns true if this set contains the given key.
Public methodDelete
Removes the specified key from this set (if the set contains the specified key).
Public methodEquals(Object)
Compares this set to the specified set.
(Overrides ObjectEquals(Object).)
Public methodEquals(SETKey)
Compares this set to the other set using set element comparison. This is an override of the default rererence equality comparison.
Public methodFloor
Returns the largest key in this set less than or equal to key.
Public methodGetEnumerator
Returns all of the keys in this set, as an iterator. To iterate over all of the keys in a set named set, use the foreach notation: foreach (Key key in set).
Public methodGetHashCode
This operation is not supported because sets are mutable.
(Overrides ObjectGetHashCode.)
Public methodIntersects
Returns the intersection of this set and that set.
Public methodStatic memberMainTest
Demo test the SET data type.
Public methodToString
Returns a string representation of this set.
(Overrides ObjectToString.)
Public methodUnion
Returns the union of this set and that set.
Top
Remarks

For additional documentation, see Section 3.5 of Algorithms in Java, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class Bag implementation by Robert Sedgewick and Kevin Wayne.

See Also