1 unstable release
0.1.1 | Sep 11, 2024 |
---|---|
0.1.0 |
|
#1783 in Data structures
21KB
202 lines
Cycle Cursor
Cyclic cursor implementation over generic iterators. Provides seek and peek methods.
This crate is logically a combination of DoubleEndIterator
and Cursor
traits providing double iterators from doubly linked lists with cursor from TableLike
.
Find complete documentation check .
lib.rs
:
Cycle Cursor
A cyclic bidirectional cursor implementation over generic iterators.
To begin, create an instance of the CycleCursor
// Cursor from [`Vec`]
let mut vec_cursor = CycleCursor::from(vec![1, 2, 3, 4]);
// Cursor from [`BTreeSet`]
let mut btree_cursor = CycleCursor::from(BTreeSet::from([2, 2, 4, 6, 8, 8]));
// Cyclically go to next element
vec_cursor.cycle_next();
// Cyclically go to previous element
vec_cursor.cycle_prev();
vec_cursor.cycle_prev();
// Get the current pointed element
assert_eq!(vec_cursor.get().unwrap(), &3);
// Cyclically peek an element without moving the cursor
assert_eq!(vec_cursor.peek(5).unwrap(), &4);
assert_eq!(vec_cursor.peek(-2).unwrap(), &1);
assert_eq!(vec_cursor.get().unwrap(), &3);
// Cyclically seek the cursor by signed offset
vec_cursor.seek(5);
assert_eq!(vec_cursor.get().unwrap(), &4);
vec_cursor.seek(-2);
assert_eq!(vec_cursor.get().unwrap(), &2);