Module collections/linked_list
Doubly-linked list with O(1) push/pop at both ends.
Types
Doubly-linked list with O(1) push/pop at both ends.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), LinkedList(T), ...)
new : (fn() -> Self)Create a new empty LinkedList
Returns: Self
len : (fn(self: Self) -> usize)Get the number of elements in the list
Returns: usize
is_empty : (fn(self: Self) -> bool)Check if the list is empty
Returns: bool
push_front : (fn(self: Self, value: T) -> unit)Push an element to the front of the list O(1) time complexity
Returns: unit
push_back : (fn(self: Self, value: T) -> unit)Push an element to the back of the list O(1) time complexity
Returns: unit
pop_front : (fn(self: Self) -> Option(T))Remove and return the element from the front O(1) time complexity
Returns: Option(T)
pop_back : (fn(self: Self) -> Option(T))Remove and return the element from the back O(1) time complexity
Returns: Option(T)
front : (fn(self: Self) -> Option(T))Get reference to the front element without removing it
Returns: Option(T)
back : (fn(self: Self) -> Option(T))Get reference to the back element without removing it
Returns: Option(T)
get : (fn(self: Self, index: usize) -> Option(T))Get element at a specific index O(n) time complexity
Returns: Option(T)
insert : (fn(self: Self, index: usize, value: T) -> Result(unit, LinkedListError))Insert element at a specific index O(n) time complexity
Returns: Result(unit, LinkedListError)
remove : (fn(self: Self, index: usize) -> Result(T, LinkedListError))Remove element at a specific index O(n) time complexity
Returns: Result(T, LinkedListError)
clear : (fn(self: Self) -> unit)Clear all elements from the list
Returns: unit
contains : (fn(
self: Self,
value: T,
where(T <: Eq(T))
) -> bool)Check if the list contains a value O(n) time complexity
Returns: bool
reverse : (fn(self: Self) -> unit)Reverse the list in place O(n) time complexity
Returns: unit
impl(forall(T : Type), LinkedList(T), Dispose(...))
dispose : (fn(self: Self) -> unit)RAII destructor - automatically called when LinkedList goes out of scope
Returns: unit
impl(forall(T : Type), LinkedList(T), ...)
into_iter : (fn(self : Self) -> LinkedListIter(T))Returns: LinkedListIter(T)
impl(forall(T : Type), LinkedList(T), ...)
iter : (fn(self : *(Self)) -> LinkedListIterPtr(T))Returns: LinkedListIterPtr(T)
Error variants for LinkedList operations.
Variants
| Variant | Fields | Description |
|---|---|---|
IndexOutOfBounds | index: usize, length: usize | Index is out of bounds for the current length. |
EmptyList | Attempted to access an element from an empty list. |
Value iterator for LinkedList - yields elements by value (T) Traverses the linked list following node.next pointers.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), LinkedListIter(T), Iterator(...))
Item : Tnext : (fn(self : *(Self)) -> Option(T))Returns: Option(T)
Pointer iterator for LinkedList - yields pointers to elements (*(T)) Yields &(node.value) for each node. Pointers are valid as long as the list is not modified during iteration.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), LinkedListIterPtr(T), Iterator(...))
Item : *(T)next : (fn(self : *(Self)) -> Option(*(T)))Returns: Option(*(T))