Struct intrusive_containers::linked_list::LinkedList [] [src]

pub struct LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, L: Linkable<Container=T> {
    // some fields omitted
}

An intrusive doubly-linked list

Methods

impl<P, T, S, L> LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, S: Node<P, L>, L: Linkable<Container=T>

fn new() -> LinkedList<P, T, S, L>

Creates an empty LinkedList

fn append(&mut self, other: &mut LinkedList<P, T, S, L>)

Moves all elements from other to the end of the list.

This reuses all the nodes from other and moves them into self. After this operation, other becomes empty.

This operation should compute in O(1) time and O(1) memory.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut a = LinkedList::new();
let mut b = LinkedList::new();
a.push_back(Box::new(MyI32::new(1)));
a.push_back(Box::new(MyI32::new(2)));
b.push_back(Box::new(MyI32::new(3)));
b.push_back(Box::new(MyI32::new(4)));

a.append(&mut b);

for e in a.iter() {
    println!("{}", e); // prints 1, then 2, then 3, then 4
}
println!("{}", b.len()); // prints 0

fn iter<'a>(&'a self) -> Iter<'a, P, S, L>

Provides a forward iterator.

fn into_iter(self) -> IntoIter<P, T, S, L>

Consumes the list into an iterator yielding elements by value.

fn is_empty(&self) -> bool

Returns true if the LinkedList is empty

This operation should compute in O(1) time

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut dl = LinkedList::new();
assert!(dl.is_empty());

dl.push_front(Box::new(MyI32::new(1)));
assert!(!dl.is_empty());

fn len(&self) -> usize

Returns the length of the LinkedList.

This operation should compute in O(1) time.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut dl = LinkedList::new();

dl.push_front(Box::new(MyI32::new(2)));
assert_eq!(dl.len(), 1);

dl.push_front(Box::new(MyI32::new(1)));
assert_eq!(dl.len(), 2);

dl.push_back(Box::new(MyI32::new(3)));
assert_eq!(dl.len(), 3);

fn clear(&mut self)

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut dl = LinkedList::new();

dl.push_front(Box::new(MyI32::new(2)));
dl.push_front(Box::new(MyI32::new(1)));
assert_eq!(dl.len(), 2);
assert_eq!(dl.front(), Some(&1));

dl.clear();
assert_eq!(dl.len(), 0);
assert_eq!(dl.front(), None);

fn front(&self) -> Option<&P>

Provides a reference to the front element, or None if the list is empty.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut dl = LinkedList::new();
assert_eq!(dl.front(), None);

dl.push_front(Box::new(MyI32::new(1)));
assert_eq!(dl.front(), Some(&1));

fn front_mut(&mut self) -> Option<&mut P>

Provides a mutable reference to the front element, or None if the list is empty.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut dl = LinkedList::new();
assert_eq!(dl.front(), None);

dl.push_front(Box::new(MyI32::new(1)));
assert_eq!(dl.front(), Some(&1));

match dl.front_mut() {
    None => {},
    Some(x) => *x = 5,
}
assert_eq!(dl.front(), Some(&5));

fn back(&self) -> Option<&P>

Provides a reference to the back element, or None if the list is empty.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut dl = LinkedList::new();
assert_eq!(dl.back(), None);

dl.push_back(Box::new(MyI32::new(1)));
assert_eq!(dl.back(), Some(&1));

fn back_mut(&mut self) -> Option<&mut P>

Provides a mutable reference to the back element, or None if the list is empty.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut dl = LinkedList::new();
assert_eq!(dl.back(), None);

dl.push_back(Box::new(MyI32::new(1)));
assert_eq!(dl.back(), Some(&1));

match unsafe {dl.back_mut()} {
    None => {},
    Some(x) => *x = 5,
}
assert_eq!(dl.back(), Some(&5));

fn push_front(&mut self, elt: T)

Adds an element first in the list.

This operation should compute in O(1) time.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut d = LinkedList::new();
assert_eq!(d.pop_front(), None);

d.push_front(Box::new(MyI32::new(1)));
d.push_front(Box::new(MyI32::new(3)));
assert_eq!(d.pop_front(), Some(Box::new(MyI32::new(3))));
assert_eq!(d.pop_front(), Some(Box::new(MyI32::new(1))));
assert_eq!(d.pop_front(), None);

fn pop_front(&mut self) -> Option<T>

Removes the first element and returns it, or None if the list is empty.

This operation should compute in O(1) time.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut d = LinkedList::new();
assert_eq!(d.pop_front(), None);

d.push_front(Box::new(MyI32::new(1)));
d.push_front(Box::new(MyI32::new(3)));
assert_eq!(d.pop_front(), Some(Box::new(MyI32::new(3))));
assert_eq!(d.pop_front(), Some(Box::new(MyI32::new(1))));
assert_eq!(d.pop_front(), None);

fn push_back(&mut self, elt: T)

Appends an element to the back of a list

