# Hash Aggregate C++ Sequence Methods

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) const | Returns 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) const | Returns 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) const | Returns a sequence of the same type with the sum of each group of elements
> void hashAggAvg(Sequence<double>& result, GenericSequence& groups, GenericSequence const& groupBy) const | Returns a `double` result sequence with the average of each group of elements
> void hashAggApproxDistinctCount(Sequence<uint4>& result, GenericSequence& groups, GenericSequence const& groupBy) const | Returns a `uint4` result sequence with the approximate district count for each group of elements
> void hashAggCount(Sequence<uint8>& result, GenericSequence& groups) const | Returns a `uint8` result sequence with the count of the number of elements in each group
> void hashAggDistinctCount(Sequence<uint8>& result, GenericSequence& groups, GenericSequence const& groupBy) const | Returns a `uint8` result_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) const | Returns a `uint8` sequence with the count of duplicates in each group. Parameter `minOccurrences` specifies minimum number for occurrences of a particular value to be counted. With `minOccurrences=1` this method is equivalent to `hashAggDistinctCount()`, with `minOccurrences=2` it counts items encountered more than once.

> ## Example

> Following is an example code snippet demonstrating 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, &quote_cursor);
>                 rc != MCO_S_CURSOR_END;
>                 rc = mco_cursor_next(trans, &quote_cursor))
>             {
>                 Sequence<double> result;
>                 Sequence<uint4> groups;

>                 Quote_from_cursor(trans, &quote_cursor, &quote);

>                 quote.close_iterator().hashAggAvg(result, groups, quote.volume_iterator() / Sequence<uint4>(10));
>                 print_sequence(quote, result);
>             }
>             ...
>         }