pub struct SegList<T> { /* private fields */ }Expand description
Segmented list with cache-friendly segment sizes.
Support push() / pop() from the tail, and one-time consume all elements. It does not support random access.
Each segment’s capacity is calculated at runtime based on T’s size to fit within a cache line. (The first segment is 2 * CACHE_LINE_SIZE, the subsequent allocation use CACHE_LINE_SIZE * 4)
It’s faster than Vec when the number of items is small (1~64), because it does not re-allocate
during push(). It’s slower than Vec when the number is very large (due to pointer dereference cost).
§NOTE
T is allow to larger than 2 * CACHE_LINE_SIZE, in this case SegList will ensure at least 2
items in one segment. But it’s not efficient when T larger than 128B, you should consider put T into Box.
Refer to module level doc for examples.
Implementations§
Source§impl<T> SegList<T>
impl<T> SegList<T>
Sourcepub const fn segment_cap() -> usize
pub const fn segment_cap() -> usize
Get the base capacity of the first segment
Sourcepub fn iter(&self) -> SegListIter<'_, T> ⓘ
pub fn iter(&self) -> SegListIter<'_, T> ⓘ
Returns an iterator over the list
Sourcepub fn iter_rev(&self) -> SegListIter<'_, T> ⓘ
pub fn iter_rev(&self) -> SegListIter<'_, T> ⓘ
Returns a reverse iterator over the list
Sourcepub fn iter_mut(&mut self) -> SegListIterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> SegListIterMut<'_, T> ⓘ
Returns a mutable iterator over the list
Sourcepub fn iter_mut_rev(&mut self) -> SegListIterMut<'_, T> ⓘ
pub fn iter_mut_rev(&mut self) -> SegListIterMut<'_, T> ⓘ
Returns a mutable reverse iterator over the list
Sourcepub fn drain(self) -> SegListDrain<T> ⓘ
pub fn drain(self) -> SegListDrain<T> ⓘ
Returns a draining iterator that consumes the list and yields elements from head to tail
Sourcepub fn into_rev(self) -> SegListDrain<T> ⓘ
pub fn into_rev(self) -> SegListDrain<T> ⓘ
Returns a draining iterator that consumes the list and yields elements from tail to head