Module collections/linked_list

collections/linked_list

Doubly-linked list with O(1) push/pop at both ends.

Types

LinkedList type-function
fn(comptime(T) : Type) -> (comptime(fn_return_yo82d8fb41_id_70) : Type)

Doubly-linked list with O(1) push/pop at both ends.

Type Parameters

NameTypeNotes
TTypecomptime

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)

LinkedListError

Error variants for LinkedList operations.

Variants

VariantFieldsDescription
IndexOutOfBoundsindex: usize, length: usize

Index is out of bounds for the current length.

EmptyList

Attempted to access an element from an empty list.

LinkedListIter type-function
fn(comptime(T) : Type) -> (comptime(fn_return_yo82d8fb41_id_279) : Type)

Value iterator for LinkedList - yields elements by value (T) Traverses the linked list following node.next pointers.

Type Parameters

NameTypeNotes
TTypecomptime

Trait Implementations

impl(forall(T : Type), LinkedListIter(T), Iterator(...))
Item : T
next : (fn(self : *(Self)) -> Option(T))

Returns: Option(T)

LinkedListIterPtr type-function
fn(comptime(T) : Type) -> (comptime(fn_return_yo82d8fb41_id_468) : Type)

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

NameTypeNotes
TTypecomptime

Trait Implementations

impl(forall(T : Type), LinkedListIterPtr(T), Iterator(...))
Item : *(T)
next : (fn(self : *(Self)) -> Option(*(T)))

Returns: Option(*(T))