class Set<+T: Hashable & Equality>
A mutable, growable collection of unique items with O(1) insertion/ membership testing. Iteration order corresponds to the order in which items were first added to the Set.
Notes
Set is backed by a Map where the keys are the set entries and the values are dummy value.
Static Methods
Methods
NOTE: Making capacity observable on frozen values prevents optimizations such as shrinking to fit on freeze. By making it mutable we preserve option value to add such optimizations in the future.
Modifying Items
mutable fun sourceadd(v: T): VoidAdds the item to this set if is not present, otherwise throws.
Removes the item from this set:
- If the item is present removes it and return true
- Otherwise do nothing and returns false
Adds the item to the set if is not present, otherwise has no effect.
Inserts the item into this set:
- If not already present adds it and returns true
- If already present does nothing and returns false
Add all the items of the second sequence to this set. Ignores items already in this set.
Remove all the items of the second sequence from this set. Ignores items not in this set.
Set Arithmetic
readonly fun sourceunion<U: Hashable & Equality, S: readonly Sequence<U>>(items: S): Set<U>Returns a new set containing all the items of this set and the second sequence.
Returns a new set containing the items of this set that do not appear in the second sequence.
Return a new set containing the items of this set that appear in the second sequence.
Returns true if this set contains all of the items in the second sequence.
Returns true if this set contains any of the items in the second sequence.