The Hash Aggregate C++ Sequence methods take various input arguments and return two iterators: result for the grouping values and groups for the group aggregates.
void hashAggMax(Sequence<T>& result, GenericSequence& groups, GenericSequence const& groupBy) constReturns a sequence of the same type with the maximum value for each group of elements.void hashAggMin(Sequence<T>& result, GenericSequence& groups, GenericSequence const& groupBy) constReturns a sequence of the same type with the minimum value for each group of elements.void hashAggSum(Sequence<R>& result, GenericSequence& groups, GenericSequence const& groupBy) constReturns a sequence of the same type with the sum of each group of elements.void hashAggAvg(Sequence<double>& result, GenericSequence& groups, GenericSequence const& groupBy) constReturns adoubleresult sequence with the average of each group of elements.void hashAggApproxDistinctCount(Sequence<uint4>& result, GenericSequence& groups, GenericSequence const& groupBy) constReturns auint4result sequence with the approximate distinct count for each group of elements.void hashAggCount(Sequence<uint8>& result, GenericSequence& groups) constReturns auint8result sequence with the count of the number of elements in each group.void hashAggDistinctCount(Sequence<uint8>& result, GenericSequence& groups, GenericSequence const& groupBy) constReturns auint8result_count sequence with the count of the number of distinct elements in each group.void hashAggDupCount(Sequence<uint8>& result, GenericSequence& groups, GenericSequence const& groupBy, mco_size_t minOccurrences) constReturns a
uint8sequence with the count of duplicates in each group. ParameterminOccurrencesspecifies the minimum number of occurrences of a particular value required for it to be counted. WithminOccurrences=1, this method is equivalent tohashAggDistinctCount(); withminOccurrences=2, it counts items encountered more than once.Example
The following code snippet demonstrates the use of a hash aggregate method to calculate the average Close price for Volume values in ranges of 0..9, 10..19, 20..29, etc.:
{ mco_trans_h trans; mco_cursor_t quote_cursor; Quote quote; mco_seq_iterator_t close_iterator, volume_div_10_iterator; mco_seq_iterator_t group_iterator, avg_iterator; MCO_RET rc; ... for (rc = mco_cursor_first(trans, "e_cursor); rc != MCO_S_CURSOR_END; rc = mco_cursor_next(trans, "e_cursor)) { Sequence<double> result; Sequence<uint4> groups; Quote_from_cursor(trans, "e_cursor, "e); quote.close_iterator().hashAggAvg(result, groups, quote.volume_iterator() / Sequence<uint4>(10)); print_sequence(quote, result); } ... }