This operation should compute in O(1) time.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut d = LinkedList::new();
d.push_back(Box::new(MyI32::new(1)));
d.push_back(Box::new(MyI32::new(3)));
assert_eq!(&3, d.back().unwrap());

fn pop_back(&mut self) -> Option<T>

Removes the last element from a list and returns it, or None if it is empty.

This operation should compute in O(1) time

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut d = LinkedList::new();
assert_eq!(d.pop_back(), None);
d.push_back(Box::new(MyI32::new(1)));
d.push_back(Box::new(MyI32::new(3)));
assert_eq!(d.pop_back(), Some(Box::new(MyI32::new(3))));

fn split_off(&mut self, at: usize) -> LinkedList<P, T, S, L>

Splits the list into two at the given index. Returns everything after the given index, including the index.

Panics

Panics if at > len.

This operation should compute in O(n) time.

Examples

use intrusive_containers::LinkedList;

define_list_element!(MyI32 = i32 : MyLink);

let mut d = LinkedList::new();

d.push_front(Box::new(MyI32::new(1)));
d.push_front(Box::new(MyI32::new(2)));
d.push_front(Box::new(MyI32::new(3)));

let mut splitted = d.split_off(2);

assert_eq!(splitted.pop_front(), Some(Box::new(MyI32::new(1))));
assert_eq!(splitted.pop_front(), None);

impl<'a, P, T, S, L> LinkedList<P, T, S, L> where T: OwningPointer<Target=S> + 'a, S: Node<P, L> + 'a, L: Linkable<Container=T> + 'a

fn iter_mut(&'a mut self) -> IterMut<'a, P, T, S, L>

Provides a forward iterator with mutable references

This operation is marked unsafe because it would be possible to use mem::replace which would invalidate the links

Trait Implementations

impl<P, T, S, L> Default for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, S: Node<P, L>, L: Linkable<Container=T>

fn default() -> LinkedList<P, T, S, L>

impl<P, T, S, L> Clone for LinkedList<P, T, S, L> where T: OwningPointer<Target=S> + Clone, S: Node<P, L>, L: Linkable<Container=T>

fn clone(&self) -> LinkedList<P, T, S, L>

fn clone_from(&mut self, source: &Self)

impl<P, T, S, L> Debug for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, P: Debug, S: Node<P, L>, L: Linkable<Container=T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<P, T, S, L> Drop for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, L: Linkable<Container=T>

fn drop(&mut self)

impl<P, T, S, L> Hash for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, P: Hash, S: Node<P, L>, L: Linkable<Container=T>

fn hash<H: Hasher>(&self, state: &mut H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

impl<P, T, S, L> Extend<T> for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, S: Node<P, L>, L: Linkable<Container=T>

fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I)

impl<P, T, S, L> FromIterator<T> for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, S: Node<P, L>, L: Linkable<Container=T>

fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> LinkedList<P, T, S, L>

impl<P, T, S, L> IntoIterator for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, S: Node<P, L>, L: Linkable<Container=T>

type Item = T

type IntoIter = IntoIter<P, T, S, L>

fn into_iter(self) -> IntoIter<P, T, S, L>

impl<'a, P, T, S, L> IntoIterator for &'a LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, P: 'a, S: Node<P, L> + 'a, L: Linkable<Container=T> + 'a

type Item = &'a P

type IntoIter = Iter<'a, P, S, L>

fn into_iter(self) -> Iter<'a, P, S, L>

impl<'a, P, T, S, L> IntoIterator for &'a mut LinkedList<P, T, S, L> where T: OwningPointer<Target=S> + 'a, P: 'a, S: Node<P, L> + 'a, L: Linkable<Container=T> + 'a

type Item = &'a mut P

type IntoIter = IterMut<'a, P, T, S, L>

fn into_iter(self) -> IterMut<'a, P, T, S, L>

impl<P, T, S, L> PartialEq for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, P: PartialEq, S: Node<P, L>, L: Linkable<Container=T>

fn eq(&self, other: &LinkedList<P, T, S, L>) -> bool

fn ne(&self, other: &LinkedList<P, T, S, L>) -> bool

impl<P, T, S, L> Eq for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, P: Eq, S: Node<P, L>, L: Linkable<Container=T>

impl<P, T, S, L> PartialOrd for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, P: PartialOrd, S: Node<P, L>, L: Linkable<Container=T>

fn partial_cmp(&self, other: &LinkedList<P, T, S, L>) -> Option<Ordering>

fn lt(&self, other: &Rhs) -> bool

fn le(&self, other: &Rhs) -> bool

fn gt(&self, other: &Rhs) -> bool

fn ge(&self, other: &Rhs) -> bool

impl<P, T, S, L> Ord for LinkedList<P, T, S, L> where T: OwningPointer<Target=S>, P: Ord, S: Node<P, L>, L: Linkable<Container=T>

fn cmp(&self, other: &LinkedList<P, T, S, L>) -> Ordering