[][src]Struct solana_libra_proptest_helpers::RepeatVec

pub struct RepeatVec<T> { /* fields omitted */ }

An efficient representation of a vector with repeated elements inserted.

Internally, this data structure stores one copy of each inserted element, along with data about how many times each element is repeated.

This data structure does not do any sort of deduplication, so it isn't any sort of set (or multiset).

This is useful for presenting a large logical vector for picking proptest indexes from.

Examples

use proptest_helpers::RepeatVec;

let mut repeat_vec = RepeatVec::new();
repeat_vec.extend("a", 10); // logically, insert "a" 10 times
repeat_vec.extend("b", 20); // logically, insert "b" 20 times
assert_eq!(repeat_vec.get(0), Some((&"a", 0))); // returns the "a" at logical position 0
assert_eq!(repeat_vec.get(5), Some((&"a", 5))); // returns the "a" at logical position 5
assert_eq!(repeat_vec.get(10), Some((&"b", 0))); // returns the "b" (offset 0) at logical position 10
assert_eq!(repeat_vec.get(20), Some((&"b", 10))); // returns the "b" (offset 10) at logical position 20
assert_eq!(repeat_vec.get(30), None); // past the end of the logical array

The data structure doesn't care about whether the inserted items are equal or not.

use proptest_helpers::RepeatVec;

let mut repeat_vec = RepeatVec::new();
repeat_vec.extend("a", 10); // logically, insert "a" 10 times
repeat_vec.extend("a", 20); // logically, insert "a" 20 times
assert_eq!(repeat_vec.get(0), Some((&"a", 0)));
assert_eq!(repeat_vec.get(5), Some((&"a", 5)));
assert_eq!(repeat_vec.get(10), Some((&"a", 0))); // This refers to the second "a".

Methods

impl<T> RepeatVec<T>[src]

pub fn new() -> Self[src]

Creates a new, empty RepeatVec.

pub fn len(&self) -> usize[src]

Returns the logical number of elements in this RepeatVec.

pub fn is_empty(&self) -> bool[src]

Returns true if this RepeatVec has no logical elements.

Examples

use proptest_helpers::RepeatVec;

let mut repeat_vec = RepeatVec::new();

// There are no elements in this RepeatVec.
assert!(repeat_vec.is_empty());

// Adding 0 logical copies of an element still means it's empty.
repeat_vec.extend("a", 0);
assert!(repeat_vec.is_empty());

// Adding non-zero logical copies makes this vector not empty.
repeat_vec.extend("b", 1);
assert!(!repeat_vec.is_empty());

pub fn extend(&mut self, item: T, size: usize)[src]

Extends this RepeatVec by logically adding size copies of item to the end of it.

pub fn get(&self, at: usize) -> Option<(&T, usize)>[src]

Returns the item at location at. The return value is a reference to the stored item, plus the offset from the start (logically, which copy of the item is being returned).

pub fn pick_uniform(&self, indexes: &[impl AsRef<Index>]) -> Vec<(&T, usize)>[src]

Picks out elements uniformly randomly from this RepeatVec, using the provided Index instances as sources of randomness.

Trait Implementations

impl<T: Clone> Clone for RepeatVec<T>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T: Default> Default for RepeatVec<T>[src]

impl<T: PartialEq> PartialEq<RepeatVec<T>> for RepeatVec<T>[src]

impl<T: Eq> Eq for RepeatVec<T>[src]

impl<T: Debug> Debug for RepeatVec<T>[src]

impl<T: Hash> Hash for RepeatVec<T>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl<T> Sync for RepeatVec<T> where
    T: Sync

impl<T> Send for RepeatVec<T> where
    T: Send

impl<T> Unpin for RepeatVec<T> where
    T: Unpin

impl<T> RefUnwindSafe for RepeatVec<T> where
    T: RefUnwindSafe

impl<T> UnwindSafe for RepeatVec<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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