May 2019
Intermediate to advanced
698 pages
17h 21m
English
The algorithm for inserting a string into a trie can be described in only a few sentences: go through each character of the word and trace it down the trie. If a node does not yet exist, create it, and add the object with the last entry.
Of course, there are special cases that need to be decided as well: what happens when a string already exists? Overwrite or ignore? In the case of this implementation, the last write will win—that is, it's overwriting whatever existed previously:
pub fn add(&mut self, device: IoTDevice) { let p = device.path.clone(); let mut path = p.chars(); if let Some(start) = path.next() { self.length += 1; let mut n = self.root .entry(start) .or_insert(Node::new(start, None)); for c in path { let tmp
Read now
Unlock full access