use std::collections::BTreeMap;
#[derive(Debug, Clone)]
pub struct Node {
pub id: usize,
pub val: char,
pub children: BTreeMap<char, usize>,
pub eow: bool,
pub count: usize,
}
impl Node {
pub fn new(id: usize, val: char) -> Self {
Node {
id,
val,
children: BTreeMap::new(),
eow: false,
count: 0,
}
}
pub fn signature(&self, nodes: &[Node]) -> String {
let mut s = String::new();
s.push(self.val);
s.push_str(&self.count.to_string());
s.push(if self.eow { '1' } else { '0' });
for (&ch, &child_idx) in &self.children {
s.push(ch);
s.push_str(&nodes[child_idx].id.to_string());
}
s
}
}