# Hash Aggregate C Sequence Functions

> All Hash Aggregate C functions take two input sequence iterator arguments, input, group_by and an integer argument n_groups. They return the result_agg or result_count sequence and the result_group_by sequence which are the values used for grouping in order for the application to make the correspondence between the values in the result sequence and the groups. (Please see the Hash_Agg_Grouping page for a more detailed explanation.)

> The function signatures are of the following form unless specified in the table below:

>         MCO_RET mco_seq_hash_agg_operation_TYPE(mco_seq_iterator_h result_agg,
>                 mco_seq_iterator_h result_group_by,
>                 mco_seq_iterator_h input,
>                 mco_seq_iterator_h group_by,
>                 mco_size_t n_groups);

> where TYPE is one of the types listed in the Analytics Functions page and operation is one of the following:

> mco_seq_hash_agg_max_TYPE() | Returns the result sequence of the same `TYPE` with the maximum value for each group of elements
> mco_seq_hash_agg_min_TYPE() | Returns the result sequence of the same `TYPE` with the minimum value for each group of elements
> mco_seq_hash_agg_sum_TYPE() | Returns the result sequence of the same `TYPE` with the sum of each group of elements
> mco_seq_hash_agg_avg_TYPE() | Returns the `double` result sequence with the average of each group of elements
> mco_seq_hash_agg_approxdc() | Returns the `uint4` result sequence with the approximate distinct count for each group of elements
> mco_seq_hash_agg_count() | Returns the `uint8` result_count sequence with the count of the number of elements in each group
>         MCO_RET mco_seq_hash_agg_count(
>                 mco_seq_iterator_h result_count,
>                 mco_seq_iterator_h result_group_by,
>                 mco_seq_iterator_h group_by,
>                 mco_size_t n_groups);
> mco_seq_hash_agg_distinct_count() | Returns the `uint8` result_count sequence with the count of the number of distinct elements in each group
>         MCO_RET mco_seq_hash_agg_distinct_count(
>                 mco_seq_iterator_h result_count,
>                 mco_seq_iterator_h result_group_by,
>                 mco_seq_iterator_h input,
>                 mco_seq_iterator_h group_by,
>                 mco_size_t n_groups,
>                 mco_size_t n_pairs);
> mco_seq_hash_agg_dup_count() | Returns the `uint8` result_count sequence with the count of duplicates in each group. Parameter `min_occurrences` specifies minimal number for occurrences of a particular value to be counted. With `min_occurrences=1` this function is equivalent to `mco_seq_hash_agg_distinct_count()`, with `min_occurrences=2` it counts items encountered more than once... If `n_pairs` parameter is 0, then `mco_seq_hash_init_size` is used to specify size of hash table and it is automatically extended when the threshold determined by `mco_seq_hash_load_factor` is reached.
>         MCO_RET mco_seq_hash_agg_dup_count(
>                 mco_seq_iterator_h result_count,
>                 mco_seq_iterator_h result_group_by,
>                 mco_seq_iterator_h input,
>                 mco_seq_iterator_h group_by,
>                 mco_size_t n_groups,
>                 mco_size_t n_pairs,
>                 mco_size_t min_occurrences);
> mco_seq_is_hash_aggreate() | Returns `true` if the iterator is the result of hash aggregation
>         mco_bool mco_seq_is_hash_aggreate(
>                 mco_seq_iterator_h iterator);

> ## Example

> Following is an example code snippet demonstrating how to use a hash aggregate function 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))
>             {
>                 Quote_from_cursor(trans, &quote_cursor, &quote);
>                 Quote_close_iterator(&quote, &close_iterator);
>                 Quote_volume_iterator(&quote, &volume_iterator);

>                 rc = mco_seq_const_uint4(&const_iterator, 10));
>                 rc = mco_seq_div_uint4(&volume_div_10_iterator, &volume_iterator, &const_iterator);

>                 rc = mco_seq_hash_agg_avg_float(&avg_iterator, &group_iterator,

>                         &close_iterator, &volume_div_10_iterator, 0);

>                 ...
>                 mco_seq_free_hash(&avg_iterator);
>             }
>             ...
>         }