[−][src]Struct external_sort::ExternalSorter
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]
T: ExternallySortable,
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]
&self,
unsorted: I
) -> Result<ExtSortedIterator<T>, Box<dyn Error>> where
I: Iterator<Item = T>,
Sort the T
s 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]
&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 T
s 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,
T: Send,
impl<T> Unpin for ExternalSorter<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for ExternalSorter<T> where
T: Sync,
T: Sync,
impl<T> UnwindSafe for ExternalSorter<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for ExternalSorter<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,