Counter

Represents a set of counters for trailing (following) tokens in a markov state.

Constructors

this
this(T follow)

Constructs a counter table with an initial token.

Members

Functions

contains
bool contains(T follow)

Checks if the counter table contains a given token.

get
uint get(T follow)

Returns the counter value for a token.

peek
uint peek(T follow)

Returns the counter value for a token. If the token doesn't exist, 0 is returned.

poke
void poke(T follow)

Pokes a token in the counter table, incrementing its counter value. If the token doesn't exist, it's created and assigned a counter of 1.

set
void set(T follow, uint count)

Sets the counter value for a given token.

Properties

empty
bool empty [@property getter]

Checks if the counter table is empty.

keys
T[] keys [@property getter]

Returns a list of tokens in the counter table.

length
size_t length [@property getter]

Returns the length of the counter table.

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

Returns a random token with equal distribution. If the counter table is emtpy, null is returned instead.

rehash
void rehash [@property getter]

Rebuilds the associative arrays used by the counter table.

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

Returns a random token, distributed based on the counter values. Specifically, a token with a higher counter is more likely to be chosen than a token with a counter lower than it. If the counter table is empty, null is returned instead.

total
uint total [@property getter]

Returns the sum of all counters on all tokens. The value is cached once it's been computed.

Meta