Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use super::Iterable; | ||
use crate::iter::Rev; | ||
|
||
/// Stream that goes over an `[ExactSizeIterator]` in reverse order. | ||
/// | ||
/// This stream allows to switch fast from little endian ordering used in | ||
/// time-efficient algorithms, e.g. in slices `&[T]` into big endia ordering | ||
/// (used in space-efficient algorithms. | ||
/// | ||
/// # Examples | ||
/// ``` | ||
/// use ark_std::iterable::{Iterable, Reverse}; | ||
/// | ||
/// let le_v = &[1, 2, 3]; | ||
/// let be_v = Reverse(le_v); | ||
/// let mut be_v_iter = be_v.iter(); | ||
/// assert_eq!(be_v_iter.next(), Some(&3)); | ||
/// assert_eq!(be_v_iter.next(), Some(&2)); | ||
/// assert_eq!(be_v_iter.next(), Some(&1)); | ||
/// ``` | ||
#[derive(Clone, Copy)] | ||
pub struct Reverse<I>(pub I) | ||
where | ||
I: Iterable, | ||
I::Iter: DoubleEndedIterator; | ||
|
||
impl<I> Iterable for Reverse<I> | ||
where | ||
I: Iterable, | ||
I::Iter: DoubleEndedIterator, | ||
{ | ||
type Item = I::Item; | ||
type Iter = Rev<I::Iter>; | ||
|
||
#[inline] | ||
fn iter(&self) -> Self::Iter { | ||
self.0.iter().rev() | ||
} | ||
|
||
#[inline] | ||
fn len(&self) -> usize { | ||
self.0.len() | ||
} | ||
} |