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
sourceimpl<'s> OpBuilder<'s>
impl<'s> OpBuilder<'s>
sourcepub fn add<I, S>(self, streamable: I) -> Selfwhere
I: for<'a> IntoStreamer<'a, Into = S, Item = &'a [u8]>,
S: 's + for<'a> Streamer<'a, Item = &'a [u8]>,
pub fn add<I, S>(self, streamable: I) -> Selfwhere
I: for<'a> IntoStreamer<'a, Into = S, Item = &'a [u8]>,
S: 's + for<'a> Streamer<'a, Item = &'a [u8]>,
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.
sourcepub 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]>,
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]>,
Add a stream to this set operation.
The stream must emit a lexicographically ordered sequence of byte strings.
sourcepub fn union(self) -> Union<'s>
pub fn union(self) -> Union<'s>
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"]);
sourcepub fn intersection(self) -> Intersection<'s>
pub fn intersection(self) -> Intersection<'s>
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"]);
sourcepub fn difference(self) -> Difference<'s>
pub fn difference(self) -> Difference<'s>
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"]);
sourcepub fn symmetric_difference(self) -> SymmetricDifference<'s>
pub fn symmetric_difference(self) -> SymmetricDifference<'s>
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
sourceimpl<'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]>,
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]>,
sourcefn extend<T>(&mut self, it: T)where
T: IntoIterator<Item = I>,
fn extend<T>(&mut self, it: T)where
T: IntoIterator<Item = I>,
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)