pub struct ExternalSorter { /* private fields */ }
Expand description

Exposes external sorting (i.e. on-disk sorting) capability on arbitrarily sized iterators, even if the generated content of the iterator doesn’t fit in memory.

It uses an in-memory buffer sorted and flushed to disk in segment files when full. Once sorted, it returns a new sorted iterator with all items. In order to remain efficient for all implementations, the crate doesn’t handle serialization, but leaves that to the user.

Implementations§

source§

impl ExternalSorter

source

pub fn new() -> ExternalSorter

source

pub fn with_segment_size(self, size: usize) -> Self

Sets the maximum size of each segment in number of sorted items.

This number of items needs to fit in memory. While sorting, an in-memory buffer is used to collect the items to be sorted. Once it reaches the maximum size, it is sorted and then written to disk.

Using a higher segment size makes sorting faster by leveraging faster in-memory operations.

Default is 10000

source

pub fn with_sort_dir(self, path: PathBuf) -> Self

Sets the directory in which sorted segments will be written (if they don’t fit in memory).

Default is to use the system’s temporary directory.

source

pub fn with_parallel_sort(self) -> Self

Uses Rayon to sort the in-memory buffer.

This may not be needed if the buffer isn’t big enough for parallelism to be beneficial over the overhead of multithreading.

Default is false

source

pub fn with_heap_iter_segment_count(self, count: usize) -> Self

From how many segments on disk should the iterator switch to using a binary heap to keep track of the smallest item from each segment.

For a small amount of segments, it is faster to peek over all segments at each iteration than to maintain a binary heap.

Default is 20

source

pub fn sort<T, I>( self, iterator: I ) -> Result<SortedIterator<T, impl Fn(&T, &T) -> Ordering + Send + Sync + Clone>, Error>
where T: Sortable + Ord, I: IntoIterator<Item = T>,

Sorts a given iterator, returning a new iterator with the sorted items.

source

pub fn sort_by_key<T, I, F, K>( self, iterator: I, f: F ) -> Result<SortedIterator<T, impl Fn(&T, &T) -> Ordering + Send + Sync + Clone>, Error>
where T: Sortable, I: IntoIterator<Item = T>, F: Fn(&T) -> K + Send + Sync + Clone, K: Ord,

Sorts a given iterator with a key extraction function, returning a new iterator with the sorted items.

source

pub fn sort_by<T, I, F>( self, iterator: I, cmp: F ) -> Result<SortedIterator<T, F>, Error>
where T: Sortable, I: IntoIterator<Item = T>, F: Fn(&T, &T) -> Ordering + Send + Sync + Clone,

Sorts a given iterator with a comparator function, returning a new iterator with the sorted items.

source

pub fn pushed<T>( self ) -> PushExternalSorter<T, impl Fn(&T, &T) -> Ordering + Send + Sync + Clone>
where T: Sortable + Ord,

Creates a pushed external sorter, which will consume items in a push pattern and compare them using the default comparator.

source

pub fn pushed_by<T, F>(self, cmp: F) -> PushExternalSorter<T, F>
where T: Sortable, F: Fn(&T, &T) -> Ordering + Send + Sync + Clone,

Creates a pushed external sorter, which will consume items in a push pattern and compare them using the given comparator function.

source

pub fn pushed_by_key<T, F, K>( self, f: F ) -> PushExternalSorter<T, impl Fn(&T, &T) -> Ordering + Send + Sync + Clone>
where T: Sortable, F: Fn(&T) -> K + Send + Sync + Clone, K: Ord,

Creates a pushed external sorter, which will consume items in a push pattern and compare them using the given key extraction function.

Trait Implementations§

source§

impl Default for ExternalSorter

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.