HashSet
class in package klyn.collections

    public class HashSet<T> extends Object implements Set<T>:

Object
└ HashSet
All Implemented Interfaces: Set

Hash set implementation.

Unordered collection of unique elements with average O(1) add/contains/remove. Internally backed by a HashMap<T, Boolean>.

Example:

    s = HashSet<String>()
    s.add("red")
    s.add("blue")
    s.add("red")     # duplicate, size stays 2
    assert "blue" in s
    assert s.count("red") == 1
    s.remove("red")

Properties

Modifier and Type | Member | Description
--- | --- | ---
public readonly native property | size `size as ULong` | Number of elements in the set.

Inherited Properties
property Inherited Properties from Object: type
Constructors

Modifier and Type | Member | Description
--- | --- | ---
public | HashSet `HashSet():` | Creates an empty hash set.
public | HashSet `HashSet(collection as Collection<T>):` | Creates a hash set from a collection.
public | HashSet `HashSet(list as IList<T>):` | Creates a hash set from a read-only list.
public | HashSet `HashSet(source as HashSet<T>):` | Creates a hash set from another hash set.
public | HashSet `HashSet(source as HashSetSync<T>):` | Creates a hash set from a synchronized hash set.

Methods

Modifier and Type | Member | Description
--- | --- | ---
public native | _items `_items() as ArrayList<T>` | No summary.
public native | add `add(item as T) as Void` | Adds an element to the set.
public native | clear `clear() as Void` | Clears all elements.
public native | count `count(item as T) as ULong` | Counts occurrences of the given element in the set.
public | difference `difference(other as HashSet<T>) as HashSet<T>:` | Returns a new set containing elements from this set that are absent from `other`.
public | intersection `intersection(other as HashSet<T>) as HashSet<T>:` | Returns a new set containing elements present in both sets.
public | isSubsetOf `isSubsetOf(other as HashSet<T>) as Boolean:` | Returns true when every element of this set is present in `other`.
public | isSupersetOf `isSupersetOf(other as HashSet<T>) as Boolean:` | Returns true when this set contains every element of `other`.
public native | remove `remove(item as T) as Boolean` | Removes an element from the set.
public | symmetricDifference `symmetricDifference(other as HashSet<T>) as HashSet<T>:` | Returns a new set containing elements present in exactly one of the two sets.
public native | toString `toString() as String` | Returns a string representation of the set.
public | union `union(other as HashSet<T>) as HashSet<T>:` | Returns a new set containing all elements from this set and `other`.

Inherited Methods
method Inherited Methods from Object: deepCopy, fromJson, toDict, toJson, toXml
method Inherited Methods from Set: count
method Inherited Methods from Collection: add, remove, toString
Operators

Modifier and Type | Member | Description
--- | --- | ---
public native | operator in(item as T) as Boolean | Returns true if the set contains the element.

Inherited Operators
operator Inherited Operators from Set: operator in(item as T) as Boolean