use std::collections::HashMap;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct ElementSkeleton {
pub name: Arc<str>,
pub prefix: Option<Arc<str>>,
pub child_counts: HashMap<String, u32>,
pub children_indices: Vec<usize>,
pub line: Option<usize>,
pub column: Option<usize>,
pub text_content: String,
}
impl ElementSkeleton {
pub fn new(
name: Arc<str>,
prefix: Option<Arc<str>>,
line: Option<usize>,
column: Option<usize>,
) -> Self {
Self {
name,
prefix,
child_counts: HashMap::new(),
children_indices: Vec::new(),
line,
column,
text_content: String::new(),
}
}
pub fn increment_child(&mut self, child_name: &str) -> u32 {
let count = self.child_counts.entry(child_name.to_string()).or_insert(0);
*count += 1;
*count
}
pub fn get_child_count(&self, child_name: &str) -> u32 {
self.child_counts.get(child_name).copied().unwrap_or(0)
}
}
#[derive(Debug, Default)]
pub struct DocumentSkeleton {
pub nodes: Vec<ElementSkeleton>,
pub root_index: Option<usize>,
}
impl DocumentSkeleton {
pub fn new() -> Self {
Self {
nodes: Vec::new(),
root_index: None,
}
}
pub fn get_node(&self, index: usize) -> Option<&ElementSkeleton> {
self.nodes.get(index)
}
}