Struct alloc::collections::linked_list::LinkedList
1.0.0 · source · pub struct LinkedList<T, A: Allocator = Global> { /* private fields */ }
Expand description
Implementations§
source§impl<T> LinkedList<T>
impl<T> LinkedList<T>
sourcepub fn append(&mut self, other: &mut Self)
pub fn append(&mut self, other: &mut Self)
将所有元素从 other
移动到列表的末尾。
这将重用 other
中的所有节点并将它们移到 self
中。
完成此操作后,other
变为空。
此操作应在 O(1) 时间和 O(1) 内存中进行计算。
Examples
use std::collections::LinkedList;
let mut list1 = LinkedList::new();
list1.push_back('a');
let mut list2 = LinkedList::new();
list2.push_back('b');
list2.push_back('c');
list1.append(&mut list2);
let mut iter = list1.iter();
assert_eq!(iter.next(), Some(&'a'));
assert_eq!(iter.next(), Some(&'b'));
assert_eq!(iter.next(), Some(&'c'));
assert!(iter.next().is_none());
assert!(list2.is_empty());
Runsource§impl<T, A: Allocator> LinkedList<T, A>
impl<T, A: Allocator> LinkedList<T, A>
sourcepub const fn new_in(alloc: A) -> Self
🔬This is a nightly-only experimental API. (allocator_api
#32838)
pub const fn new_in(alloc: A) -> Self
allocator_api
#32838)sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
提供一个正向迭代器。
Examples
use std::collections::LinkedList;
let mut list: LinkedList<u32> = LinkedList::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
let mut iter = list.iter();
assert_eq!(iter.next(), Some(&0));
assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), None);
Runsourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
提供具有可变引用的正向迭代器。
Examples
use std::collections::LinkedList;
let mut list: LinkedList<u32> = LinkedList::new();
list.push_back(0);
list.push_back(1);
list.push_back(2);
for element in list.iter_mut() {
*element += 10;
}
let mut iter = list.iter();
assert_eq!(iter.next(), Some(&10));
assert_eq!(iter.next(), Some(&11));
assert_eq!(iter.next(), Some(&12));
assert_eq!(iter.next(), None);
Runsourcepub fn cursor_front(&self) -> Cursor<'_, T, A>
🔬This is a nightly-only experimental API. (linked_list_cursors
#58533)
pub fn cursor_front(&self) -> Cursor<'_, T, A>
linked_list_cursors
#58533)在前元素处提供游标。
如果列表为空,则游标指向 “ghost” 非元素。
sourcepub fn cursor_front_mut(&mut self) -> CursorMut<'_, T, A>
🔬This is a nightly-only experimental API. (linked_list_cursors
#58533)
pub fn cursor_front_mut(&mut self) -> CursorMut<'_, T, A>
linked_list_cursors
#58533)在前面的元素上为游标提供编辑操作。
如果列表为空,则游标指向 “ghost” 非元素。
sourcepub fn cursor_back(&self) -> Cursor<'_, T, A>
🔬This is a nightly-only experimental API. (linked_list_cursors
#58533)
pub fn cursor_back(&self) -> Cursor<'_, T, A>
linked_list_cursors
#58533)在 back 元素上提供游标。
如果列表为空,则游标指向 “ghost” 非元素。
sourcepub fn cursor_back_mut(&mut self) -> CursorMut<'_, T, A>
🔬This is a nightly-only experimental API. (linked_list_cursors
#58533)
pub fn cursor_back_mut(&mut self) -> CursorMut<'_, T, A>
linked_list_cursors
#58533)在 back 元素上为游标提供编辑操作。
如果列表为空,则游标指向 “ghost” 非元素。
sourcepub fn push_front(&mut self, elt: T)
pub fn push_front(&mut self, elt: T)
sourcepub fn split_off(&mut self, at: usize) -> LinkedList<T, A>where
A: Clone,
pub fn split_off(&mut self, at: usize) -> LinkedList<T, A>where A: Clone,
在给定的索引处将列表分为两部分。 返回给定索引之后的所有内容,包括索引。
此运算应在 O(n) 时间中计算。
Panics
如果为 at > len
,就会出现 panics。
Examples
use std::collections::LinkedList;
let mut d = LinkedList::new();
d.push_front(1);
d.push_front(2);
d.push_front(3);
let mut split = d.split_off(2);
assert_eq!(split.pop_front(), Some(1));
assert_eq!(split.pop_front(), None);
Runsourcepub fn remove(&mut self, at: usize) -> T
🔬This is a nightly-only experimental API. (linked_list_remove
#69210)
pub fn remove(&mut self, at: usize) -> T
linked_list_remove
#69210)删除给定索引处的元素并返回它。
此运算应在 O(n) 时间中计算。
Panics
如果 >= len 就会出现 panics
Examples
#![feature(linked_list_remove)]
use std::collections::LinkedList;
let mut d = LinkedList::new();
d.push_front(1);
d.push_front(2);
d.push_front(3);
assert_eq!(d.remove(1), 2);
assert_eq!(d.remove(0), 3);
assert_eq!(d.remove(0), 1);
Runsourcepub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F, A> ⓘwhere
F: FnMut(&mut T) -> bool,
🔬This is a nightly-only experimental API. (drain_filter
#43244)
pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F, A> ⓘwhere F: FnMut(&mut T) -> bool,
drain_filter
#43244)创建一个迭代器,该迭代器使用闭包确定是否应删除元素。
如果闭包返回 true,则删除并生成元素。 如果闭包返回 false,则该元素将保留在列表中,并且不会由迭代器产生。
请注意,无论选择保留还是删除 drain_filter
,您都可以对过滤器闭包中的每个元素进行可变的。
Examples
将列表分成偶数和几率,重新使用原始列表:
#![feature(drain_filter)]
use std::collections::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![1, 3, 5, 9, 11, 13, 15]);
RunTrait Implementations§
source§impl<T, A: Allocator> Drop for LinkedList<T, A>
impl<T, A: Allocator> Drop for LinkedList<T, A>
1.2.0 · source§impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for LinkedList<T, A>
impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for LinkedList<T, A>
source§fn extend_one(&mut self, elem: &'a T)
fn extend_one(&mut self, elem: &'a T)
🔬This is a nightly-only experimental API. (
extend_one
#72631)用一个元素扩展一个集合。
source§impl<T, A: Allocator> Extend<T> for LinkedList<T, A>
impl<T, A: Allocator> Extend<T> for LinkedList<T, A>
source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
使用迭代器的内容扩展集合。 Read more
source§fn extend_one(&mut self, elem: T)
fn extend_one(&mut self, elem: T)
🔬This is a nightly-only experimental API. (
extend_one
#72631)用一个元素扩展一个集合。
source§impl<T> FromIterator<T> for LinkedList<T>
impl<T> FromIterator<T> for LinkedList<T>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
从迭代器创建一个值。 Read more
source§impl<'a, T, A: Allocator> IntoIterator for &'a LinkedList<T, A>
impl<'a, T, A: Allocator> IntoIterator for &'a LinkedList<T, A>
source§impl<'a, T, A: Allocator> IntoIterator for &'a mut LinkedList<T, A>
impl<'a, T, A: Allocator> IntoIterator for &'a mut LinkedList<T, A>
source§impl<T, A: Allocator> IntoIterator for LinkedList<T, A>
impl<T, A: Allocator> IntoIterator for LinkedList<T, A>
source§impl<T: PartialEq, A: Allocator> PartialEq<LinkedList<T, A>> for LinkedList<T, A>
impl<T: PartialEq, A: Allocator> PartialEq<LinkedList<T, A>> for LinkedList<T, A>
source§impl<T: PartialOrd, A: Allocator> PartialOrd<LinkedList<T, A>> for LinkedList<T, A>
impl<T: PartialOrd, A: Allocator> PartialOrd<LinkedList<T, A>> for LinkedList<T, A>
impl<T: Eq, A: Allocator> Eq for LinkedList<T, A>
impl<T: Send, A: Allocator + Send> Send for LinkedList<T, A>
impl<T: Sync, A: Allocator + Sync> Sync for LinkedList<T, A>
Auto Trait Implementations§
impl<T, A> RefUnwindSafe for LinkedList<T, A>where A: RefUnwindSafe, T: RefUnwindSafe,
impl<T, A> Unpin for LinkedList<T, A>where A: Unpin,
impl<T, A> UnwindSafe for LinkedList<T, A>where A: UnwindSafe, T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
从拥有的值中借用。 Read more