Skip to content

HashSet Reference

A HashSet is a collection of values that does not allow duplicate entries.

Constructs the HashSet.

var set1 = HashSet();
var set2 = HashSet([0, 1, 2]);

initial_values: [dyn!]? - The initial values to populate the hash set with.

Adds a value to the has set.

var set = HashSet();
set.add("value"); // true

value: dyn! - The value to add to the hash set.

Boolean - Returns true if the value was added, false if already present.

Renives a value to the has set.

var set = HashSet();
set.add("value");
set.remove("value") // true

value: dyn! - The value to remove from the hash set.

Boolean - Returns true if the value was removed, false if it was not present.

Removes the values of the provided set.

var set1 = HashSet([1, 2]);
var set2 = HashSet([1]);
var difference = set1.difference(set2).values().collect(); // [2]

value: HashSet - The set of values to remove.

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(); // 0

None

nil

Returns true if the value is in the hash set, otherwise false.

var set = HashSet([0, 1, 2]);
set.clear();
set.has(0); // true

value: dyn?' - The value to search for.

Boolean - true if the key is in the hash set, otherwise false.

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]

value: HashSet - The set to check against.

HashSet - A hash set of values that exist in both hash sets.

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
// 2

None

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]

value: HashSet - The set to add to the current set.

HashSet - A hash set of all values in each hash set.