HashSet Reference
A HashSet is a collection of values that does not allow duplicate entries.
Constructor
Section titled “Constructor”Constructs the HashSet.
var set1 = HashSet();var set2 = HashSet([0, 1, 2]);Parameters
Section titled “Parameters”initial_values: [dyn!]? - The initial values to populate the hash set with.
Methods
Section titled “Methods”Adds a value to the has set.
var set = HashSet();set.add("value"); // trueParameters
Section titled “Parameters”value: dyn! - The value to add to the hash set.
Returns
Section titled “Returns”Boolean - Returns true if the value was added, false if already present.
delete
Section titled “delete”Renives a value to the has set.
var set = HashSet();set.add("value");set.remove("value") // trueParameters
Section titled “Parameters”value: dyn! - The value to remove from the hash set.
Returns
Section titled “Returns”Boolean - Returns true if the value was removed, false if it was not present.
difference
Section titled “difference”Removes the values of the provided set.
var set1 = HashSet([1, 2]);var set2 = HashSet([1]);var difference = set1.difference(set2).values().collect(); // [2]Parameters
Section titled “Parameters”value: HashSet - The set of values to remove.
Returns
Section titled “Returns”HashSet - The difference of the two hash sets.
Removes the values from the hash set.
var set = HashSet([0, 1, 2]);set.clear();var size = map.size(); // 0Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”nil
Returns true if the value is in the hash set, otherwise false.
var set = HashSet([0, 1, 2]);set.clear();set.has(0); // trueParameters
Section titled “Parameters”value: dyn?' - The value to search for.
Returns
Section titled “Returns”Boolean - true if the key is in the hash set, otherwise false.
intersection
Section titled “intersection”Returns a hash set of values that exist in both sets.
var set1 = HashSet([1, 2]);var set2 = HashSet([1]);var intersection = set1.intersection(set2).values().collect(); // [1]Parameters
Section titled “Parameters”value: HashSet - The set to check against.
Returns
Section titled “Returns”HashSet - A hash set of values that exist in both hash sets.
values
Section titled “values”Returns an iterator of the values in the hash set.
var set = HashSet([0, 1, 2]);set.values().for_each((value) -> { println(value);});// 0// 1// 2Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”Iterator - An iterator of values.
Returns a hash set of all values that exist in both sets.
var set1 = HashSet([1, 2]);var set2 = HashSet([1, 3]);var union = set1.union(set2).values().collect(); // [1, 2, 3]Parameters
Section titled “Parameters”value: HashSet - The set to add to the current set.
Returns
Section titled “Returns”HashSet - A hash set of all values in each hash set.