Class in collections::set coil-stdlib

HashSet

class HashSet<T>
Import
use collections::set::{HashSet};
Source: src/collections/set.hy

A set of unique values.

Values need Eq and Hash. Backed by a HashMap<T, bool>.

Associated functions#

NameDescription
with_capacityCreate a set with bucket count rounded up to the next power of two (min 8).
newEmpty set with default capacity 8.

Methods#

NameDescription
sizeNumber of elements.
is_emptyReturns true when the set has no values.
clearRemove all elements.
insertInsert x; returns true when newly added.
containsTrue when x is present.
removeRemove x; returns true when an element was removed.

Examples#

use collections::set::{HashSet};
use tests::assert;
let tags: HashSet<string> = HashSet::new();
assert!(tags.insert("red"));
assert!(!tags.insert("red"));
assert!(tags.contains("red"));
assert!(tags.size() == 1);

See also#

↑ ↓ navigate ↵ open