Crates.io | window-sort-iterator |
lib.rs | window-sort-iterator |
version | 0.1.0 |
source | src |
created_at | 2022-06-01 17:52:46.127437 |
updated_at | 2022-06-01 17:52:46.127437 |
description | An iterator adapter that sorts items within a sliding window |
homepage | |
repository | https://github.com/mrd0ll4r/window-sort-iterator |
max_upload_size | |
id | 598314 |
size | 9,676 |
An iterator adapter that sorts items within a sliding window.
This keeps a BinaryHeap of the items within a sliding window on top of an iterator. The algorithm works like this:
By default, this uses a max-heap, which results in the highest item being yielded first.
You can use a min-heap by wrapping items with std::cmp::Reverse
.
use window_sort_iterator::WindowSortIterExt;
let a = &[4, 2, 3, 1];
let mut it = a.iter().cloned().window_sort(2);
assert_eq!(Some(4), it.next());
assert_eq!(Some(3), it.next());
assert_eq!(Some(2), it.next());
assert_eq!(Some(1), it.next());
assert_eq!(None, it.next());
MIT, see LICENSE.