pub struct Permutation { /* private fields */ }Expand description
A keyed rearrangement of 0..len.
Every index in the range maps to a distinct value in the range, and the whole range is covered.
use zond_engine::model::order::Permutation;
let order = Permutation::new(0x5EED, 1_000);
let mut asked: Vec<u64> = order.iter().collect();
assert_eq!(asked.len(), 1_000);
asked.sort_unstable();
assert!(asked.iter().copied().eq(0..1_000), "every target, asked once");Implementations§
Source§impl Permutation
impl Permutation
Sourcepub fn new(seed: u64, len: u64) -> Self
pub fn new(seed: u64, len: u64) -> Self
The rearrangement of 0..len that seed names.
The same pair produces the same order on any build, since a seed recorded in a journal has to mean the same order when the scan is continued. The mixing is written out here because a library hasher’s output may change between releases.
Sourcepub fn at(&self, index: u64) -> Option<u64>
pub fn at(&self, index: u64) -> Option<u64>
The position asked about indexth, or None for an index outside the
range this rearranges.
The bound matters: the walk lands inside 0..len from anywhere in the domain,
so an index past the end would repeat a position some index inside it answers.
Sourcepub fn index_of(&self, position: u64) -> Option<u64>
pub fn index_of(&self, position: u64) -> Option<u64>
When position is asked about: the index at names it
at, or None for a position outside the range.
The inverse of at, and as cheap. Lets progress be counted in the
order the scan asks while answers arrive numbered by plan position.
use zond_engine::model::order::Permutation;
let order = Permutation::new(0x5EED, 1_000);
let position = order.at(417).expect("inside the range");
assert_eq!(order.index_of(position), Some(417));
assert_eq!(order.index_of(1_000), None);Trait Implementations§
Source§impl Clone for Permutation
impl Clone for Permutation
impl Copy for Permutation
Source§impl Debug for Permutation
impl Debug for Permutation
impl Eq for Permutation
Source§impl PartialEq for Permutation
impl PartialEq for Permutation
impl StructuralPartialEq for Permutation
Auto Trait Implementations§
impl Freeze for Permutation
impl RefUnwindSafe for Permutation
impl Send for Permutation
impl Sync for Permutation
impl Unpin for Permutation
impl UnsafeUnpin for Permutation
impl UnwindSafe for Permutation
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more