pub struct SortedLinkedList<T, Idx, K, const N: usize>where
    Idx: SortedLinkedListIndex,
{ /* private fields */ }
Expand description

The linked list.

Implementations

Create a new linked list.

Create a new linked list.

Create a new linked list.

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.

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

Complexity is worst-case O(N).

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

// 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));

Get an iterator over the sorted list.

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

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);

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

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

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(), Ok(1002));
assert_eq!(ll.pop(), Ok(3));
assert_eq!(ll.pop(), Ok(1));
assert_eq!(ll.pop(), Err(()));

Peek at the first element.

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

// 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> = SortedLinkedList::new_usize();

// 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));

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

Safety

Assumes that the list is not empty.

Pops the first element in the list.

Complexity is worst-case O(1).

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

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

assert_eq!(ll.pop(), Ok(2));
assert_eq!(ll.pop(), Ok(1));
assert_eq!(ll.pop(), Err(()));

Checks if the linked list is full.

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

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);

Checks if the linked list is empty.

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

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

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

Trait Implementations

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.