lru-st
This crate provides a Vec based doubly linked list implementation. It also aims at providing data structures built on top of doubly linked list such as LRU HashMap.
Features
sync: to enable whencollectionsstructures needs to be used in threads
Example: DoublyLinkedList
use ;
let mut dll = dll!;
assert_eq!;
let c = dll.push_front;
// even though the element has been pushed
// at front (i.e. 0th position in the list)
// its [Cursor] is 4. This is because the
// Cursor is a reference to the item not
// related to its position in the list.
assert_eq!;
// first element is 0
assert_eq!;
assert_eq!;
// we move item with value 4 at front of
// the list
dll.move_front.unwrap;
assert_eq!;
assert_eq!;
// even if order of list items changed cursors
// are never affected by those changes
assert_eq!;
Example: LRU HashMap
use LruHashMap;
let mut lru_map = with_max_entries;
lru_map.insert;
assert_eq!;
assert_eq!;
// we fill the map entirely
for i in 0..lru_map.cap
assert_eq!;
// this element disapeared from the map as we filled
// all the map without fetching it
assert_eq!;
Example: LRU HashSet
use LruHashSet;
let mut lru_set = with_max_entries;
assert_eq!;
assert_eq!;
assert_eq!;
// we remove one element
assert_eq!;
assert_eq!;
assert!;
let mut lru_set = with_max_entries;
assert_eq!;
for i in 0..10
// the item vanished as the LRU got full
assert_eq!;
assert!;
License
GNU General Public License v3.0
Permissions of this strong copyleft license are conditioned on making available complete source code of licensed works and modifications, which include larger works using a licensed work, under the same license. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights.