orx-linked-list
Implements a doubly-linked list.
As opposed to the note of std::collections::LinkedList
, orx_linked_list::LinkedList
provides the main theoretical benefits of a linked list; i.e.,
- efficient insertion and removal of elements,
while aiming to avoid the practical drawbacks related with allocations and CPU cache due to the following:
LinkedList
uses anImpVec
as the underlying data structure which allows for defining inter-element relationships by thin references;next
andprev
relationships are defined by thin&
references without any additional heap allocations since smart pointers such asBox
orRc
per element are not necessary.
- All elements are stored in the underlying
PinnedVec
of theImpVec
; which might either be aFixedVec
orSplitVec
. In either case, the elements will be stored close to each other in a vec-like structure. Although the order of elements in this vector will not be in the correct order as expected in a linked list, they will be pointing to other elements of the same vector. Therefore, unlike classical implementations by arbitrary heap allocations, theLinkedList
implementation provides better cache locality.
Example
use *;
let mut list = with_exponential_growth;
// build linked list: x <-> a <-> b <-> c
list.push_back;
list.push_back;
list.push_front;
list.push_back;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;