SortedLinkedListInner

Struct SortedLinkedListInner 

Source
pub struct SortedLinkedListInner<T, Idx, K, S>
where Idx: LenType, S: SortedLinkedListStorage<T, Idx> + ?Sized,
{ /* private fields */ }
Expand description

Base struct for SortedLinkedList and SortedLinkedListView, generic over the SortedLinkedListStorage.

In most cases you should use SortedLinkedList or SortedLinkedListView directly. Only use this struct if you want to write code that’s generic over both.

Implementations§

Source§

impl<T, K, const N: usize> SortedLinkedListInner<T, u8, K, SortedLinkedListStorageInner<[Node<T, u8>; N]>>

Source

pub const fn new_u8() -> Self

Create a new linked list.

Source§

impl<T, K, const N: usize> SortedLinkedListInner<T, u16, K, SortedLinkedListStorageInner<[Node<T, u16>; N]>>

Source

pub const fn new_u16() -> Self

Create a new linked list.

Source§

impl<T, K, const N: usize> SortedLinkedListInner<T, usize, K, SortedLinkedListStorageInner<[Node<T, usize>; N]>>

Source

pub const fn new_usize() -> Self

Create a new linked list.

Source§

impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
where Idx: LenType, S: SortedLinkedListStorage<T, Idx> + ?Sized,

Source

pub fn as_view(&self) -> &SortedLinkedListView<T, K, Idx>

Get a reference to the SortedLinkedList, erasing the N const-generic.

Source

pub fn as_mut_view(&mut self) -> &mut SortedLinkedListView<T, K, Idx>

Get a mutable reference to the Vec, erasing the N const-generic.

Source§

impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
where T: Ord, Idx: LenType, K: Kind, S: SortedLinkedListStorage<T, Idx> + ?Sized,

Source

pub unsafe fn push_unchecked(&mut self, value: T)

Pushes a value onto the list without checking if the list is full.

Complexity is worst-case O(n).

§Safety

Assumes that the list is not full.

Source

pub fn push(&mut self, value: T) -> Result<(), T>

Pushes an element to the linked list and sorts it into place.

Complexity is worst-case O(n).

§Example
use heapless::sorted_linked_list::{Max, SortedLinkedList};
let mut ll: SortedLinkedList<_, Max, 3, u8> = SortedLinkedList::new_u8();

// The largest value will always be first
ll.push(1).unwrap();
assert_eq!(ll.peek(), Some(&1));

ll.push(2).unwrap();
assert_eq!(ll.peek(), Some(&2));

ll.push(3).unwrap();
assert_eq!(ll.peek(), Some(&3));

// This will not fit in the queue.
assert_eq!(ll.push(4), Err(4));
Source

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

Peek at the first element.

§Example
use heapless::sorted_linked_list::{Max, Min, SortedLinkedList};
let mut ll_max: SortedLinkedList<_, Max, 3, u8> = SortedLinkedList::new_u8();

// The largest value will always be first
ll_max.push(1).unwrap();
assert_eq!(ll_max.peek(), Some(&1));
ll_max.push(2).unwrap();
assert_eq!(ll_max.peek(), Some(&2));
ll_max.push(3).unwrap();
assert_eq!(ll_max.peek(), Some(&3));

let mut ll_min: SortedLinkedList<_, Min, 3, u8> = SortedLinkedList::new_u8();

// The Smallest value will always be first
ll_min.push(3).unwrap();
assert_eq!(ll_min.peek(), Some(&3));
ll_min.push(2).unwrap();
assert_eq!(ll_min.peek(), Some(&2));
ll_min.push(1).unwrap();
assert_eq!(ll_min.peek(), Some(&1));
Source

pub unsafe fn pop_unchecked(&mut self) -> T

Pop an element from the list without checking so the list is not empty.

§Safety

Assumes that the list is not empty.

Source

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

Pops the first element in the list.

Complexity is worst-case O(1).

§Example
use heapless::sorted_linked_list::{Max, SortedLinkedList};
let mut ll: SortedLinkedList<_, Max, 3, u8> = SortedLinkedList::new_u8();

