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.
Namespace: Algs4Net
public class SET<Key> : IEquatable<SET<Key>>, IEnumerable<Key>, IEnumerable where Key : Object, IComparable<Key>
The SETKey type exposes the following members.
Name | Description | |
---|---|---|
![]() | SETKey |
Initializes an empty set. |
![]() | SETKey(IEnumerableKey) |
Initializes a set with an initial list of items. |
![]() | SETKey(SETKey) |
Initializes a new set that is an independent copy of the specified set. |
Name | Description | |
---|---|---|
![]() | Count |
Returns the number of keys in this set. |
![]() | IsEmpty |
Returns true if this set is empty. |
![]() | Max |
Returns the largest key in this set. |
![]() | Min |
Returns the smallest key in this set. |
Name | Description | |
---|---|---|
![]() | Add |
Adds the key to this set (if it is not already present). |
![]() | Ceiling |
Returns the smallest key in this set greater than or equal to key. |
![]() | Contains |
Returns true if this set contains the given key. |
![]() | Delete |
Removes the specified key from this set (if the set contains the specified key). |
![]() | Equals(Object) |
Compares this set to the specified set. (Overrides ObjectEquals(Object).) |
![]() | Equals(SETKey) |
Compares this set to the other set using set element comparison. This is
an override of the default rererence equality comparison.
|
![]() | Floor |
Returns the largest key in this set less than or equal to key. |
![]() | GetEnumerator |
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). |
![]() | GetHashCode |
This operation is not supported because sets are mutable. (Overrides ObjectGetHashCode.) |
![]() | Intersects |
Returns the intersection of this set and that set. |
![]() ![]() | MainTest |
Demo test the SET data type. |
![]() | ToString |
Returns a string representation of this set. (Overrides ObjectToString.) |
![]() | Union |
Returns the union of this set and that set. |
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.