pub struct ExternalSorter<T>where
T: ExternallySortable,{ /* 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>where
T: ExternallySortable,
impl<T> ExternalSorter<T>where
T: ExternallySortable,
Sourcepub fn new(buffer_bytes: u64, tmp_dir: Option<PathBuf>) -> ExternalSorter<T>
pub fn new(buffer_bytes: u64, tmp_dir: Option<PathBuf>) -> ExternalSorter<T>
Create a new ExternalSorter with a specified memory buffer and
temporary directory
Sourcepub fn sort<I>(
&self,
unsorted: I,
) -> Result<ExtSortedIterator<T>, Box<dyn Error>>where
I: Iterator<Item = T>,
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
Sourcepub fn sort_by<I, F>(
&self,
unsorted: I,
compare: F,
) -> Result<ExtSortedIterator<T>, Box<dyn Error>>
pub fn sort_by<I, F>( &self, unsorted: I, compare: F, ) -> Result<ExtSortedIterator<T>, Box<dyn Error>>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more