LinkedList
ferum_std::linked_list
Ferum's implementation of a doubly linked list. Values stored in the list should be cheap to copy. Duplicate values are supported.
This list should be used for values that are cheap to copy. For a list that stores by moving values, see (ref_linked_list)[/]
Insertion of value to tail
O(D)
Deletion of value
O(1)
Deletion of value at head
O(D)
Deletion of value at tail
O(D)
Contains value
O(1)
Where D is the number of duplicates of that particular value.
Each value is stored internally in a table with a unique key pointing to that value. The key is generated sequentially using a u128 counter. So the maximum number of values that can be added to the list is MAX_U128 (340282366920938463463374607431768211455).
Quick Example
Resource LinkedList
LinkedList
Struct representing the linked list.
Struct ListPosition
ListPosition
Used to represent a position within a doubly linked list during iteration.
Constants
DUPLICATE_KEY
Thrown when a duplicate key is added to the list.
EMPTY_LIST
Thrown when a trying to perform an operation that requires a list to have elements but it doesn't.
KEY_NOT_FOUND
Thrown when the key for a given node is not found.
MUST_HAVE_NEXT_VALUE
Thrown when attempting to iterate beyond the limit of the linked list.
VALUE_NOT_FOUND
Thrown when a value being searched for is not found.
Functions
Function new
new
Initialize a new list.
Function singleton
singleton
Creates a linked list with a single element.
Function add
add
Add a value to the list.
Function insert_at
insert_at
Inserts a value to the given index.
Function remove
remove
Removes a value from the list. If there are duplicates, a random occurence is removed.
Function remove_first
remove_first
Remove the first element of the list. If the list is empty, will throw an error.
Function remove_last
remove_last
Remove the last element of the list. If the list is empty, will throw an error.
Function borrow_first
borrow_first
Get a reference to the first element of the list.
Function borrow_last
borrow_last
Get a reference to the last element of the list.
Function contains
contains
Returns true is the element is in the list.
Function length
length
Returns the length of the list.
Function is_empty
is_empty
Returns true if empty.
Function as_vector
as_vector
Returns the list as a vector.
Function iterator
iterator
Returns a left to right iterator. First time you call next(...) will return the first value. Updating the list while iterating will abort.
Function has_next
has_next
Returns true if there is another element left in the iterator.
Function get_next
get_next
Returns the next value, and updates the current position.
Function peek_next
peek_next
Returns a reference to the next value in the iterator. The iterator position is not updated.
Function drop
drop
Empties out the list and drops all values.
Last updated