Struct grenad::Sorter

source ·
pub struct Sorter<MF, CC: ChunkCreator = DefaultChunkCreator> { /* private fields */ }
Expand description

A struct you can use to automatically sort and merge duplicate entries.

You can insert key-value pairs in arbitrary order, it will use the ChunkCreator and you the generated chunks to buffer when the dump_threashold setting is reached.

Implementations§

source§

impl<MF> Sorter<MF, DefaultChunkCreator>

source

pub fn builder(merge: MF) -> SorterBuilder<MF, DefaultChunkCreator>

Creates a SorterBuilder from a merge function, it can be used to configure your Sorter to better fit your needs.

source

pub fn new(merge: MF) -> Sorter<MF, DefaultChunkCreator>

Creates a Sorter from a merge function, with the default parameters.

source

pub fn estimated_dumped_memory_usage(&self) -> u64

A rough estimate of how much memory usage it will take on the disk once dumped to disk.

This is a very bad estimate in the sense that it does not calculate the amount of duplicate entries that are in the dumped chunks and neither the fact that the in-memory buffer will likely be compressed once written to disk. This estimate will always be greater than the actual end space usage on disk.

source§

impl<MF, CC, U> Sorter<MF, CC>
where MF: for<'a> Fn(&[u8], &[Cow<'a, [u8]>]) -> Result<Cow<'a, [u8]>, U>, CC: ChunkCreator,

source

pub fn insert<K, V>(&mut self, key: K, val: V) -> Result<(), Error<U>>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Insert an entry into the Sorter making sure that conflicts are resolved by the provided merge function.

source

pub fn write_into_stream_writer<W: Write>( self, writer: &mut Writer<W> ) -> Result<(), Error<U>>

Consumes this Sorter and streams the entries to the Writer given in parameter.

source

pub fn into_stream_merger_iter( self ) -> Result<MergerIter<CC::Chunk, MF>, Error<U>>

Consumes this Sorter and outputs a stream of the merged entries in key-order.

source

pub fn into_reader_cursors( self ) -> Result<Vec<ReaderCursor<CC::Chunk>>, Error<U>>

Consumes this Sorter and outputs the list of reader cursors.

Auto Trait Implementations§

§

impl<MF, CC> Freeze for Sorter<MF, CC>
where CC: Freeze, MF: Freeze,

§

impl<MF, CC> RefUnwindSafe for Sorter<MF, CC>

§

impl<MF, CC> Send for Sorter<MF, CC>
where CC: Send, MF: Send, <CC as ChunkCreator>::Chunk: Send,

§

impl<MF, CC> Sync for Sorter<MF, CC>
where CC: Sync, MF: Sync, <CC as ChunkCreator>::Chunk: Sync,

§

impl<MF, CC> Unpin for Sorter<MF, CC>
where CC: Unpin, MF: Unpin, <CC as ChunkCreator>::Chunk: Unpin,

§

impl<MF, CC = TempFileChunk> !UnwindSafe for Sorter<MF, CC>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.