pub struct Node<'buf> { /* private fields */ }
Expand description
A node in a trie.
Nodes implement ordering and equality according to their frequency in order to accommodate using them in priority queues for best-first search.
§Examples
use nutrimatic::Node;
// This buffer represents a single node with three leaf children.
let buf: &[u8] = &[0x61, 0x11, 0x62, 0x12, 0x63, 0x13, 0x03];
let root = Node::new(buf);
// Print out all children of the root node of the trie.
for child in &root.children() {
println!("{} {}", child.ch() as char, child.freq());
}
Implementations§
Source§impl<'buf> Node<'buf>
impl<'buf> Node<'buf>
Sourcepub fn new(buf: &'buf [u8]) -> Node<'buf>
pub fn new(buf: &'buf [u8]) -> Node<'buf>
Constructs the root node of the trie serialized in the given buffer.
Sourcepub fn ch(&self) -> u8
pub fn ch(&self) -> u8
Returns the character associated with the node—i.e., the letter used to transition from this node’s parent to this node.
This value is not useful for a root node returned by Node::new
.
Sourcepub fn freq(&self) -> u64
pub fn freq(&self) -> u64
Returns the frequency of the node—i.e., the total number of times that the corpus contains any phrase that starts with the sequence of characters corresponding to the path to this node (including this node’s own character).
Sourcepub fn children(&self) -> ChildReader<'buf>
pub fn children(&self) -> ChildReader<'buf>
Parses a node and returns an object representing the sequence of its children.
Sourcepub fn from_thin(&self, thin: ThinNode<'buf>) -> Node<'buf>
pub fn from_thin(&self, thin: ThinNode<'buf>) -> Node<'buf>
Reconstitutes a thin node into a full node.
The thin node must have originally been associated with the same index file buffer as this node.
Sourcepub fn search_string<'a, I>(&self, q: I) -> SearchResult<'buf>where
I: IntoIterator<Item = &'a u8>,
pub fn search_string<'a, I>(&self, q: I) -> SearchResult<'buf>where
I: IntoIterator<Item = &'a u8>,
Searches multiple levels through the trie in one call.
Sourcepub fn word_freq<'a, I>(&self, word: I) -> Option<u64>where
I: IntoIterator<Item = &'a u8>,
pub fn word_freq<'a, I>(&self, word: I) -> Option<u64>where
I: IntoIterator<Item = &'a u8>,
Finds the frequency of the given sequence of characters in the trie.
This function performs a query for the given characters followed by a space character and returns the frequency of the final node, if found.