As in the previous implementation, this tree builds on the numerical_id property of IoTDevice as keys, and the device object as value. In code, a node looks very similar to the previous example:
type Tree = Box<Node>;
type KeyType = u64;
type Data = (Option<IoTDevice>, Option<Tree>);
#[derive(Clone, PartialEq, Debug)]
enum NodeType {
Leaf,
Regular,
}
#[derive(Clone, PartialEq)]
enum Direction {
Left,
Right(usize),
}
#[derive(Clone)]
struct Node {
devices: Vec<Option<IoTDevice>>,
children: Vec<Option<Tree>>,
left_child: Option<Tree>,
pub node_type: NodeType,
}
Instead of triples, this node type uses a synchronized index to find the children associated with a specified key-value pair. These pairs are also created ad hoc by evaluating the numerical_id property of the contained device, thereby also simplifying the code and eventual updates to the keys. Something that is missing from the node is a parent pointer,...