pub struct SortedLinkedListInner<T, Idx, K, S>{ /* 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]>>
impl<T, K, const N: usize> SortedLinkedListInner<T, u8, K, SortedLinkedListStorageInner<[Node<T, u8>; N]>>
Source§impl<T, K, const N: usize> SortedLinkedListInner<T, u16, K, SortedLinkedListStorageInner<[Node<T, u16>; N]>>
impl<T, K, const N: usize> SortedLinkedListInner<T, u16, K, SortedLinkedListStorageInner<[Node<T, u16>; N]>>
Source§impl<T, K, const N: usize> SortedLinkedListInner<T, usize, K, SortedLinkedListStorageInner<[Node<T, usize>; N]>>
impl<T, K, const N: usize> SortedLinkedListInner<T, usize, K, SortedLinkedListStorageInner<[Node<T, usize>; N]>>
Source§impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
Sourcepub fn as_view(&self) -> &SortedLinkedListView<T, K, Idx>
pub fn as_view(&self) -> &SortedLinkedListView<T, K, Idx>
Get a reference to the SortedLinkedList, erasing the N const-generic.
Sourcepub fn as_mut_view(&mut self) -> &mut SortedLinkedListView<T, K, Idx>
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>
impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
Sourcepub unsafe fn push_unchecked(&mut self, value: T)
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.
Sourcepub fn push(&mut self, value: T) -> Result<(), T>
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));Sourcepub fn peek(&self) -> Option<&T>
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));Sourcepub unsafe fn pop_unchecked(&mut self) -> T
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.
Sourcepub fn pop(&mut self) -> Option<T>
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);Sourcepub fn is_full(&self) -> bool
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);Sourcepub fn is_empty(&self) -> bool
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>
impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
Sourcepub fn iter(&self) -> IterView<'_, T, Idx, K> ⓘ
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);Sourcepub fn find_mut<F>(&mut self, f: F) -> Option<FindMutView<'_, T, Idx, K>>
pub fn find_mut<F>(&mut self, f: F) -> Option<FindMutView<'_, T, Idx, K>>
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);