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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
#[cfg(not(feature = "std"))] use alloc::collections::LinkedList; #[cfg(feature = "std")] use std::collections::LinkedList; use super::super::*; impl<T> Collection for LinkedList<T> { #[inline(always)] fn len(&self) -> usize { LinkedList::<T>::len(self) } } impl<T> CollectionMut for LinkedList<T> { fn clear(&mut self) { while let Some(_) = LinkedList::<T>::pop_front(self) {} } } impl<T> Create<T> for LinkedList<T> { #[inline(always)] fn create() -> Self { LinkedList::<T>::new() } #[inline(always)] fn create_with_capacity(_: usize) -> Self { LinkedList::<T>::new() } #[inline(always)] fn add_element(mut self, value: T) -> Self { LinkedList::<T>::push(&mut self, value); self } } impl<T> Deque<T> for LinkedList<T> { #[inline(always)] fn push_front(&mut self, element: T) { LinkedList::<T>::push_front(self, element) } #[inline(always)] fn push_back(&mut self, element: T) { LinkedList::<T>::push_back(self, element) } #[inline(always)] fn pop_front(&mut self) -> Option<T> { LinkedList::<T>::pop_front(self) } #[inline(always)] fn pop_back(&mut self) -> Option<T> { LinkedList::<T>::pop_back(self) } #[inline(always)] fn front(&self) -> Option<&T> { LinkedList::<T>::front(self) } #[inline(always)] fn back(&self) -> Option<&T> { LinkedList::<T>::back(self) } #[inline(always)] fn front_mut(&mut self) -> Option<&mut T> { LinkedList::<T>::front_mut(self) } #[inline(always)] fn back_mut(&mut self) -> Option<&mut T> { LinkedList::<T>::back_mut(self) } } impl<T> Stack<T> for LinkedList<T> { #[inline(always)] fn push(&mut self, element: T) { LinkedList::<T>::push_back(self, element) } #[inline(always)] fn pop(&mut self) -> Option<T> { LinkedList::<T>::pop_back(self) } #[inline(always)] fn top(&self) -> Option<&T> { LinkedList::<T>::back(self) } #[inline(always)] fn top_mut(&mut self) -> Option<&mut T> { LinkedList::<T>::back_mut(self) } } impl<T> Queue<T> for LinkedList<T> { #[inline(always)] fn enqueue(&mut self, element: T) { LinkedList::<T>::push_back(self, element) } #[inline(always)] fn dequeue(&mut self) -> Option<T> { LinkedList::<T>::pop_front(self) } #[inline(always)] fn peek(&self) -> Option<&T> { LinkedList::<T>::front(self) } #[inline(always)] fn peek_mut(&mut self) -> Option<&mut T> { LinkedList::<T>::front_mut(self) } } impl<T> Insert<usize, T> for LinkedList<T> { type Output = (); #[inline] fn insert(&mut self, index: usize, element: T) { if index == 0 { LinkedList::<T>::push_front(self, element); } else if index < LinkedList::<T>::len(self) { let mut front = LinkedList::<T>::split_off(self, index); front.push_back(element); LinkedList::<T>::append(self, &mut front); } else { LinkedList::<T>::push_back(self, element); } } } impl<T> Add<T> for LinkedList<T> { type Output = (); #[inline(always)] fn add(&mut self, v: T) -> Self::Output { LinkedList::<T>::push_front(self, v); } } impl<T> Remove<usize> for LinkedList<T> { type Output = T; #[inline] fn remove(&mut self, index: usize) -> Self::Output { if index == 0 { LinkedList::<T>::pop_front(self).expect("index out of bounds") } else if index < LinkedList::<T>::len(self) { let mut front = LinkedList::<T>::split_off(self, index); let element = front.pop_back(); LinkedList::<T>::append(self, &mut front); element.expect("index out of bounds") } else { LinkedList::<T>::pop_back(self).expect("index out of bounds") } } } impl<T> Get<usize> for LinkedList<T> { type Output = T; #[inline] fn get(&self, index: usize) -> Option<&Self::Output> { LinkedList::<T>::iter(self).nth(index) } } impl<T> GetMut<usize> for LinkedList<T> { #[inline] fn get_mut(&mut self, index: usize) -> Option<&mut Self::Output> { LinkedList::<T>::iter_mut(self).nth(index) } }