Struct mtbl::Sorter
[−]
[src]
pub struct Sorter { pub options: SorterOptions, pub merge_fn: Box<Box<MergeFn>>, // some fields omitted }
A tool to create an MTBL file out of keys in any order.
A Sorter will buffer entries in memory, periodically writing them to (sorted) temporary files. When everything has been added, the temporary files will be merged into a single MTBL file.
To create a Sorter with non-default options, see SorterOptions.
Example
let mut sorter = Sorter::create_from_path("/tmp/f.mtbl", |k, v0, v1| "collision".as_bytes().to_vec()); sorter.add("b", dat_b); sorter.add("a", dat_a); sorter.add("a", other_dat_a); sorter.add_all((0..100).map(|i| (format!("key {}", i), format!("entry {}", i))));Run
Fields
options: SorterOptions
The options used to create this sorter.
merge_fn: Box<Box<MergeFn>>
The function used to merge entries with colliding keys.
Methods
impl Sorter
[src]
fn create_from_writer<F>(writer: Writer, merge_fn: F) -> Sorter where F: Fn(&[u8], &[u8], &[u8]) -> Vec<u8> + 'static
Create a new Sorter
.
Once sorting is done, the resulting sequence of entries will be written
to the supplied Writer
. Note that a MergeFn
must be supplied to
combine values for entries with colliding keys.
fn create_from_path<T, F>(path: T, merge_fn: F) -> IOResult<Sorter> where T: AsRef<Path>, F: Fn(&[u8], &[u8], &[u8]) -> Vec<u8> + 'static
Create a new Sorter
.
Once sorting is done, the resulting sequence of entries will be written
to the supplied path. Note that a MergeFn
must be supplied to combine
values for entries with colliding keys.
fn create_from_file<T, F>(file: T, merge_fn: F) -> IOResult<Sorter> where T: 'static + AsRawFd, F: Fn(&[u8], &[u8], &[u8]) -> Vec<u8> + 'static
Create a new Sorter
.
Once sorting is done, the resulting sequence of entries will be written
to the supplied path. Note that a MergeFn
must be supplied to combine
values for entries with colliding keys.
fn add_all<T, U, I>(&mut self, iterable: I) -> Result<(), ()> where T: AsRef<[u8]>, U: AsRef<[u8]>, I: IntoIterator<Item=(T, U)>
Add all elements from an iterator.
This will result in an Error only if the output Writer receives items out of order, which can only happen if the output Writer had already had items added, not from the Sorter.
Trait Implementations
impl Write for Sorter
[src]
fn add<T, U>(&mut self, key: T, value: U) -> Result<(), ()> where T: AsRef<[u8]>, U: AsRef<[u8]>
Add a key-value pair to be written to the MTBL file.