[][src]Struct 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 libra_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 libra_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".

Implementations

impl<T> RepeatVec<T>[src]

pub fn new() -> Self[src]

Creates a new, empty RepeatVec.

pub fn with_capacity(capacity: usize) -> Self[src]

Creates a new, empty RepeatVec with the specified capacity to store physical elements.

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 libra_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 remove(&mut self, index: usize)[src]

Removes the item specified by the given logical index, shifting all elements after it to the left by updating start positions.

Out of bounds indexes have no effect.

pub fn remove_all(&mut self, logical_indexes: impl IntoIterator<Item = usize>)[src]

Removes the items specified by the given logical indexes, shifting all elements after them to the left by updating start positions.

Ignores any out of bounds indexes.

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_indexes(&self, indexes: &[impl AsRef<Index>]) -> Vec<usize>[src]

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

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]

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

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

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

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

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

impl<T> StructuralEq for RepeatVec<T>[src]

impl<T> StructuralPartialEq for RepeatVec<T>[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

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

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

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

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

impl<T> Pointable for T

type Init = T

The type for initializers.

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

type Owned = T

The resulting type after obtaining ownership.

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<V, T> VZip<V> for T where
    V: MultiLane<T>,