# [−][src]Struct trie::set::Set

`pub struct Set { /* fields omitted */ }`

A set implemented as a radix trie.

# Examples

```let mut set = trie::Set::new();
set.insert(6);
set.insert(28);
set.insert(6);

assert_eq!(set.len(), 2);

if !set.contains(&3) {
println!("3 is not in the set");
}

// Print contents in order
for x in set.iter() {
println!("{}", x);
}

set.remove(&6);
assert_eq!(set.len(), 1);

set.clear();
assert!(set.is_empty());```

## Implementations

### `impl Set`[src]

#### `pub fn new() -> Set`[src]

Creates an empty set.

# Examples

`let mut set = trie::Set::new();`

#### `pub fn each_reverse<F>(&self, f: F) -> bool where    F: FnMut(&usize) -> bool, `[src]

Visits all values in reverse order. Aborts traversal when `f` returns `false`. Returns `true` if `f` returns `true` for all elements.

# Examples

```let set: trie::Set = [1, 2, 3, 4, 5].iter().cloned().collect();

let mut vec = vec![];
assert_eq!(true, set.each_reverse(|&x| { vec.push(x); true }));
assert_eq!(vec, [5, 4, 3, 2, 1]);

// Stop when we reach 3
let mut vec = vec![];
assert_eq!(false, set.each_reverse(|&x| { vec.push(x); x != 3 }));
assert_eq!(vec, [5, 4, 3]);```

#### `pub fn iter(&self) -> Iter`[src]

Gets an iterator over the values in the set, in sorted order.

# Examples

```let mut set = trie::Set::new();
set.insert(3);
set.insert(2);
set.insert(1);
set.insert(2);

// Print 1, 2, 3
for x in set.iter() {
println!("{}", x);
}```

#### `pub fn lower_bound(&self, val: usize) -> Range`[src]

Gets an iterator pointing to the first value that is not less than `val`. If all values in the set are less than `val` an empty iterator is returned.

# Examples

```let set: trie::Set = [2, 4, 6, 8].iter().cloned().collect();
assert_eq!(set.lower_bound(4).next(), Some(4));
assert_eq!(set.lower_bound(5).next(), Some(6));
assert_eq!(set.lower_bound(10).next(), None);```

#### `pub fn upper_bound(&self, val: usize) -> Range`[src]

Gets an iterator pointing to the first value that key is greater than `val`. If all values in the set are less than or equal to `val` an empty iterator is returned.

# Examples

```let set: trie::Set = [2, 4, 6, 8].iter().cloned().collect();
assert_eq!(set.upper_bound(4).next(), Some(6));
assert_eq!(set.upper_bound(5).next(), Some(6));
assert_eq!(set.upper_bound(10).next(), None);```

#### `pub fn difference<'a>(&'a self, other: &'a Set) -> Difference<'a>`[src]

Visits the values representing the difference, in ascending order.

# Examples

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [3, 4, 5].iter().cloned().collect();

// Can be seen as `a - b`.
for x in a.difference(&b) {
println!("{}", x); // Print 1 then 2
}

let diff1: trie::Set = a.difference(&b).collect();
assert_eq!(diff1, [1, 2].iter().cloned().collect());

// Note that difference is not symmetric,
// and `b - a` means something else:
let diff2: trie::Set = b.difference(&a).collect();
assert_eq!(diff2, [4, 5].iter().cloned().collect());```

#### `pub fn symmetric_difference<'a>(    &'a self,     other: &'a Set) -> SymmetricDifference<'a>`[src]

Visits the values representing the symmetric difference, in ascending order.

# Examples

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [3, 4, 5].iter().cloned().collect();

// Print 1, 2, 4, 5 in ascending order.
for x in a.symmetric_difference(&b) {
println!("{}", x);
}

let diff1: trie::Set = a.symmetric_difference(&b).collect();
let diff2: trie::Set = b.symmetric_difference(&a).collect();

assert_eq!(diff1, diff2);
assert_eq!(diff1, [1, 2, 4, 5].iter().cloned().collect());```

#### `pub fn intersection<'a>(&'a self, other: &'a Set) -> Intersection<'a>`[src]

Visits the values representing the intersection, in ascending order.

# Examples

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [2, 3, 4].iter().cloned().collect();

// Print 2, 3 in ascending order.
for x in a.intersection(&b) {
println!("{}", x);
}

let diff: trie::Set = a.intersection(&b).collect();
assert_eq!(diff, [2, 3].iter().cloned().collect());```

#### `pub fn union<'a>(&'a self, other: &'a Set) -> Union<'a>`[src]

Visits the values representing the union, in ascending order.

# Examples

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [3, 4, 5].iter().cloned().collect();

// Print 1, 2, 3, 4, 5 in ascending order.
for x in a.union(&b) {
println!("{}", x);
}

let diff: trie::Set = a.union(&b).collect();
assert_eq!(diff, [1, 2, 3, 4, 5].iter().cloned().collect());```

#### `pub fn len(&self) -> usize`[src]

Return the number of elements in the set

# Examples

```let mut v = trie::Set::new();
assert_eq!(v.len(), 0);
v.insert(1);
assert_eq!(v.len(), 1);```

