https://github.com/rozbb/rust-iterslide
A "sliding window" iterator.
https://github.com/rozbb/rust-iterslide
Last synced: 11 months ago
JSON representation
A "sliding window" iterator.
- Host: GitHub
- URL: https://github.com/rozbb/rust-iterslide
- Owner: rozbb
- License: other
- Created: 2015-05-24T00:11:35.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2020-04-26T17:42:23.000Z (about 6 years ago)
- Last Synced: 2025-04-09T21:59:53.249Z (about 1 year ago)
- Language: Rust
- Size: 18.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
rust-iterslide
===============
[](https://crates.io/crates/iterslide)
[](https://docs.rs/iterslide)
[](https://travis-ci.org/rozbb/rust-iterslide)
This package implements "sliding window" functionality for any iterator over a `Clone`able item.
Example
-------
```rust
use iterslide::SlideIterator;
fn main() {
let v: Vec = vec![1, 2, 3, 4, 5];
for window in v.slide(3) {
// window is a VecDeque
println!("{:?}", window);
}
}
```
Output:
```
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
```
Alternatives
------------
* Rust's [`windows`](https://doc.rust-lang.org/std/primitive.slice.html#method.windows) method for slices does what you would expect. This does no allocation. However, this is only implemented for slices.
* itertools' [`tuple_windows`](https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.tuple_windows) method returns a sliding window iterator over tuples instead of `VecDeques`. This saves a `VecDeque` allocation in construction of the iterator. However, `tuple_windows` is limited to window sizes of at most 4.
License
-------
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
* MIT license ([LICENSE-MIT](LICENSE-MIT))
at your option.
Contribution
------------
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you shall be dual licensed as above, without any
additional terms or conditions.