use std::collections::BTreeMap;
pub struct Node<V> {
pub items: BTreeMap<String, V>,
pub children: BTreeMap<String, Node<V>>,
}
impl<V> Node<V> {
pub fn new() -> Self {
Self {
items: BTreeMap::new(),
children: BTreeMap::new(),
}
}
pub fn insert(&mut self, path: &[&str], value: V) {
assert!(!path.is_empty());
if path.len() == 1 {
self.items.insert(path[0].to_string(), value);
return;
}
self.children
.entry(path[0].to_string())
.or_default()
.insert(&path[1..], value);
}
}
impl<V> Default for Node<V> {
fn default() -> Self {
Self::new()
}
}