Conditional C Sequence Functions

The following conditional C API functions take one input sequence or two (then, else) sequences, and a Boolean sequence condition. The sequences can be of any TYPE listed on the Analytics Functions page. The result sequence is of the specified TYPE, except for the mco_seq_filter_pos() API, which returns a result sequence of type uint4.

The two input sequence iterator arguments must be of the same type, and the result is a sequence of values or a scalar value. If the two input sequence arguments are of different lengths, the operation will be performed on only the number of elements in the shorter of the two sequences.

mco_seq_iif_TYPE()
Choose the element of the then sequence or the else sequence depending on the Boolean value of the corresponding element of the condition sequence. All three sequences are traversed at the same speed. If the element of the then sequence is used, the corresponding element of the else sequence is skipped, and vice versa. Please see the Ternary Operations page for further details.
mco_seq_if_TYPE()
Choose the element of the then sequence or the else sequence depending on the Boolean value of the corresponding element of the condition sequence. Unlike mco_seq_iif_TYPE(), the position in the unused sequence is not changed. Please see the Ternary Operations page for further details.
mco_seq_filter_TYPE()
Leave only those elements of the input sequence for which the corresponding Boolean elements of the cond sequence are true.
    MCO_RET mco_seq_filter_TYPE(mco_seq_iterator_h result,
            mco_seq_iterator_h cond,
            mco_seq_iterator_h input);
mco_seq_filter_search()
This function is used in combination with a generated classname_fieldname_search() function. The result of classname_fieldname_search() is passed as the search_result parameter, and the filter condition is passed as the cond parameter.
    MCO_RET mco_seq_filter_search(mco_seq_iterator_h result,
            mco_seq_iterator_h cond,
            mco_seq_iterator_h search_result);
mco_seq_filter_pos()
Get the positions of the elements that are true in the cond sequence.
    MCO_RET mco_seq_filter_pos(mco_seq_iterator_h result,
            mco_seq_iterator_h cond);

Example

The following is an example code snippet demonstrating a conditional function:

    Quote_by_sym_index_cursor(trans, &quote_cursor);
    for (rc = mco_cursor_first(trans, &quote_cursor);
        rc != MCO_S_CURSOR_END;
        rc = mco_cursor_next(trans, &quote_cursor))
    {
        /* Get current object */
        Quote_from_cursor(trans, &quote_cursor, &quote);

        /* Select interval */
        Quote_day_last(&quote, &last);
        Quote_day_search(&quote, &day_iterator, DMY(1, MONTH(last), YEAR(last)),
            MCO_SEQ_BOUNDARY_INCLUSIVE,
            last,
            MCO_SEQ_BOUNDARY_INCLUSIVE);
        Quote_open_project(&quote, &open_iterator, &day_iterator);
        Quote_close_project(&quote, &close_iterator, &day_iterator);

        /* Construct operator's pipeline */
        mco_seq_gt_float(&gt_iterator, &close_iterator, &open_iterator);
        mco_seq_filter_uint4(&filter_iterator, &gt_iterator, &day_iterator);

        ...
    }
    rc = mco_trans_commit(trans);