fast-list
A doubly linked list using SlotMap
for improved cache locality, and to solve the ABA problem.
✅ On average ~2-3x faster than the standard LinkedList
for all operations.
✅ On average ~2-3x faster than Vec
& VecDeque
for random insertions (random removals are about the same as of now)
✅ Only slightly slower than Vec
& VecDeque
for most other operations.
✅ Safe against ABA problem by using a SlotMap
internally, which makes it safer to iterate & mutate the list across multiple threads. An advantage over just using a SlotMap is that the order when iterating is not arbitrary.
✅ Written in 100% safe Rust.
Examples
Basic example
use LinkedList;
// the extend() function accepts an iterator over T (i32 in this case)
let mut list = new;
list.extend;
assert_eq!;
assert_eq!;
list.push_front;
assert_eq!;
assert_eq!; // 101 items from our range, one item from push_back
// These two iterators are equivalent
assert_eq!;
Multithreaded iteration & mutation
use LinkedList;
use thread;
use ;
let mut list = new;
let indexes = new;
// You can also get the ordered indexes with something like this:
// let indexes = Arc::new(
// list.cursor_next(list.head.unwrap()).collect::<Vec<_>>()
// );
let list_mut = new;
let mut threads = Vec new;
for _ in 0..3
for t in threads
// Even though remove() is called 9000*3 times, only 9000 items are removed.
Structure
LinkedList
- The main struct that holds the list.
// A doubly linked list using SlotMap for better cache performance than a linked list using pointers, and which also solves the ABA problem.
LinkedListIndex
- An index into the list.
new_key_type!
LinkedListItem
- An item in the list.
LinkedListWalker
- [feature = "unstable"] A walker type (like in petgraph) which can be used to iterate over the list.