Struct fst::set::OpBuilder [] [src]

pub struct OpBuilder<'s>(_);

A builder for collecting set streams on which to perform set operations.

Set operations include intersection, union, difference and symmetric difference. The result of each set operation is itself a stream that emits keys in lexicographic order.

All set operations work efficiently on an arbitrary number of streams with memory proportional to the number of streams.

The algorithmic complexity of all set operations is O(n1 + n2 + n3 + ...) where n1, n2, n3, ... correspond to the number of elements in each stream.

The 's lifetime parameter refers to the lifetime of the underlying set.

Methods

impl<'s> OpBuilder<'s>
[src]

Create a new set operation builder.

Add a stream to this set operation.

This is useful for a chaining style pattern, e.g., builder.add(stream1).add(stream2).union().

The stream must emit a lexicographically ordered sequence of byte strings.

Add a stream to this set operation.

The stream must emit a lexicographically ordered sequence of byte strings.

Performs a union operation on all streams that have been added.

Example

use fst::{IntoStreamer, Streamer, Set};

let set1 = Set::from_iter(&["a", "b", "c"]).unwrap();
let set2 = Set::from_iter(&["a", "y", "z"]).unwrap();

let mut union = set1.op().add(&set2).union();

let mut keys = vec![];
while let Some(key) = union.next() {
    keys.push(key.to_vec());
}
assert_eq!(keys, vec![b"a", b"b", b"c", b"y", b"z"]);

Performs an intersection operation on all streams that have been added.

Example

use fst::{IntoStreamer, Streamer, Set};

let set1 = Set::from_iter(&["a", "b", "c"]).unwrap();
let set2 = Set::from_iter(&["a", "y", "z"]).unwrap();

let mut intersection = set1.op().add(&set2).intersection();

let mut keys = vec![];
while let Some(key) = intersection.next() {
    keys.push(key.to_vec());
}
assert_eq!(keys, vec![b"a"]);

Performs a difference operation with respect to the first stream added. That is, this returns a stream of all elements in the first stream that don't exist in any other stream that has been added.

Example

use fst::{IntoStreamer, Streamer, Set};

let set1 = Set::from_iter(&["a", "b", "c"]).unwrap();
let set2 = Set::from_iter(&["a", "y", "z"]).unwrap();

let mut difference = set1.op().add(&set2).difference();

let mut keys = vec![];
while let Some(key) = difference.next() {
    keys.push(key.to_vec());
}
assert_eq!(keys, vec![b"b", b"c"]);

Performs a symmetric difference operation on all of the streams that have been added.

When there are only two streams, then the keys returned correspond to keys that are in either stream but not in both streams.

More generally, for any number of streams, keys that occur in an odd number of streams are returned.

Example

use fst::{IntoStreamer, Streamer, Set};

let set1 = Set::from_iter(&["a", "b", "c"]).unwrap();
let set2 = Set::from_iter(&["a", "y", "z"]).unwrap();

let mut sym_difference = set1.op().add(&set2).symmetric_difference();

let mut keys = vec![];
while let Some(key) = sym_difference.next() {
    keys.push(key.to_vec());
}
assert_eq!(keys, vec![b"b", b"c", b"y", b"z"]);

Trait Implementations

impl<'f, I, S> Extend<I> for OpBuilder<'f> where
    I: for<'a> IntoStreamer<'a, Into = S, Item = &'a [u8]>,
    S: 'f + for<'a> Streamer<'a, Item = &'a [u8]>, 
[src]

Extends a collection with the contents of an iterator. Read more

impl<'f, I, S> FromIterator<I> for OpBuilder<'f> where
    I: for<'a> IntoStreamer<'a, Into = S, Item = &'a [u8]>,
    S: 'f + for<'a> Streamer<'a, Item = &'a [u8]>, 
[src]

Creates a value from an iterator. Read more