Struct std::collections::LinkedList
1.0.0 · source · pub struct LinkedList<T, A = Global>where
A: Allocator,{ /* private fields */ }
Expand description
Implementations§
source§impl<T> LinkedList<T, Global>
impl<T> LinkedList<T, Global>
const: 1.39.0 · sourcepub const fn new() -> LinkedList<T, Global>
pub const fn new() -> LinkedList<T, Global>
sourcepub fn append(&mut self, other: &mut LinkedList<T, Global>)
pub fn append(&mut self, other: &mut LinkedList<T, Global>)
将所有元素从 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> LinkedList<T, A>where
A: Allocator,
impl<T, A> LinkedList<T, A>where A: Allocator,
sourcepub const fn new_in(alloc: A) -> LinkedList<T, A>
🔬This is a nightly-only experimental API. (allocator_api
#32838)
pub const fn new_in(alloc: A) -> LinkedList<T, A>
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> Clone for LinkedList<T, A>where
T: Clone,
A: Allocator + Clone,
impl<T, A> Clone for LinkedList<T, A>where T: Clone, A: Allocator + Clone,
source§fn clone(&self) -> LinkedList<T, A>
fn clone(&self) -> LinkedList<T, A>
返回值的副本。 Read more
source§fn clone_from(&mut self, other: &LinkedList<T, A>)
fn clone_from(&mut self, other: &LinkedList<T, A>)
从
source
执行复制分配。 Read moresource§impl<T> Default for LinkedList<T, Global>
impl<T> Default for LinkedList<T, Global>
source§fn default() -> LinkedList<T, Global>
fn default() -> LinkedList<T, Global>
创建一个空的 LinkedList<T>
。
source§impl<T, A> Drop for LinkedList<T, A>where
A: Allocator,
impl<T, A> Drop for LinkedList<T, A>where A: Allocator,
1.2.0 · source§impl<'a, T, A> Extend<&'a T> for LinkedList<T, A>where
T: 'a + Copy,
A: Allocator,
impl<'a, T, A> Extend<&'a T> for LinkedList<T, A>where T: 'a + Copy, A: Allocator,
source§fn extend_one(&mut self, _: &'a T)
fn extend_one(&mut self, _: &'a T)
🔬This is a nightly-only experimental API. (
extend_one
#72631)用一个元素扩展一个集合。
source§impl<T, A> Extend<T> for LinkedList<T, A>where
A: Allocator,
impl<T, A> Extend<T> for LinkedList<T, A>where A: Allocator,
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = T>,
使用迭代器的内容扩展集合。 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, Global>
impl<T> FromIterator<T> for LinkedList<T, Global>
source§fn from_iter<I>(iter: I) -> LinkedList<T, Global>where
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> LinkedList<T, Global>where I: IntoIterator<Item = T>,
从迭代器创建一个值。 Read more
source§impl<'a, T, A> IntoIterator for &'a LinkedList<T, A>where
A: Allocator,
impl<'a, T, A> IntoIterator for &'a LinkedList<T, A>where A: Allocator,
source§impl<'a, T, A> IntoIterator for &'a mut LinkedList<T, A>where
A: Allocator,
impl<'a, T, A> IntoIterator for &'a mut LinkedList<T, A>where A: Allocator,
source§impl<T, A> IntoIterator for LinkedList<T, A>where
A: Allocator,
impl<T, A> IntoIterator for LinkedList<T, A>where A: Allocator,
source§impl<T, A> Ord for LinkedList<T, A>where
T: Ord,
A: Allocator,
impl<T, A> Ord for LinkedList<T, A>where T: Ord, A: Allocator,
source§fn cmp(&self, other: &LinkedList<T, A>) -> Ordering
fn cmp(&self, other: &LinkedList<T, A>) -> Ordering
source§impl<T, A> PartialEq<LinkedList<T, A>> for LinkedList<T, A>where
T: PartialEq<T>,
A: Allocator,
impl<T, A> PartialEq<LinkedList<T, A>> for LinkedList<T, A>where T: PartialEq<T>, A: Allocator,
source§fn eq(&self, other: &LinkedList<T, A>) -> bool
fn eq(&self, other: &LinkedList<T, A>) -> bool
此方法测试
self
和 other
值是否相等,并由 ==
使用。source§fn ne(&self, other: &LinkedList<T, A>) -> bool
fn ne(&self, other: &LinkedList<T, A>) -> bool
此方法测试
!=
。
默认实现几乎总是足够的,并且不应在没有充分理由的情况下被覆盖。source§impl<T, A> PartialOrd<LinkedList<T, A>> for LinkedList<T, A>where
T: PartialOrd<T>,
A: Allocator,
impl<T, A> PartialOrd<LinkedList<T, A>> for LinkedList<T, A>where T: PartialOrd<T>, A: Allocator,
source§fn partial_cmp(&self, other: &LinkedList<T, A>) -> Option<Ordering>
fn partial_cmp(&self, other: &LinkedList<T, A>) -> Option<Ordering>
impl<T, A> Eq for LinkedList<T, A>where T: Eq, A: Allocator,
impl<T, A> Send for LinkedList<T, A>where T: Send, A: Allocator + Send,
impl<T, A> Sync for LinkedList<T, A>where T: Sync, A: Allocator + Sync,
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