HashSet
class HashSet<T> Import
Source: use collections::set::{HashSet}; src/collections/set.hy A set of unique values.
Values need Eq and Hash. Backed by a HashMap<T, bool>.
Associated functions#
| Name | Description |
|---|---|
with_capacity | Create a set with bucket count rounded up to the next power of two (min 8). |
new | Empty set with default capacity 8. |
Methods#
| Name | Description |
|---|---|
size | Number of elements. |
is_empty | Returns true when the set has no values. |
clear | Remove all elements. |
insert | Insert x; returns true when newly added. |
contains | True when x is present. |
remove | Remove 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);