A doubly-linked list. Supports O(1) head, tail, count, push, pop, etc.

Safety note

Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.

Enum DList

Variants

Enum DListNode

Variants

Implementation for DListNode<T>

Implementation for DListNode<T>

Method next_node

fn next_node() -> DListNode<T>

Get the next node in the list, failing if there isn't one.

Method prev_node

fn prev_node() -> DListNode<T>

Get the previous node in the list, failing if there isn't one.

Implementation for DList<T>

Method assert_mine

fn assert_mine(nobe: DListNode<T>)

Method make_mine

fn make_mine(nobe: DListNode<T>)

Method add_head

fn add_head(nobe: DListLink<T>)

Method add_tail

fn add_tail(nobe: DListLink<T>)

Method insert_left

fn insert_left(nobe: DListLink<T>, neighbour: DListNode<T>)

Method insert_right

fn insert_right(neighbour: DListNode<T>, nobe: DListLink<T>)

Implementation for DList<T>

Method len

fn len() -> uint

Get the size of the list. O(1).

Method is_empty

fn is_empty() -> bool

Returns true if the list is empty. O(1).

Method is_not_empty

fn is_not_empty() -> bool

Returns true if the list is not empty. O(1).

Method push_head

fn push_head(data: T)

Add data to the head of the list. O(1).

Method 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).

Method push

fn push(data: T)

Add data to the tail of the list. O(1).

Method 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).

Method 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).

Method 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).

Method 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).

Method 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).

Method 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).

Method 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).

Method pop_n

fn pop_n() -> Option<DListNode<T>>

Remove a node from the head of the list. O(1).

Method pop_tail_n

fn pop_tail_n() -> Option<DListNode<T>>

Remove a node from the tail of the list. O(1).

Method peek_n

fn peek_n() -> Option<DListNode<T>>

Get the node at the list's head. O(1).

Method peek_tail_n

fn peek_tail_n() -> Option<DListNode<T>>

Get the node at the list's tail. O(1).

Method head_n

fn head_n() -> DListNode<T>

Get the node at the list's head, failing if empty. O(1).

Method tail_n

fn tail_n() -> DListNode<T>

Get the node at the list's tail, failing if empty. O(1).

Method remove

fn remove(nobe: DListNode<T>)

Remove a node from anywhere in the list. O(1).

Method 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).

Method 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).

Method reverse

fn reverse()

Reverse the list's elements in place. O(n).

Method clear

fn clear()

Remove everything from the list. This is important because the cyclic links won't otherwise be automatically refcounted-collected. O(n).

Method each_node

fn each_node(f: &fn(DListNode<T>) -> bool)

Iterate over nodes.

Method assert_consistent

fn assert_consistent()

Check data structure integrity. O(n).

Implementation for DList<T>

Method pop

fn pop() -> Option<T>

Remove data from the head of the list. O(1).

Method pop_tail

fn pop_tail() -> Option<T>

Remove data from the tail of the list. O(1).

Method peek

fn peek() -> Option<T>

Get data at the list's head. O(1).

Method peek_tail

fn peek_tail() -> Option<T>

Get data at the list's tail. O(1).

Method head

fn head() -> T

Get data at the list's head, failing if empty. O(1).

Method tail

fn tail() -> T

Get data at the list's tail, failing if empty. O(1).

Method to_vec

fn to_vec() -> ~[T]

Get the elements of the list as a vector. O(n).

Function DList

fn DList<T>() -> DList<T>

Creates a new, empty dlist.

Function 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).

Function from_elem

fn from_elem<T>(data: T) -> DList<T>

Creates a new dlist with a single element

Function from_vec

fn from_vec<T: Copy>(vec: &[T]) -> DList<T>

Function new_dlist_node

fn new_dlist_node<T>(data: T) -> DListNode<T>

Creates a new dlist node with the given data.