Skip to main content

SegList

Struct SegList 

Source
pub struct SegList<T> { /* private fields */ }
Expand description

Segmented list with cache-friendly segment sizes

Each segment’s capacity is calculated at runtime based on T’s size to fit within a cache line.

NOTE: T is allow to larger than CACHE_LINE_SIZE, in this case SegList will ensure at least 2 items in one segment. But when T larger than 128B, you should consider put T into Box.

Implementations§

Source§

impl<T> SegList<T>

Source

pub fn new() -> Self

Create a new empty SegList with one allocated segment

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty

Source

pub const fn segment_cap() -> usize

Get the capacity of each segment

Source

pub fn len(&self) -> usize

Returns the total number of elements in the list

Source

pub fn push(&mut self, item: T)

Push an element to the back of the list

Source

pub fn pop(&mut self) -> Option<T>

Pop an element from the back of the list

Source

pub fn iter(&self) -> SegListIter<'_, T>

Returns an iterator over the list

Source

pub fn iter_mut(&mut self) -> SegListIterMut<'_, T>

Returns a mutable iterator over the list

Source

pub fn drain(self) -> SegListDrain<T>

Returns a draining iterator that consumes the list and yields elements from head to tail

Source

pub fn first(&self) -> Option<&T>

Returns a reference to the first element in the list

Source

pub fn last(&self) -> Option<&T>

Returns a reference to the last element in the list

Source

pub fn last_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the last element in the list

Source

pub fn clear(&mut self)

Clear all elements from the list

Trait Implementations§

Source§

impl<T: Debug> Debug for SegList<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for SegList<T>

Source§

fn default() -> Self

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

impl<T> Drop for SegList<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> IntoIterator for SegList<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = SegListDrain<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Send> Send for SegList<T>

Source§

impl<T: Send> Sync for SegList<T>

Auto Trait Implementations§

§

impl<T> Freeze for SegList<T>

§

impl<T> RefUnwindSafe for SegList<T>

§

impl<T> Unpin for SegList<T>

§

impl<T> UnsafeUnpin for SegList<T>

§

impl<T> UnwindSafe for SegList<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.