Struct drone_core::sync::linked_list::LinkedList[][src]

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

A lock-free singly-linked list.

Implementations

impl<T> LinkedList<T>[src]

pub const fn new() -> Self[src]

Creates an empty LinkedList.

Examples

use drone_core::sync::LinkedList;

let list: LinkedList<u32> = LinkedList::new();

pub fn is_empty(&self) -> bool[src]

Returns true if the LinkedList is empty.

This operation should compute in O(1) time.

Examples

use drone_core::sync::LinkedList;

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

list.push("foo");
assert!(!list.is_empty());

pub fn push(&self, data: T)[src]

Adds an element first in the list.

This operation should compute in O(1) time.

Examples

use drone_core::sync::LinkedList;

let list = LinkedList::new();

list.push(2);
list.push(1);
assert_eq!(list.pop().unwrap(), 1);
assert_eq!(list.pop().unwrap(), 2);

pub unsafe fn push_raw(&self, node: *mut Node<T>)[src]

Adds a pre-allocated element first in the list.

This operation should compute in O(1) time.

Examples

use drone_core::sync::linked_list::{LinkedList, Node};

let list = LinkedList::new();

let foo = Box::into_raw(Box::new(Node::from("foo")));
unsafe { list.push_raw(foo) };
assert_eq!(unsafe { **foo }, "foo");

Safety

The node parameter must point to a valid allocation. Other list methods, which drop nodes in-place, assume that node is created using Box::from_raw.

pub fn pop(&self) -> Option<T>[src]

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

This operation should compute in O(1) time.

Examples

use drone_core::sync::LinkedList;

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

d.push(1);
d.push(3);
assert_eq!(d.pop(), Some(3));
assert_eq!(d.pop(), Some(1));
assert_eq!(d.pop(), None);

pub unsafe fn pop_raw(&self) -> Option<*mut Node<T>>[src]

Removes the first element and returns a raw pointer to it, or None if the list is empty.

This operation should compute in O(1) time.

Examples

use drone_core::sync::linked_list::{LinkedList, Node};

let list = LinkedList::new();

let foo = Box::into_raw(Box::new(Node::from("foo")));
unsafe {
    list.push_raw(foo);
    let foo = list.pop_raw().unwrap();
    list.push_raw(foo);
}

assert_eq!(unsafe { **foo }, "foo");

Safety

It’s responsibility of the caller to de-allocate the node.

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Notable traits for IterMut<'a, T>

impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
[src]

Provides a forward iterator with mutable references.

Examples

use drone_core::sync::LinkedList;

let mut list: LinkedList<u32> = LinkedList::new();

list.push(0);
list.push(1);
list.push(2);

for element in list.iter_mut() {
    *element += 10;
}

let mut iter = list.iter_mut();
assert_eq!(iter.next(), Some(&mut 12));
assert_eq!(iter.next(), Some(&mut 11));
assert_eq!(iter.next(), Some(&mut 10));
assert_eq!(iter.next(), None);

pub unsafe fn iter_mut_unchecked(&self) -> IterMut<'_, T>

Notable traits for IterMut<'a, T>

impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
[src]

Unsafe variant of [iter_mut] with non-mutable self.

Safety

While the returned iterator is alive:

  • Nodes shouldn’t be removed.
  • No other methods that produce mutable references (including this method) should be called.

pub fn drain_filter<'a, F: 'a>(
    &'a mut self,
    filter: F
) -> DrainFilter<'_, T, impl FnMut(*mut Node<T>) -> bool>

Notable traits for DrainFilter<'_, T, F>

impl<T, F> Iterator for DrainFilter<'_, T, F> where
    F: FnMut(*mut Node<T>) -> bool, 
type Item = T;
where
    F: FnMut(&mut T) -> bool, 
[src]

Creates an iterator which uses a closure to determine if an element should be removed.

If the closure returns true, then the element is removed and yielded. If the closure returns false, the element will remain in the list and will not be yielded by the iterator.

Note that drain_filter lets you mutate every element in the filter closure, regardless of whether you choose to keep or remove it.

Examples

Splitting a list into evens and odds, reusing the original list:

use drone_core::sync::LinkedList;

let mut numbers: LinkedList<u32> = LinkedList::new();
numbers.extend(&[1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]);

let evens = numbers.drain_filter(|x| *x % 2 == 0).collect::<LinkedList<_>>();
let odds = numbers;

assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![2, 4, 6, 8, 14]);
assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![15, 13, 11, 9, 5, 3, 1]);

pub unsafe fn drain_filter_raw<F>(
    &self,
    filter: F
) -> DrainFilterRaw<'_, T, impl FnMut(*mut Node<T>) -> bool>

Notable traits for DrainFilterRaw<'_, T, F>

impl<T, F> Iterator for DrainFilterRaw<'_, T, F> where
    F: FnMut(*mut Node<T>) -> bool, 
type Item = *mut Node<T>;
where
    F: FnMut(*mut Node<T>) -> bool, 
[src]

Raw variant of [drain_filter].

Safety

It’s responsibility of the caller to de-allocate returned nodes.

While the returned iterator is alive:

  • Nodes shouldn’t be removed.
  • No other methods that produce mutable references (including this method) should be called.

Trait Implementations

impl<T> Drop for LinkedList<T>[src]

impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T>[src]

impl<T> Extend<T> for LinkedList<T>[src]

impl<T> FromIterator<T> for LinkedList<T>[src]

impl<T> IntoIterator for LinkedList<T>[src]

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

type Item = T

The type of the elements being iterated over.

impl<T> Sync for LinkedList<T>[src]

Auto Trait Implementations

impl<T> Send for LinkedList<T>

impl<T> Unpin for LinkedList<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.