packages/perspective/src/cpp/sparse_tree.cpp
// aggregates should be presized to be same size
// as agg_indices
aggregates should be presized to be same size
as agg_indices
aggregates should be presized to be same size as agg_indices
void
t_stree::get_aggregates(t_uindex nidx,
                        const t_idxvec& agg_indices,
                        t_tscalvec& aggregates,
                        t_ctx2 * ctx2) const
{
    t_uindex aggidx = get_aggidx(nidx);
    for (t_uindex idx = 0, loop_end = agg_indices.size();
         idx < loop_end;
         ++idx)
    {
        auto which_agg = agg_indices[idx];
       if(which_agg < 0)
        {
            aggregates[idx] = get_value(nidx);
        }
        else if( ctx2 || ( size_t(which_agg) >= m_aggcols.size() ) )
        {
			aggregates[idx].set(t_none());
            if(ctx2)
            {
				if( (ctx2->get_config().get_totals() == TOTALS_BEFORE) && (size_t(which_agg) < m_aggcols.size()) )
				{
					aggregates[idx] = m_aggcols[which_agg]->get_scalar(aggidx);
					continue;
				}
                t_tscalvec col_path = ctx2->get_column_path_userspace( which_agg+1 );
                if( col_path.empty() )
                {
                    if( ctx2->get_config().get_totals() == TOTALS_AFTER )
                    {
                        aggregates[idx] = m_aggcols[which_agg % m_aggcols.size()]->get_scalar(aggidx);
                    }
                    continue;
                }
                t_tscalvec row_path;
                get_path(nidx, row_path);
                auto target_tree = ctx2->get_trees()[ get_node(nidx).m_depth ];
                t_ptidx target = target_tree->resolve_path( 0, row_path );
                if( target != INVALID_INDEX )
                    target = target_tree->resolve_path( target, col_path );
                if( target != INVALID_INDEX )
                {
                    aggregates[idx] = target_tree->get_aggregate( target, which_agg % m_aggcols.size() );
                }
            }
        }
        else
        {
            aggregates[idx] =
                m_aggcols[which_agg]->get_scalar(aggidx);
        }
    }
}
void t_stree :: get_aggregates ( t_uindex nidx , const t_idxvec & agg_indices , t_tscalvec & aggregates , t_ctx2 * ctx2 ) const { t_uindex aggidx = get_aggidx ( nidx ) ; for ( t_uindex idx = 0 , loop_end = agg_indices . size ( ) ; idx < loop_end ; ++ idx ) { auto which_agg = agg_indices [ idx ] ; if ( which_agg < 0 ) { aggregates [ idx ] = get_value ( nidx ) ; } else if ( ctx2 || ( size_t ( which_agg ) >= m_aggcols . size ( ) ) ) { aggregates [ idx ] . set ( t_none ( ) ) ; if ( ctx2 ) { if ( ( ctx2 -> get_config ( ) . get_totals ( ) == TOTALS_BEFORE ) && ( size_t ( which_agg ) < m_aggcols . size ( ) ) ) { aggregates [ idx ] = m_aggcols [ which_agg ] -> get_scalar ( aggidx ) ; continue ; } t_tscalvec col_path = ctx2 -> get_column_path_userspace ( which_agg + 1 ) ; if ( col_path . empty ( ) ) { if ( ctx2 -> get_config ( ) . get_totals ( ) == TOTALS_AFTER ) { aggregates [ idx ] = m_aggcols [ which_agg % m_aggcols . size ( ) ] -> get_scalar ( aggidx ) ; } continue ; } t_tscalvec row_path ; get_path ( nidx , row_path ) ; auto target_tree = ctx2 -> get_trees ( ) [ get_node ( nidx ) . m_depth ] ; t_ptidx target = target_tree -> resolve_path ( 0 , row_path ) ; if ( target != INVALID_INDEX ) target = target_tree -> resolve_path ( target , col_path ) ; if ( target != INVALID_INDEX ) { aggregates [ idx ] = target_tree -> get_aggregate ( target , which_agg % m_aggcols . size ( ) ) ; } } } else { aggregates [ idx ] = m_aggcols [ which_agg ] -> get_scalar ( aggidx ) ; } } }
aggregates should be presized to be same size
as agg_indices
aggregates should be presized to be same size as agg_indices
// two sided pivoted column // we don't have enough information here to work out the shape of the data // so we have to use ctx2 to resolve // fetch the row/column path from ctx2