In this video we implement an LRU Cache (Least Recently Used) in Rust with a double linked list along side a HashMap. We make use of Smart Pointers (Weak and Reference Counters) to maintain references between nodes and the HashMap. For the LRU cache, we also add the ability to set a capacity and pop least recently used items off of the list.
**Note**:
Because we make use of weak pointers we do not necessarily have to clean up our HashMap when the cache is being used up but it is something should try and implement later by storing the key alongside the node in order to do this. Try updating our implementation to store the key as well and clean up the HashMap whenever the LRU reaches its capacity.
↠ Other Videos to Watch
Double Linked List: • Rust Programming Exercises: Double Linked ...
Tree Traversals with Reference Counting and Interior Mutability (in Rust): • Tree Traversals with Reference Counting an...
Handling Reference Cycles (in Rust): • Handling Reference Cycles (in Rust)
↠ References:
LRU Cache: https://leetcode.com/problems/lru-cache/
HashMap: https://doc.rust-lang.org/std/collect...
Double Linked List: https://en.wikipedia.org/wiki/Doubly_...
alloc::rc::Weak: https://doc.rust-lang.org/nightly/all...
Reference Cycles: https://doc.rust-lang.org/book/ch15-0...
Interior Mutability: https://doc.rust-lang.org/nightly/std...
Reference Counters: https://doc.rust-lang.org/nightly/src...
Drop Trait: https://doc.rust-lang.org/std/ops/tra...
std::cell: https://doc.rust-lang.org/src/core/ce...
Borrow Trait: https://doc.rust-lang.org/std/borrow/...
Pointers: https://manishearth.github.io/blog/20...
↠ Patreon: https://www.patreon.com/nyxtom?fan_la...
↠ Dotfiles: https://github.com/nyxtom/dotfiles
↠ Twitter: @nyxtom / nyxtom
↠ Channel: / nyxtom
Cheers! 🍻
🦀 #rust #rustlang #rustprogramming #exercises #programming
Auf dieser Seite können Sie das Online-Video Rust Programming Exercises: LRU Cache mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Thomas 🏕 16 Mai 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 7,963 Mal angesehen und es wurde von 203 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!