pub struct Trie<V> { /* private fields */ }Expand description
Hierarchical prefix tree
Implementations§
Source§impl<V> Trie<V>
impl<V> Trie<V>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true if a Trie is empty (has no leaf or internal nodes), otherwise false.
Sourcepub fn has_leaf_node(&self, addr: &str) -> bool
pub fn has_leaf_node(&self, addr: &str) -> bool
Return true if a Trie has a leaf node at addr, otherwise false.
Sourcepub fn get_leaf_node(&self, addr: &str) -> Option<&V>
pub fn get_leaf_node(&self, addr: &str) -> Option<&V>
Return Some(&value) if self contains a value located at addr, otherwise None.
Sourcepub fn insert_leaf_node(&mut self, addr: &str, value: V) -> Option<V>
pub fn insert_leaf_node(&mut self, addr: &str, value: V) -> Option<V>
Insert value as a leaf node located at addr.
If there was a value prev located at addr, return Some(prev), otherwise None.
Sourcepub fn remove_leaf_node(&mut self, addr: &str) -> Option<V>
pub fn remove_leaf_node(&mut self, addr: &str) -> Option<V>
Return Some(value) if self contains a value located at addr and remove value from the leaf nodes, otherwise return None.
Sourcepub fn has_internal_node(&self, addr: &str) -> bool
pub fn has_internal_node(&self, addr: &str) -> bool
Return true if a Trie has an internal node at addr, otherwise false.
Sourcepub fn get_internal_node(&self, addr: &str) -> Option<&Self>
pub fn get_internal_node(&self, addr: &str) -> Option<&Self>
Return Some(&subtrie) if self contains a subtrie located at addr, otherwise None.
Sourcepub fn insert_internal_node(
&mut self,
addr: &str,
new_node: Self,
) -> Option<Trie<V>>
pub fn insert_internal_node( &mut self, addr: &str, new_node: Self, ) -> Option<Trie<V>>
Insert subtrie as an internal node located at addr.
If there was a value prev_subtrie located at addr, return Some(prev_subtrie), otherwise None.
Panics if subtrie.is_empty().
Sourcepub fn remove_internal_node(&mut self, addr: &str) -> Option<Trie<V>>
pub fn remove_internal_node(&mut self, addr: &str) -> Option<Trie<V>>
Return Some(subtrie) if self contains a subtrie located at addr and remove subtrie from the internal nodes, otherwise return None.
Sourcepub fn internal_iter(&self) -> Iter<'_, String, Trie<V>>
pub fn internal_iter(&self) -> Iter<'_, String, Trie<V>>
Return an iterator over a Trie’s internal nodes.
Source§impl<V> Trie<(V, f64)>
impl<V> Trie<(V, f64)>
Sourcepub fn sum(&self) -> f64
pub fn sum(&self) -> f64
Return the sum of all the weights of the leaf nodes and the recursive sum of all internal nodes.
Sourcepub fn into_unweighted(self) -> Trie<V>
pub fn into_unweighted(self) -> Trie<V>
Convert a weighted Trie into the equivalent unweighted version by discarding all the weights.
Sourcepub fn from_unweighted(trie: Trie<V>) -> Self
pub fn from_unweighted(trie: Trie<V>) -> Self
Convert an unweighted Trie into the equivalent weighted version by adding a weight of 0. to all leaf nodes.
Source§impl Trie<()>
impl Trie<()>
Sourcepub fn schema<V>(data: &Trie<V>) -> Self
pub fn schema<V>(data: &Trie<V>) -> Self
Return the unique AddrTrie that contains an addr if and only if data contains that addr.
Sourcepub fn all_visited<T>(&self, data: &Trie<T>) -> bool
pub fn all_visited<T>(&self, data: &Trie<T>) -> bool
Return true if every addr in data is also present in self.
Sourcepub fn get_unvisited<V>(&self, data: &Trie<V>) -> Self
pub fn get_unvisited<V>(&self, data: &Trie<V>) -> Self
Return the AddrTrie that contains all addresses present in data, but not present in self.
Trait Implementations§
Source§impl<Args: Clone + 'static, Ret: 'static> GenFn<Args, Trie<(Rc<dyn Any>, f64)>, Ret> for TrieFn<Args, Ret>
impl<Args: Clone + 'static, Ret: 'static> GenFn<Args, Trie<(Rc<dyn Any>, f64)>, Ret> for TrieFn<Args, Ret>
Source§fn simulate(&self, args: Args) -> Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>
fn simulate(&self, args: Args) -> Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>
Source§fn generate(
&self,
args: Args,
constraints: Trie<(Rc<dyn Any>, f64)>,
) -> (Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, f64)
fn generate( &self, args: Args, constraints: Trie<(Rc<dyn Any>, f64)>, ) -> (Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, f64)
constraints.
Return the log probability
log[p(t; args) / q(t; constraints, args)]impl<V> StructuralPartialEq for Trie<V>
Auto Trait Implementations§
impl<V> Freeze for Trie<V>
impl<V> RefUnwindSafe for Trie<V>where
V: RefUnwindSafe,
impl<V> Send for Trie<V>where
V: Send,
impl<V> Sync for Trie<V>where
V: Sync,
impl<V> Unpin for Trie<V>where
V: Unpin,
impl<V> UnwindSafe for Trie<V>where
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.