Skip to Content
Hands-On Data Structures and Algorithms with Rust
book

Hands-On Data Structures and Algorithms with Rust

by Claus Matzinger
January 2019
Intermediate to advanced
316 pages
8h 8m
English
Packt Publishing
Content preview from Hands-On Data Structures and Algorithms with Rust

Quick access

Due to the underlying slice, accessing an index is cheap. In fact, it always takes the same amount of time, regardless of the index (which makes it different to previously discussed lists). A call to the at() function will therefore simply forward it accordingly:

pub fn at(&mut self, index: usize) -> Option<u64> {    if self.length > index {        self.buf[index]    } else {        None    }}

Here, again, the Rust implementation has to deal with sharing borrowed content or clone the data structure which might require more memory. Under the hood, a u64 is implicitly cloned.

To fulfill all requirements, the Iterator trait has to be implemented as well. Unlike the doubly linked list, the iterator cannot store a single node and go forward or backward ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Data Structures and Algorithms in Rust

Hands-On Data Structures and Algorithms in Rust

Matthew Stoodley

Publisher Resources

ISBN: 9781788995528Supplemental Content