[][src]Struct external_sort::ExternalSorter

pub struct ExternalSorter<T> where
    T: ExternallySortable
{ /* fields omitted */ }

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);
    }
}

Methods

impl<T> ExternalSorter<T> where
    T: ExternallySortable
[src]

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

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

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

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

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
[src]

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> Send for ExternalSorter<T> where
    T: Send

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

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

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

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

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]