#### `pub fn is_empty(&self) -> bool`[src]

Returns true if the set contains no elements

# Examples

```let mut v = trie::Set::new();
assert!(v.is_empty());
v.insert(1);
assert!(!v.is_empty());```

#### `pub fn clear(&mut self)`[src]

Clears the set, removing all values.

# Examples

```let mut v = trie::Set::new();
v.insert(1);
v.clear();
assert!(v.is_empty());```

#### `pub fn contains(&self, value: &usize) -> bool`[src]

Returns `true` if the set contains a value.

# Examples

```let set: trie::Set = [1, 2, 3].iter().cloned().collect();
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);```

#### `pub fn is_disjoint(&self, other: &Set) -> bool`[src]

Returns `true` if the set has no elements in common with `other`. This is equivalent to checking for an empty intersection.

# Examples

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let mut b = trie::Set::new();

assert_eq!(a.is_disjoint(&b), true);
b.insert(4);
assert_eq!(a.is_disjoint(&b), true);
b.insert(1);
assert_eq!(a.is_disjoint(&b), false);```

#### `pub fn is_subset(&self, other: &Set) -> bool`[src]

Returns `true` if the set is a subset of another.

# Examples

```let sup: trie::Set = [1, 2, 3].iter().cloned().collect();
let mut set = trie::Set::new();

assert_eq!(set.is_subset(&sup), true);
set.insert(2);
assert_eq!(set.is_subset(&sup), true);
set.insert(4);
assert_eq!(set.is_subset(&sup), false);```

#### `pub fn is_superset(&self, other: &Set) -> bool`[src]

Returns `true` if the set is a superset of another.

# Examples

```let sub: trie::Set = [1, 2].iter().cloned().collect();
let mut set = trie::Set::new();

assert_eq!(set.is_superset(&sub), false);

set.insert(0);
set.insert(1);
assert_eq!(set.is_superset(&sub), false);

set.insert(2);
assert_eq!(set.is_superset(&sub), true);```

#### `pub fn insert(&mut self, value: usize) -> bool`[src]

Adds a value to the set. Returns `true` if the value was not already present in the set.

# Examples

```let mut set = trie::Set::new();

assert_eq!(set.insert(2), true);
assert_eq!(set.insert(2), false);
assert_eq!(set.len(), 1);```

#### `pub fn remove(&mut self, value: &usize) -> bool`[src]

Removes a value from the set. Returns `true` if the value was present in the set.

# Examples

```let mut set = trie::Set::new();

set.insert(2);
assert_eq!(set.remove(&2), true);
assert_eq!(set.remove(&2), false);```

## Trait Implementations

### `impl<'a, 'b> BitAnd<&'b Set> for &'a Set`[src]

#### `type Output = Set`

The resulting type after applying the `&` operator.

#### `fn bitand(self, rhs: &Set) -> Set`[src]

Returns the intersection of `self` and `rhs` as a new set.

# Example

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [2, 3, 4].iter().cloned().collect();

let set: trie::Set = &a & &b;
let v: Vec<usize> = set.iter().collect();
assert_eq!(v, [2, 3]);```

### `impl<'a, 'b> BitOr<&'b Set> for &'a Set`[src]

#### `type Output = Set`

The resulting type after applying the `|` operator.

#### `fn bitor(self, rhs: &Set) -> Set`[src]

Returns the union of `self` and `rhs` as a new set.

# Example

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [3, 4, 5].iter().cloned().collect();

let set: trie::Set = &a | &b;
let v: Vec<usize> = set.iter().collect();
assert_eq!(v, [1, 2, 3, 4, 5]);```

### `impl<'a, 'b> BitXor<&'b Set> for &'a Set`[src]

#### `type Output = Set`

The resulting type after applying the `^` operator.

#### `fn bitxor(self, rhs: &Set) -> Set`[src]

Returns the symmetric difference of `self` and `rhs` as a new set.

# Example

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [3, 4, 5].iter().cloned().collect();

let set: trie::Set = &a ^ &b;
let v: Vec<usize> = set.iter().collect();
assert_eq!(v, [1, 2, 4, 5]);```

### `impl<'a> IntoIterator for &'a Set`[src]

#### `type Item = usize`

The type of the elements being iterated over.

#### `type IntoIter = Iter<'a>`

Which kind of iterator are we turning this into?

### `impl<'a, 'b> Sub<&'b Set> for &'a Set`[src]

#### `type Output = Set`

The resulting type after applying the `-` operator.

#### `fn sub(self, rhs: &Set) -> Set`[src]

Returns the difference of `self` and `rhs` as a new set.

# Example

```let a: trie::Set = [1, 2, 3].iter().cloned().collect();
let b: trie::Set = [3, 4, 5].iter().cloned().collect();

let set: trie::Set = &a - &b;
let v: Vec<usize> = set.iter().collect();
assert_eq!(v, [1, 2]);```

## Blanket Implementations

### `impl<T> ToOwned for T where    T: Clone, `[src]

#### `type Owned = T`

The resulting type after obtaining ownership.

### `impl<T, U> TryFrom<U> for T where    U: Into<T>, `[src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

### `impl<T, U> TryInto<U> for T where    U: TryFrom<T>, `[src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.