Struct markov_generator::Chain

source ·
pub struct Chain<T> { /* private fields */ }
Expand description

A Markov chain.

This type implements Serialize and Deserialize when the serde feature is enabled (which it is by default).

Implementations§

Creates a new chain.

See Self::depth for an explanation of the depth.

Gets the chain’s depth.

A depth of n means the chain maps sequences of n items of type T to a list of possible next items.

Adds all items in an iterator to the chain.

This essentially calls Self::add_next on every overlapping window of self.depth() + 1 elements.

edges controls whether the start or end of items can be used as start or end data for the chain. See the documentation for AddEdges for more information.

Adds items to the chain.

The first self.depth() + 1 items are added, increasing the chance that the first self.depth() items will be followed by the remaining item.

If items.into_iter() yields fewer than self.depth() items, this function is a no-op. If it yields exactly self.depth() items, the remaining item is treated as None.

Adds items preceded by various amounts of Nones so that Self::get_start has a chance of returning those items.

Specifically, this function calls Self::add with i Nones followed by the items in items for every i from 1 to self.depth() (inclusive). This increases the chance that the first self.depth() items of items will be returned by Self::get_start.

Note that this function does not increase the chance that the first self.depth() items of items will be followed by the self.depth() + 1st item; Self::add_next or Self::add must be called.

Convenience function that wraps each item in Some and calls Self::add.

Note that this function alone does not increase the chance that items will be returned by Self::get_start; Self::add_start (or manually passing None-prefixed sequences to Self::add) must be used.

Available on crate feature std only.

Generates random Markov chain data.

Returns an iterator that yields the elements by reference. If you want them by value, simply use Iterator::cloned (as long as T is Clone).

Like Self::generate, but takes a custom random number generator.

Available on crate feature std only.

Gets a random item that has followed items in the added data.

Only the first self.depth() items are considered. A return value of None either means those items were never followed by anything in the data passed to Self::add, or that None sometimes followed those items and that possibility happened to be picked by the random number generator.

Given iter as items.into_iter(), if iter.next() returns None, it is treated as if it returned Some(None).

Like Self::get, but takes a custom random number generator.

Available on crate feature std only.

Gets some initial items that have appeared at the start of a sequence (see Self::add_start).

Like Self::get_start, but takes a custom random number generator.

Available on crate feature std only.

Convenience function that wraps each item in Some and calls Self::get.

Like Self::get_next, but takes a custom random number generator.

Trait Implementations§

Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.