Struct ixlist::List [] [src]

pub struct List<T> { /* fields omitted */ }

List is a doubly linked list stored in one contiguous allocation.

Features

  • O(1) insert and remove both at front and back.
  • O(1) insert anywhere if you have a cursor to that position.
  • Only use of unsafe is an unavoidable use for IterMut.

Implementation

It is similar to a linked list in a language like C, except instead of pointers we use indices into a backing vector.

The list is just a vector, and indices to the head and tail:

struct List<T> {
    /// Head, Tail
    link: [usize; 2],
    nodes: Vec<Node<T>>,
}

The list node is represented like this:

struct Node<T> {
    /// Prev, Next.
    link: [usize; 2],
    value: T,
}

The link arrays contain the vector indices of the previous and next node. We use an array so that symmetries in front/back or prev/next can be used easily in the code — it's nice if we can write just one push and one pop method instead of two.

There is a constant to denote a “null” index, and that's usize's max value. We don't always have to check for this case, we can just access the nodes vector using .get() or .get_mut(); a “null” link is the None case.

To do

List could be generic over the index type, so that internal prev/node links can use less space than a regular pointer (can be u16 or u32 index).

With some cleanup we can use unchecked indexing — but it's not guaranteed to make any difference.

Methods

impl<T> List<T>
[src]

[src]

Create a new List.

[src]

Create a new List with specified capacity.

[src]

Return the number of elements in the List.

[src]

Return an iterator.

[src]

Return an iterator.

[src]

Return a new cursor, focused before the head of the List.

[src]

Insert an element at the beginning of the List.

[src]

Insert an element at the end of the List.

[src]

Remove the element at the beginning of the List and return it, or return None if the List is empty.

[src]

Remove the element at the end of the List and return it, or return None if the List is empty.

[src]

Reorder internal datastructure into traversal order.

Trait Implementations

impl<T: Clone> Clone for List<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Debug> Debug for List<T>
[src]

[src]

Formats the value using the given formatter.

impl<'a, T> FromIterator<T> for List<T>
[src]

[src]

Creates a value from an iterator. Read more

impl<'a, T> Extend<T> for List<T>
[src]

[src]

Extends a collection with the contents of an iterator. Read more