orx_linked_list/list/mutate.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
use super::List;
use crate::variant::ListVariant;
use orx_pinned_vec::PinnedVec;
use orx_selfref_col::MemoryPolicy;
impl<V, M> List<V, M>
where
V: ListVariant,
M: MemoryPolicy<V>,
{
/// Clears the list removing all elements.
///
/// # Examples
///
/// ```rust
/// use orx_linked_list::*;
///
/// let mut list = DoublyList::new();
///
/// list.push_front('b');
/// list.push_back('c');
/// list.push_front('a');
///
/// assert_eq!(3, list.len());
///
/// list.clear();
/// assert!(list.is_empty());
/// assert!(list.front().is_none());
/// ```
#[inline(always)]
pub fn clear(&mut self) {
self.0.clear();
}
/// Returns an arbitrary order iterator of mutable references to elements of the list from front to back.
///
/// Note that the iterator created by `iter_mut_x` is often faster than that created by `iter_mut`;
/// and hence, can be preferred whenever the iteration order does not matter.
///
/// # Examples
///
/// ```rust
/// use orx_linked_list::*;
///
/// let mut list = DoublyList::new();
///
/// list.push_front(2);
/// list.push_front(1);
/// list.push_front(0);
/// assert!(list.eq_to_iter_vals([0, 1, 2]));
///
/// for x in list.iter_mut_x() {
/// *x += 40;
/// }
///
/// assert!(list.eq_to_iter_vals([40, 41, 42]));
/// ```
pub fn iter_mut_x(&mut self) -> impl Iterator<Item = &mut V::Item> {
self.0.nodes_mut().iter_mut().filter_map(|x| x.data_mut())
}
}