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

pub struct OpBuilder<'s>(_);
Expand description

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.

Implementations

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

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

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.