ExternalSorter

Struct ExternalSorter 

Source
pub struct ExternalSorter<T>{ /* private fields */ }
Expand description

Perform an external sort on an unsorted stream of incoming data

§Examples

extern crate external_sort;
#[macro_use]
extern crate serde_derive;

use external_sort::{ExternallySortable, ExternalSorter};

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
struct Num {
    the_num: u32
}

impl Num {
    fn new(num:u32) -> Num {
        Num { the_num: num }
    }
}

impl ExternallySortable for Num {
    fn get_size(&self) -> u64 {
        4
    }
}

fn main() {
    let unsorted = vec![Num::new(5), Num::new(2), Num::new(1), Num::new(3),
        Num::new(4)]; 
    let sorted = vec![Num::new(1), Num::new(2), Num::new(3), Num::new(4), 
        Num::new(5)];

    let external_sorter = ExternalSorter::new(16, None);
    let iter = external_sorter.sort(unsorted.into_iter()).unwrap();
    for (idx, i) in iter.enumerate() {
        assert_eq!(i.unwrap().the_num, sorted[idx].the_num);
    }
}

Implementations§

Source§

impl<T> ExternalSorter<T>

Source

pub fn new(buffer_bytes: u64, tmp_dir: Option<PathBuf>) -> ExternalSorter<T>

Create a new ExternalSorter with a specified memory buffer and temporary directory

Source

pub fn sort<I>( &self, unsorted: I, ) -> Result<ExtSortedIterator<T>, Box<dyn Error>>
where I: Iterator<Item = T>,

Sort the Ts provided by unsorted and return a sorted (ascending) iterator

§Errors

This method can fail due to issues writing intermediate sorted chunks to disk, or due to serde serialization issues

Source

pub fn sort_by<I, F>( &self, unsorted: I, compare: F, ) -> Result<ExtSortedIterator<T>, Box<dyn Error>>
where I: Iterator<Item = T>, F: 'static + FnMut(&T, &T) -> Ordering,

Sort (based on compare) the Ts provided by unsorted and return an iterator

§Errors

This method can fail due to issues writing intermediate sorted chunks to disk, or due to serde serialization issues

Auto Trait Implementations§

§

impl<T> Freeze for ExternalSorter<T>

§

impl<T> RefUnwindSafe for ExternalSorter<T>
where T: RefUnwindSafe,

§

impl<T> Send for ExternalSorter<T>
where T: Send,

§

impl<T> Sync for ExternalSorter<T>
where T: Sync,

§

impl<T> Unpin for ExternalSorter<T>
where T: Unpin,

§

impl<T> UnwindSafe for ExternalSorter<T>
where T: UnwindSafe,

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>,

Source§

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>,

Source§

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.