A doubly-linked list. Supports O(1) head, tail, count, push, pop, etc.
Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.
DListLink
DList
DListNode
for DListNode<T>
for DListNode<T>
for DList<T>
for DList<T>
for DList<T>
DList
- Creates a new, empty dlist.concat
- Produce a list from a list of lists, leaving no elements behind in the inputfrom_elem
- Creates a new dlist with a single elementfrom_vec
new_dlist_node
- Creates a new dlist node with the given data.DListLink
type DListLink<T> = Option<DListNode<T>>
DList
DList_(@{mut size: uint, mut hd: DListLink<T>, mut tl: DListLink<T>,})
DListNode
pub DListNode(@{data: T, mut linked: bool, mut prev: DListLink<T>, mut next: DListLink<T>,})
DListNode<T>
assert_links
fn assert_links()
DListNode<T>
next_link
fn next_link() -> Option<DListNode<T>>
Get the next node in the list, if there is one.
next_node
fn next_node() -> DListNode<T>
Get the next node in the list, failing if there isn't one.
prev_link
fn prev_link() -> Option<DListNode<T>>
Get the previous node in the list, if there is one.
prev_node
fn prev_node() -> DListNode<T>
Get the previous node in the list, failing if there isn't one.
DList<T>
new_link
fn new_link(data: T) -> DListLink<T>
assert_mine
fn assert_mine(nobe: DListNode<T>)
make_mine
fn make_mine(nobe: DListNode<T>)
link
fn link(before: DListLink<T>, after: DListLink<T>)
unlink
fn unlink(nobe: DListNode<T>)
add_head
fn add_head(nobe: DListLink<T>)
add_tail
fn add_tail(nobe: DListLink<T>)
insert_left
fn insert_left(nobe: DListLink<T>, neighbour: DListNode<T>)
insert_right
fn insert_right(neighbour: DListNode<T>, nobe: DListLink<T>)
DList<T>
len
fn len() -> uint
Get the size of the list. O(1).
is_empty
fn is_empty() -> bool
Returns true if the list is empty. O(1).
is_not_empty
fn is_not_empty() -> bool
Returns true if the list is not empty. O(1).
push_head
fn push_head(data: T)
Add data to the head of the list. O(1).
push_head_n
fn push_head_n(data: T) -> DListNode<T>
Add data to the head of the list, and get the new containing node. O(1).
push
fn push(data: T)
Add data to the tail of the list. O(1).
push_n
fn push_n(data: T) -> DListNode<T>
Add data to the tail of the list, and get the new containing node. O(1).
insert_before
fn insert_before(data: T, neighbour: DListNode<T>)
Insert data into the middle of the list, left of the given node. O(1).
insert_n_before
fn insert_n_before(nobe: DListNode<T>, neighbour: DListNode<T>)
Insert an existing node in the middle of the list, left of the given node. O(1).
insert_before_n
fn insert_before_n(data: T, neighbour: DListNode<T>) -> DListNode<T>
Insert data in the middle of the list, left of the given node, and get its containing node. O(1).
insert_after
fn insert_after(data: T, neighbour: DListNode<T>)
Insert data into the middle of the list, right of the given node. O(1).
insert_n_after
fn insert_n_after(nobe: DListNode<T>, neighbour: DListNode<T>)
Insert an existing node in the middle of the list, right of the given node. O(1).
insert_after_n
fn insert_after_n(data: T, neighbour: DListNode<T>) -> DListNode<T>
Insert data in the middle of the list, right of the given node, and get its containing node. O(1).
pop_n
fn pop_n() -> Option<DListNode<T>>
Remove a node from the head of the list. O(1).
pop_tail_n
fn pop_tail_n() -> Option<DListNode<T>>
Remove a node from the tail of the list. O(1).
peek_n
fn peek_n() -> Option<DListNode<T>>
Get the node at the list's head. O(1).
peek_tail_n
fn peek_tail_n() -> Option<DListNode<T>>
Get the node at the list's tail. O(1).
head_n
fn head_n() -> DListNode<T>
Get the node at the list's head, failing if empty. O(1).
tail_n
fn tail_n() -> DListNode<T>
Get the node at the list's tail, failing if empty. O(1).
remove
fn remove(nobe: DListNode<T>)
Remove a node from anywhere in the list. O(1).
append
fn append(them: DList<T>)
Empty another list onto the end of this list, joining this list's tail to the other list's head. O(1).
prepend
fn prepend(them: DList<T>)
Empty another list onto the start of this list, joining the other list's tail to this list's head. O(1).
reverse
fn reverse()
Reverse the list's elements in place. O(n).
clear
fn clear()
Remove everything from the list. This is important because the cyclic links won't otherwise be automatically refcounted-collected. O(n).
each_node
fn each_node(f: &fn(DListNode<T>) -> bool)
Iterate over nodes.
assert_consistent
fn assert_consistent()
Check data structure integrity. O(n).
DList<T>
pop
fn pop() -> Option<T>
Remove data from the head of the list. O(1).
pop_tail
fn pop_tail() -> Option<T>
Remove data from the tail of the list. O(1).
peek
fn peek() -> Option<T>
Get data at the list's head. O(1).
peek_tail
fn peek_tail() -> Option<T>
Get data at the list's tail. O(1).
head
fn head() -> T
Get data at the list's head, failing if empty. O(1).
tail
fn tail() -> T
Get data at the list's tail, failing if empty. O(1).
to_vec
fn to_vec() -> ~[T]
Get the elements of the list as a vector. O(n).
DList
fn DList<T>() -> DList<T>
Creates a new, empty dlist.
concat
fn concat<T>(lists: DList<DList<T>>) -> DList<T>
Produce a list from a list of lists, leaving no elements behind in the input. O(number of sub-lists).
from_elem
fn from_elem<T>(data: T) -> DList<T>
Creates a new dlist with a single element
from_vec
fn from_vec<T: Copy>(vec: &[T]) -> DList<T>
new_dlist_node
fn new_dlist_node<T>(data: T) -> DListNode<T>
Creates a new dlist node with the given data.