pub struct PrefixSumVec<T, Idx = usize> { /* private fields */ }Expand description
A data structure for space-efficient storage of repeating sequences.
Much like Vec, this is a growable array-like type. This data structure is capaable of
storing a contiguous sequence of repeating values only once, thus “compressing” the
representation of the sequence. Conversely index lookups are O(log n), rather than O(1) as
provided by Vec.
Note, however, that this data structure can become less space-efficient than a plain Vec if
the data is incompressible.
§Examples
let mut prefix_sum_vec = prefix_sum_vec::PrefixSumVec::new();
prefix_sum_vec.try_push_many(12, "strings").expect("could not push");
assert_eq!(prefix_sum_vec.max_index(), Some(&11));
assert_eq!(prefix_sum_vec[0], "strings");
assert_eq!(prefix_sum_vec[11], "strings");Implementations§
Source§impl<T, Idx> PrefixSumVec<T, Idx>
impl<T, Idx> PrefixSumVec<T, Idx>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty PrefixSumVec.
Does not allocate.
Source§impl<T, Idx: Ord> PrefixSumVec<T, Idx>
impl<T, Idx: Ord> PrefixSumVec<T, Idx>
Source§impl<T, Idx: Index> PrefixSumVec<T, Idx>
impl<T, Idx: Index> PrefixSumVec<T, Idx>
Sourcepub fn try_push_many(
&mut self,
count: Idx,
value: T,
) -> Result<(), TryPushError>
pub fn try_push_many( &mut self, count: Idx, value: T, ) -> Result<(), TryPushError>
Append count copies of a value to the back of the collection.
This method will not inspect the values currently stored in the data structure in search
for further compression opportunities. Instead the provided value will be stored compressed
as-if a sequence of count repeating values were provided.
Complexity: O(1) amortized.
Source§impl<T: PartialEq, Idx: Index> PrefixSumVec<T, Idx>
impl<T: PartialEq, Idx: Index> PrefixSumVec<T, Idx>
Sourcepub fn try_push_more(
&mut self,
count: Idx,
value: T,
) -> Result<(), TryPushError>
pub fn try_push_more( &mut self, count: Idx, value: T, ) -> Result<(), TryPushError>
Append count copies of a value to the back of the collection, attempting compression.
This method will not inspect the values currently stored in the data structure in search
for further compression opportunities. Instead the provided value will be stored compressed
as-if a sequence of count repeating values were provided.
Complexity: O(1) amortized.