State

Represents a table of token sequences bound to counter tables in a markov chain.

Constructors

this
this()
Undocumented in source.
this
this(size_t size)

Constructs a markov state with the given size. The size must be greater than 0.

Members

Functions

contains
bool contains(T[] first)

Checks if a counter table exists in the markov state.

contains
bool contains(T[] first, T follow)

Checks if a token exists in a counter table in the markov state.

get
Counter!T get(T[] first)

Returns the counter table that corresponds to the token sequence.

peek
uint peek(T[] first, T follow)

Return the counter value of a token, from the counter table that corresponds to the given token sequence. If the token doesn't exist in the counter table, of the leading sequence doesn't exist in the markov state, or the length of the sequence doesn't match the size of the markov state, 0 is returned instead.

poke
void poke(T[] first, T follow)

Pokes a token in the counter table that corresponds to the given leading sequence of tokens, incrementing its counter value. If the token counter have an entry in the counter table, it is created and assigned a value of 1, and if no counter table exists for the leading token sequence, one is created as well. The length of the token sequence must match the size of the markov state.

set
void set(T[] first, Counter!T counter)

Sets the counter table for a given sequence of tokens.

Properties

empty
bool empty [@property getter]

Checks if the markov state is empty.

keys
T[][] keys [@property getter]

Returns a list of token sequences in the counter table.

length
size_t length [@property getter]

Returns the length of the markov state.

random
T random [@property getter]
Nullable!(Unqual!T) random [@property getter]

Returns a random token from a random counter table. If either the markov state or the counter table is empty, null is returned instead.

rehash
bool rehash [@property setter]

Rebuilds the associative arrays used by the markov table.

select
T[] select [@property setter]

Returns a random token that might follow the given sequence of tokens based on the markov state and the counter table that corresponds to the token sequence. If either the markov state of the corresponding counter table is empty, or the token sequence doesn't have a counter table assigned to it, null is returned instead.

size
size_t size [@property getter]

Returns the size of the markov state.

Meta