pub struct Index { /* private fields */ }Expand description
The index of one version of a tree. Its owner builds it once and keeps it until the tree changes: every query reads it, none builds it.
Implementations§
Source§impl Index
impl Index
Sourcepub fn build(tree: &Document, roots: &[u32]) -> Index
pub fn build(tree: &Document, roots: &[u32]) -> Index
Indexes the tree under each of roots in turn: the document, then
any subtrees removed from it or built apart from it, so every node
a caller can hold has a position.
pub fn is_empty(&self) -> bool
Sourcepub fn order(&self, id: u32) -> u32
pub fn order(&self, id: u32) -> u32
A node’s position; u32::MAX if it was made after the index was.
Sourcepub fn tag_id_named(&self, name: &str) -> Option<usize>
pub fn tag_id_named(&self, name: &str) -> Option<usize>
The tag id elements named name (compared lowercased) carry, if
any element could: a known tag’s always, another name’s only when
some element in the document has it.
Sourcepub fn with_id<'t>(
&self,
id: &str,
id_of: impl Fn(u32) -> Option<&'t str>,
) -> Vec<u32>
pub fn with_id<'t>( &self, id: &str, id_of: impl Fn(u32) -> Option<&'t str>, ) -> Vec<u32>
The elements whose id is id, in document order. id_of reads a
node’s id attribute; the first call’s is used for every call.
Sourcepub fn descendants(
&self,
at: u32,
include_self: bool,
keep: impl Fn(u8, usize) -> bool,
out: &mut Vec<u32>,
)
pub fn descendants( &self, at: u32, include_self: bool, keep: impl Fn(u8, usize) -> bool, out: &mut Vec<u32>, )
Appends to out the nodes below at (from at itself if
include_self) that pass keep(kind, tag), in document order.