3.4 Enumerating Action Choice States and Cycle Types

Use the following function to enumerate action choice states that have the pieces of information held in storage.

Function: int qsmm_storage_enum_states_v2 (qsmm_storage_t storage, int ngram_lower_sz, int ngram_upper_sz, int range_sz, int rez1, const qsmm_sig_t *sig_ngram_lower_p, const qsmm_sig_t *sig_ngram_upper_p, const struct qsmm_pair_sig_s *range_sig_p, qsmm_enum_state_callback_func_t callback_func, void *paramp)

This function enumerates lists of signal identifiers encoding action choice states that have the pieces of information held in storage.

If ngram_lower_sz is positive, it specifies the length of sig_ngram_lower_p array containing a lower bound for the enumerated lists—their prefixes with length ngram_lower_sz must be greater than or equal to the lower bound. If ngram_upper_sz is positive, it specifies the length of sig_ngram_upper_p array containing an upper bound for the enumerated lists—their prefixes with length ngram_upper_sz must be less than the upper bound. If range_sz is positive, it specifies the length of range_sig_p array containing allowed ranges of signal identifiers in prefixes with length range_sz in the enumerated lists—every signal identifier in a prefix must be greater than or equal to the field first of an element of range_sig_p at the same index and must be less than or equal to the field second of the element.

The function compares two lists of signal identifiers from left to right. If a signal identifier in the first list is less than or greater than a signal identifier in the second list at the same index, the first list is less than or greater than the second list respectively. If the first list is a prefix of the second list, the first list is less than the second list. If the second list is a prefix of the first list, the first list is greater than the second list. If the two lists have the same length and content, the lists are equal.

The process of enumeration is repeated calling a callback function callback_func with passing an array of signal identifiers encoding an enumerated action choice state in ascending order of the arrays. The callback function also receives a user parameter paramp. If the callback function returns a positive value, qsmm_storage_enum_states_v2 continues enumeration. If the callback function returns zero, qsmm_storage_enum_states_v2 terminates enumeration and reports success. If the callback function returns a negative value, qsmm_storage_enum_states_v2 terminates enumeration and reports failure.

The function qsmm_storage_enum_states_v2 does not support recursive calling from the callback function for storage.

The function returns a non-negative value on success or a negative error code on failure. Currently, the function can return the following error codes.

QSMM_ERR_INVAL

One of the following conditions is true:

  • ngram_lower_sz is negative;
  • ngram_lower_sz is greater than the length of a list of signal identifiers encoding an action choice state;
  • ngram_lower_sz is positive, but sig_ngram_lower_p is NULL;
  • ngram_upper_sz is negative;
  • ngram_upper_sz is greater than the length of a list of signal identifiers encoding an action choice state;
  • ngram_upper_sz is positive, but sig_ngram_upper_p is NULL;
  • range_sz is negative;
  • range_sz is greater than the length of a list of signal identifiers encoding an action choice state;
  • range_sz is positive, but range_sig_p is NULL;
  • field first in an element of range_sig_p is greater than the field second of the element;
  • field second in an element of range_sig_p is greater than QSMM_SIG_MAX.
QSMM_ERR_CALLBACK

The callback function reported an error.

The type of a pointer to a callback function called for every enumerated action choice state is below.

Data type: qsmm_enum_state_callback_func_t

This is a type of a callback function pointer with the following declaration:

typedef int
(*qsmm_enum_state_callback_func_t)(
    qsmm_storage_t storage,
    int ngram_sz,
    const qsmm_sig_t *sig_ngram_p,
    void *paramp
);

The function qsmm_storage_enum_states_v2 calls the callback function for every enumerated action choice state of storage. The argument sig_ngram_p specifies an array of signal identifiers encoding an enumerated action choice state. The argument ngram_sz specifies the length of the array. The argument paramp is a user parameter passed to qsmm_storage_enum_states_v2.

The callback function shall return a positive value to continue the process of enumeration, zero to terminate the process of enumeration, or a negative value on error.

Use a function described below to enumerate types of cycles starting at an action choice state. The action choice state and a cycle direction make up an enumerated cycle type.

Function: int qsmm_get_storage_cycle_next (qsmm_storage_t storage, int ngram_sz, const qsmm_sig_t *sig_ngram_p, qsmm_sig_t *sig_cycle_next_p)

This function retrieves the next cycle type that has a piece of information held in storage. An action choice state and cycle direction specify the cycle type. An array of signal identifiers sig_ngram_p holding ngram_sz elements encodes the action choice state.

If *sig_cycle_next_p is QSMM_SIG_INVALID, then on successful function completion, *sig_cycle_next_p will contain the first cycle direction. It has a minimum value among existing cycle directions. If *sig_cycle_next_p is not QSMM_SIG_INVALID, then on successful function completion, *sig_cycle_next_p will contain the next cycle direction greater than a cycle direction specified in *sig_cycle_next_p when calling the function. If the first or next cycle direction does not exist, then on successful function completion, *sig_cycle_next_p will be QSMM_SIG_INVALID.

If storage has a set redirection function for retrieving the next cycle type of an action choice state, qsmm_get_storage_cycle_next calls the redirection function to obtain the next cycle type. If the redirection function reports that it has not retrieved the next cycle type, qsmm_get_storage_cycle_next proceeds as if storage does not have the redirection function set. See Specifying Redirection Functions, for more information on the redirection function.

The function returns a non-negative value on success or a negative error code on failure. Currently, the function can return the following error codes.

QSMM_ERR_INVAL

The storage does not support length ngram_sz for arrays of signal identifiers encoding action choice states.

QSMM_ERR_NGRAM

The storage does not support holding information on an action choice state encoded by the array sig_ngram_p. A set of action choice states supported by storage is equal to a set of action choice states supported by an actor owning the storage.

QSMM_ERR_STORAGE

The storage redirection function reported QSMM_ERR_STORAGE or an unexpected error code. See Getting the Reason of a Storage Failure, for how to get an error message describing the failure.

QSMM_ERR_STATS

The storage redirection function reported QSMM_ERR_STATS, or a cycle direction obtained by that redirection function was not QSMM_SIG_INVALID and was greater than or equal to the number of output signals of an actor owning the storage or was less than or equal to *sig_cycle_next_p if it was not QSMM_SIG_INVALID.

QSMM_ERR_ILSEQ

The storage redirection function reported QSMM_ERR_ILSEQ, or a generated error message was not convertible to a wide string according to a current locale.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation.