Struct diem_proptest_helpers::RepeatVec[][src]

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

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 diem_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 diem_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

Creates a new, empty RepeatVec.

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

Returns the logical number of elements in this RepeatVec.

Returns true if this RepeatVec has no logical elements.

Examples

use diem_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());

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

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.

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.

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).

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

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.