set: Set type
The Set class implements a set of objects. Any objects that can be used as Map keys can be added to a set. The Set class enforces the set constraint: any object may be included in a set at most a single time. An object can be added to a set even when the set already contains that object, but the operation will have no effect. The order of item additions and removals is not significant — a set object only records which objects are currently included in the set, but the objects have no specific order.
- class Set()
- Construct an empty set.
- class Set(iterable as Iterable<T>)
Construct and initialize a set. Iterate over the contents of the
argument, which must be an iterable object, and add them to the set.
Set([1, 3, "x"]) -- Set with items 1, 3 and "x"
- length() as Int
- Return the number of objects in the set.
- add(object as T)
- Add an object to the set. If the object is already in the set, this operation does nothing.
- remove(object as T)
- Remove an object from the set. Do nothing if the object is not included in the set.
- iterator() as Iterator<T>
- Return an iterator object that iterates over all the objects in the set in an arbitrary order.
- copy() as Set<T>
Return a copy of the set with the same items as the original set.
Note: Only item references are copied to the new set — the items itself are not duplicated.
Set objects support the following operations:
- x in set (Object in Set<T> ⇒ Boolean)
- Test whether a set contains a specific object.
- for x in set (for T in Set<T>)
- Set contents can be iterated with a for loop. The objects are iterated in an arbitrary order.
- set1 == set2 (Set<T> == Object)
- Compare sets for equality. Two sets are equal if they contain the same objects.
- Return a string representation of a set.
- Return the hash value of a set.