Trie

Struct Trie 

Source
pub struct Trie<V> { /* private fields */ }
Expand description

Hierarchical prefix tree

Implementations§

Source§

impl<V> Trie<V>

Source

pub fn new() -> Self

Construct an empty Trie.

Source

pub fn is_empty(&self) -> bool

Return true if a Trie is empty (has no leaf or internal nodes), otherwise false.

Source

pub fn has_leaf_node(&self, addr: &str) -> bool

Return true if a Trie has a leaf node at addr, otherwise false.

Source

pub fn get_leaf_node(&self, addr: &str) -> Option<&V>

Return Some(&value) if self contains a value located at addr, otherwise None.

Source

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.

Source

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.

Source

pub fn leaf_iter(&self) -> Iter<'_, String, V>

Return an iterator over a Trie’s leaf nodes.

Source

pub fn has_internal_node(&self, addr: &str) -> bool

Return true if a Trie has an internal node at addr, otherwise false.

Source

pub fn get_internal_node(&self, addr: &str) -> Option<&Self>

Return Some(&subtrie) if self contains a subtrie located at addr, otherwise None.

Source

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

Source

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.

Source

pub fn internal_iter(&self) -> Iter<'_, String, Trie<V>>

Return an iterator over a Trie’s internal nodes.

Source

pub fn merge(self, other: Self) -> Self

Merge other into self, freeing previous values and subtries at each addr in self if other also has an entry at addr.

Returns the mutated self.

Source§

impl<V> Trie<(V, f64)>

Source

pub fn sum(&self) -> f64

Return the sum of all the weights of the leaf nodes and the recursive sum of all internal nodes.

Source

pub fn into_unweighted(self) -> Trie<V>

Convert a weighted Trie into the equivalent unweighted version by discarding all the weights.

Source

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<Rc<dyn Any>>

Source

pub fn read<V: 'static + Clone>(&self, addr: &str) -> V

Optimistically casts the reference-counted dyn Any at addr into type V, and returns a cloned value.

Source§

impl Trie<(Rc<dyn Any>, f64)>

Source

pub fn read<V: 'static + Clone>(&self, addr: &str) -> V

Optimistically casts the reference-counted dyn Any at addr into type V, and returns a cloned value.

Source§

impl Trie<()>

Source

pub fn schema<V>(data: &Trie<V>) -> Self

Return the unique AddrTrie that contains an addr if and only if data contains that addr.

Source

pub fn visit(&mut self, addr: &str)

Add an address to the AddrTrie.

Source

pub fn all_visited<T>(&self, data: &Trie<T>) -> bool

Return true if every addr in data is also present in self.

Source

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<V: Clone> Clone for Trie<V>

Source§

fn clone(&self) -> Trie<V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for Trie<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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>

Execute the generative function and return a sampled trace.
Source§

fn generate( &self, args: Args, constraints: Trie<(Rc<dyn Any>, f64)>, ) -> (Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, f64)

Execute the generative function consistent with constraints. Return the log probability log[p(t; args) / q(t; constraints, args)]
Source§

fn update( &self, trace: Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, args: Args, _: GfDiff, constraints: Trie<(Rc<dyn Any>, f64)>, ) -> (Trace<Args, Trie<(Rc<dyn Any>, f64)>, Ret>, Trie<(Rc<dyn Any>, f64)>, f64)

Update a trace
Source§

fn call(&self, args: Args) -> Ret

Call a generative function and return the output.
Source§

fn propose(&self, args: Args) -> (Data, f64)

Use a generative function to propose some data.
Source§

fn assess(&self, args: Args, constraints: Data) -> f64

Assess the conditional probability of some proposed constraints under a generative function.
Source§

impl<V> Index<&str> for Trie<V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<V: PartialEq> PartialEq for Trie<V>

Source§

fn eq(&self, other: &Trie<V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,