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

Walking

Add and search work in a very similar manner: follow the links to the characters of the key and return the "value" in the end:

pub fn find(&mut self, path: &str) -> Option<IoTDevice> {    let mut path = path.chars();    if let Some(start) = path.next() {        self.root.get(&start).map_or(None, |mut n| {            for c in path {                match n.next.get(&c) {                    Some(ref tmp) => n = tmp,                    None => break,                }            }                n.value.clone()        })    } else {        None    }}

Since the trie does not store strings in any particular order (or even consistently), getting the same data out in a predictable way is tricky! Walking it like a binary tree works well enough, but will only be deterministic with respect to the insertion order, something that should be kept in mind when testing the implementation: ...

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