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 arrayThe 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 with the specified capacity to store physical elements.
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.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for RepeatVec<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for RepeatVec<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more