Struct nutrimatic::Node[][src]

pub struct Node<'buf> { /* fields omitted */ }

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

impl<'buf> Node<'buf>[src]

pub fn new(buf: &'buf [u8]) -> Node<'buf>[src]

Constructs the root node of the trie serialized in the given buffer.

pub fn ch(&self) -> u8[src]

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.

pub fn freq(&self) -> u64[src]

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).

pub fn children(&self) -> ChildReader<'buf>[src]

Parses a node and returns an object representing the sequence of its children.

pub fn to_thin(&self) -> ThinNode<'buf>[src]

Constructs a thin version of this node.

pub fn from_thin(&self, thin: ThinNode<'buf>) -> Node<'buf>[src]

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.

pub fn search_string<'a, I>(&self, q: I) -> SearchResult<'buf> where
    I: IntoIterator<Item = &'a u8>, 
[src]

Searches multiple levels through the trie in one call.

pub fn word_freq<'a, I>(&self, word: I) -> Option<u64> where
    I: IntoIterator<Item = &'a u8>, 
[src]

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.

Trait Implementations

impl<'buf> Clone for Node<'buf>[src]

impl<'buf> Copy for Node<'buf>[src]

impl<'buf> Debug for Node<'buf>[src]

impl Eq for Node<'_>[src]

impl Ord for Node<'_>[src]

impl PartialEq<Node<'_>> for Node<'_>[src]

impl PartialOrd<Node<'_>> for Node<'_>[src]

Auto Trait Implementations

impl<'buf> RefUnwindSafe for Node<'buf>

impl<'buf> Send for Node<'buf>

impl<'buf> Sync for Node<'buf>

impl<'buf> Unpin for Node<'buf>

impl<'buf> UnwindSafe for Node<'buf>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.