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

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]

pub fn new() -> OpBuilder<'s>[src]

Create a new set operation builder.

pub fn add<I, S>(self, streamable: I) -> OpBuilder<'s> where
    I: for<'a> IntoStreamer<'a, Into = S, Item = &'a [u8]>,
    S: 's + for<'a> Streamer<'a, Item = &'a [u8]>, 
[src]

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.

pub fn push<I, S>(&mut self, streamable: I) where
    I: for<'a> IntoStreamer<'a, Into = S, Item = &'a [u8]>,
    S: 's + for<'a> Streamer<'a, Item = &'a [u8]>, 
[src]

Add a stream to this set operation.

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

pub fn union(self) -> Union<'s>[src]

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"]);

pub fn intersection(self) -> Intersection<'s>[src]

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"]);

pub fn difference(self) -> Difference<'s>[src]

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"]);

pub fn symmetric_difference(self) -> SymmetricDifference<'s>[src]

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]

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]

Auto Trait Implementations

impl<'s> !RefUnwindSafe for OpBuilder<'s>

impl<'s> !Send for OpBuilder<'s>

impl<'s> !Sync for OpBuilder<'s>

impl<'s> Unpin for OpBuilder<'s>

impl<'s> !UnwindSafe for OpBuilder<'s>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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.