ll.push(1).unwrap();
ll.push(2).unwrap();

assert_eq!(ll.pop(), Some(2));
assert_eq!(ll.pop(), Some(1));
assert_eq!(ll.pop(), None);
Source

pub fn is_full(&self) -> bool

Checks if the linked list is full.

§Example
use heapless::sorted_linked_list::{Max, SortedLinkedList};
let mut ll: SortedLinkedList<_, Max, 3, u8> = SortedLinkedList::new_u8();

assert_eq!(ll.is_full(), false);

ll.push(1).unwrap();
assert_eq!(ll.is_full(), false);
ll.push(2).unwrap();
assert_eq!(ll.is_full(), false);
ll.push(3).unwrap();
assert_eq!(ll.is_full(), true);
Source

pub fn is_empty(&self) -> bool

Checks if the linked list is empty.

§Example
use heapless::sorted_linked_list::{Max, SortedLinkedList};
let mut ll: SortedLinkedList<_, Max, 3, u8> = SortedLinkedList::new_u8();

assert_eq!(ll.is_empty(), true);

ll.push(1).unwrap();
assert_eq!(ll.is_empty(), false);
Source§

impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
where T: Ord, Idx: LenType, K: Kind, S: SortedLinkedListStorage<T, Idx> + ?Sized,

Source

pub fn iter(&self) -> IterView<'_, T, Idx, K>

Get an iterator over the sorted list.

§Example
use heapless::sorted_linked_list::{Max, SortedLinkedList};
let mut ll: SortedLinkedList<_, Max, 3, u8> = SortedLinkedList::new_u8();

ll.push(1).unwrap();
ll.push(2).unwrap();

let mut iter = ll.iter();

assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), None);
Source

pub fn find_mut<F>(&mut self, f: F) -> Option<FindMutView<'_, T, Idx, K>>
where F: FnMut(&T) -> bool,

Find an element in the list that can be changed and resorted.

§Example
use heapless::sorted_linked_list::{Max, SortedLinkedList};
let mut ll: SortedLinkedList<_, Max, 3, u8> = SortedLinkedList::new_u8();

ll.push(1).unwrap();
ll.push(2).unwrap();
ll.push(3).unwrap();

// Find a value and update it
let mut find = ll.find_mut(|v| *v == 2).unwrap();
*find += 1000;
find.finish();

assert_eq!(ll.pop(), Some(1002));
assert_eq!(ll.pop(), Some(3));
assert_eq!(ll.pop(), Some(1));
assert_eq!(ll.pop(), None);

Trait Implementations§

Source§

impl<T, Idx, K, S> Debug for SortedLinkedListInner<T, Idx, K, S>
where T: Ord + Debug, Idx: LenType, K: Kind, S: ?Sized + SortedLinkedListStorage<T, Idx>,

Source§

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

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

impl<T, Idx, K, S> Drop for SortedLinkedListInner<T, Idx, K, S>
where Idx: LenType, S: SortedLinkedListStorage<T, Idx> + ?Sized,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T, Idx, K, S> Freeze for SortedLinkedListInner<T, Idx, K, S>
where Idx: Freeze, S: Freeze + ?Sized,

§

impl<T, Idx, K, S> RefUnwindSafe for SortedLinkedListInner<T, Idx, K, S>

§

impl<T, Idx, K, S> Send for SortedLinkedListInner<T, Idx, K, S>
where S: Send + ?Sized, K: Send, T: Send,

§

impl<T, Idx, K, S> Sync for SortedLinkedListInner<T, Idx, K, S>
where S: Sync + ?Sized, K: Sync, T: Sync,

§

impl<T, Idx, K, S> Unpin for SortedLinkedListInner<T, Idx, K, S>
where Idx: Unpin, S: Unpin + ?Sized, K: Unpin, T: Unpin,

§

impl<T, Idx, K, S> UnwindSafe for SortedLinkedListInner<T, Idx, K, S>
where Idx: UnwindSafe, S: UnwindSafe + ?Sized, K: UnwindSafe, T: UnwindSafe,

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.