pub struct GrowingSubset<Ix, T> { /* private fields */ }
Expand description

A set of elements, each with an associated key, that grows over time.

This is called GrowingSubset because the universal set the subset grows from is provided upfront. At any time, the items included form the current subset.

GrowingSubset integrates with proptest through the pick_item and pick_value methods.

Examples

use diem_proptest_helpers::GrowingSubset;
let items = vec![(1, "a"), (3, "c"), (2, "b"), (2, "d")];
let mut subset: GrowingSubset<_, _> = items.into_iter().collect();

assert_eq!(subset.total_len(), 4);
assert_eq!(subset.len(), 0);
assert_eq!(subset.current(), &[]);

subset.advance_to(&2);
assert_eq!(subset.len(), 1);
assert_eq!(subset.current(), &[(1, "a")]);

subset.advance_to(&4);
assert_eq!(subset.len(), 4);
assert_eq!(subset.current(), &[(1, "a"), (2, "b"), (2, "d"), (3, "c")]);

subset.advance_to(&5);
assert_eq!(subset.len(), 4);
assert_eq!(subset.current(), &[(1, "a"), (2, "b"), (2, "d"), (3, "c")]);

Implementations§

source§

impl<Ix, T> GrowingSubset<Ix, T>where Ix: Ord,

source

pub fn len(&self) -> usize

Returns the number of elements in the current subset.

See total_len for the length of the universal set.

source

pub fn is_empty(&self) -> bool

Returns true if the current subset contains no elements.

source

pub fn total_len(&self) -> usize

Returns the total number of elements in the universal set.

This remains fixed once the GrowingSubset has been created.

source

pub fn current(&self) -> &[(Ix, T)]

Returns a slice containing the items in the current subset.

source

pub fn pick_item(&self, index: &Index) -> &(Ix, T)

Chooses an (index, value) pair from the current subset using the provided Index instance as the source of randomness.

source

pub fn pick_value(&self, index: &Index) -> &T

Chooses a value from the current subset using the provided Index instance as the source of randomness.

source

pub fn advance_to(&mut self, to_idx: &Ix)

Advances the valid subset to the provided index. After the end of this, the current subset will contain all elements where the index is less than to_idx.

If duplicate indexes exist, advance_to will cause all of the corresponding items to be included.

It is expected that advance_to will be called with larger indexes over time.

Trait Implementations§

source§

impl<Ix: Clone, T: Clone> Clone for GrowingSubset<Ix, T>

source§

fn clone(&self) -> GrowingSubset<Ix, T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Ix: Debug, T: Debug> Debug for GrowingSubset<Ix, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Ix, T> FromIterator<(Ix, T)> for GrowingSubset<Ix, T>where Ix: Ord,

Constructs a GrowingSubset from an iterator of (index, value) pairs.

The input does not need to be pre-sorted.

source§

fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = (Ix, T)>,

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<Ix, T> RefUnwindSafe for GrowingSubset<Ix, T>where Ix: RefUnwindSafe, T: RefUnwindSafe,

§

impl<Ix, T> Send for GrowingSubset<Ix, T>where Ix: Send, T: Send,

§

impl<Ix, T> Sync for GrowingSubset<Ix, T>where Ix: Sync, T: Sync,

§

impl<Ix, T> Unpin for GrowingSubset<Ix, T>where Ix: Unpin, T: Unpin,

§

impl<Ix, T> UnwindSafe for GrowingSubset<Ix, T>where Ix: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V