IterList
A doubly linked list with a cursor based api.
it's also an iterator!
O(1) pretty much everything (at the cursor).
Example
use IterList;
let mut list = new
list.push_prev;
list.push_next;
list.push_next;
list.push_next
assert_eq!
list.move_to;
assert_eq!
list.move_by;
assert_eq!
let mut cursor = list.as_cursor;
assert_eq!;
assert_eq!
assert_eq!
list.move_by;
list.consume
assert_eq!
let num = list.fold
assert_eq!;
Why would I want to use IterList?
Short answer? idk honestly.
Long answer:
- You're iterating over a list, and are removing/inserting elements as you go.
- You want to have multiple independant cursors on the same list.
- You need an iterator that you can move around in and modify.
Why wouldn't I want to use IterList?
Pretty much any other case. (lol)
It has all the disadvantages of a doubly linked list, and is even slower at many front/back operations.
Instead of pointers to front and back, IterList keeps the cursor and it's index. Meaning O(1) operations work only around the cursor.
Todos
-
replace- replace the element at the cursor with another. -
split- split the list at the cursor. -
append- append another list to the end of this one. -
prepend- prepend another list to the start of this one. -
drain- remove a range of elements (around the cursor) from the list. -
splice- replace a range of elements (around the cursor) with another list.
If ya wanna add any of these, feel free to!