pub struct SkipLinkedList<T> { /* private fields */ }
Expand description
§SkipLinkedList
SkipLinkedList
is a skiplist-backed linked-list that supports fast random access.
The (amortized) time complexity is O(log n)
for both reads and writes, regardless of the position.
It is more efficient than Vec
and Linkedlist
for large list that requires lots of random access.
§Examples
let mut list = skip_linked_list::SkipLinkedList::new();
list.push_front(1);
list.push_back(2);
list.insert(1, 3);
list.insert(1, 4);
list.insert(1, 5);
// current list is: [1, 5, 4, 3, 2]
assert_eq!(list.get(1), Some(&5));
assert_eq!(list.get(3), Some(&3));
assert_eq!(list.remove(2), 4);
Implementations§
Source§impl<T> SkipLinkedList<T>
impl<T> SkipLinkedList<T>
Sourcepub fn insert(&mut self, i: usize, elem: T)
pub fn insert(&mut self, i: usize, elem: T)
Inserts an element at position index within the list, shifting all elements after it to the right.
§Examples
let mut list = skip_linked_list::SkipLinkedList::new();
list.insert(0, 10);
list.insert(1, 30);
list.insert(1, 20);
assert_eq!(list.into_iter().collect::<Vec<i32>>(), vec![10, 20, 30]);
§Panics
Panics if i > len
.
Sourcepub fn get(&self, i: usize) -> Option<&T>
pub fn get(&self, i: usize) -> Option<&T>
Gets the element at position index within the list.
§Examples
let mut list = skip_linked_list::SkipLinkedList::new();
list.insert(0, 10);
assert_eq!(list.get(0), Some(&10));
assert_eq!(list.get(1), None);
Sourcepub fn push_front(&mut self, elem: T)
pub fn push_front(&mut self, elem: T)
Inserts an element at the start of the list.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for SkipLinkedList<T>
impl<T> RefUnwindSafe for SkipLinkedList<T>where
T: RefUnwindSafe,
impl<T> !Send for SkipLinkedList<T>
impl<T> !Sync for SkipLinkedList<T>
impl<T> Unpin for SkipLinkedList<T>
impl<T> UnwindSafe for SkipLinkedList<T>where
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
Mutably borrows from an owned value. Read more