use crate::persistent_artrie::block_storage::BlockStorage;
use crate::persistent_artrie_core::overlay::flip::LockFreeOverlay;
impl<S: BlockStorage> super::dict_impl::PersistentVocabARTrie<S> {
pub fn get_root_children(&self) -> Vec<(char, bool)> {
self.get_children_at_path(&[])
}
pub fn get_children_at_path(&self, path: &[char]) -> Vec<(char, bool)> {
let units: Vec<u32> = path.iter().map(|&c| c as u32).collect();
let Some(node) = self.overlay_navigate(&units) else {
return Vec::new();
};
node.iter_children()
.filter_map(|(key, child)| {
let child_node = child.as_in_mem()?;
char::from_u32(*key).map(|c| (c, child_node.is_final()))
})
.collect()
}
pub fn is_final_at_path(&self, path: &[char]) -> bool {
let units: Vec<u32> = path.iter().map(|&c| c as u32).collect();
self.overlay_navigate(&units)
.map(|node| node.is_final())
.unwrap_or(false)
}
pub fn iter_terms(&self) -> impl Iterator<Item = String> + '_ {
let terms: Vec<String> = self
.overlay_collect_units(&[])
.unwrap_or_default()
.into_iter()
.map(|u| u.iter().filter_map(|&c| char::from_u32(c)).collect())
.collect();
terms.into_iter()
}
pub fn iter_terms_with_prefix<'a>(
&'a self,
prefix: &'a str,
) -> impl Iterator<Item = String> + 'a {
let prefix_units: Vec<u32> = prefix.chars().map(|c| c as u32).collect();
let terms: Vec<String> = self
.overlay_collect_units(&prefix_units)
.unwrap_or_default()
.into_iter()
.map(|u| u.iter().filter_map(|&c| char::from_u32(c)).collect())
.collect();
terms.into_iter()
}
}