Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor C++, misc. C++ fixes #1233

Merged
merged 5 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/perspective/src/cpp/aggspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ t_aggspec::get_inv_mode() const {
std::vector<std::string>
t_aggspec::get_input_depnames() const {
std::vector<std::string> rval;
rval.reserve(m_dependencies.size());
for (const auto & d : m_dependencies) {
rval.push_back(d.name());
}
Expand All @@ -273,6 +274,7 @@ t_aggspec::get_input_depnames() const {
std::vector<std::string>
t_aggspec::get_output_depnames() const {
std::vector<std::string> rval;
rval.reserve(m_dependencies.size());
for (const auto & d: m_dependencies) {
rval.push_back(d.name());
}
Expand Down Expand Up @@ -331,6 +333,7 @@ t_aggspec::get_output_specs(const t_schema& schema) const {
case AGGTYPE_UDF_COMBINER:
case AGGTYPE_UDF_REDUCER: {
std::vector<t_col_name_type> rval;
rval.reserve(m_odependencies.size());
for (const auto& d : m_odependencies) {
t_col_name_type tp(d.name(), d.dtype());
rval.push_back(tp);
Expand Down
22 changes: 0 additions & 22 deletions cpp/perspective/src/cpp/context_grouped_pkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ t_ctx_grouped_pkey::init() {
m_tree = std::make_shared<t_stree>(pivots, m_config.get_aggregates(), m_schema, m_config);
m_tree->init();
m_traversal = std::shared_ptr<t_traversal>(new t_traversal(m_tree));
m_minmax = std::vector<t_minmax>(m_config.get_num_aggregates());
m_init = true;
}

Expand Down Expand Up @@ -194,7 +193,6 @@ void
t_ctx_grouped_pkey::step_end() {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
m_minmax = m_tree->get_min_max();
sort_by(m_sortby);
if (m_depth_set) {
set_depth(m_depth);
Expand Down Expand Up @@ -395,19 +393,6 @@ t_ctx_grouped_pkey::set_deltas_enabled(bool enabled_state) {
m_tree->set_deltas_enabled(enabled_state);
}

void
t_ctx_grouped_pkey::set_minmax_enabled(bool enabled_state) {
m_features[CTX_FEAT_MINMAX] = enabled_state;
m_tree->set_minmax_enabled(enabled_state);
}

std::vector<t_minmax>
t_ctx_grouped_pkey::get_min_max() const {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
return m_minmax;
}

t_stepdelta
t_ctx_grouped_pkey::get_step_delta(t_index bidx, t_index eidx) {
PSP_TRACE_SENTINEL();
Expand Down Expand Up @@ -472,13 +457,6 @@ t_ctx_grouped_pkey::has_deltas() const {
return true;
}

t_minmax
t_ctx_grouped_pkey::get_agg_min_max(t_uindex aggidx, t_depth depth) const {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
return m_tree->get_agg_min_max(aggidx, depth);
}

template <typename DATA_T>
void
rebuild_helper(t_column*) {}
Expand Down
22 changes: 0 additions & 22 deletions cpp/perspective/src/cpp/context_one.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ t_ctx1::init() {
m_tree = std::make_shared<t_stree>(pivots, m_config.get_aggregates(), m_schema, m_config);
m_tree->init();
m_traversal = std::shared_ptr<t_traversal>(new t_traversal(m_tree));
m_minmax = std::vector<t_minmax>(m_config.get_num_aggregates());
m_init = true;
}

Expand Down Expand Up @@ -233,7 +232,6 @@ void
t_ctx1::step_end() {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
m_minmax = m_tree->get_min_max();
sort_by(m_sortby);
if (m_depth_set) {
set_depth(m_depth);
Expand Down Expand Up @@ -388,19 +386,6 @@ t_ctx1::set_deltas_enabled(bool enabled_state) {
m_tree->set_deltas_enabled(enabled_state);
}

void
t_ctx1::set_minmax_enabled(bool enabled_state) {
m_features[CTX_FEAT_MINMAX] = enabled_state;
m_tree->set_minmax_enabled(enabled_state);
}

std::vector<t_minmax>
t_ctx1::get_min_max() const {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
return m_minmax;
}

/**
* @brief Returns updated cells.
*
Expand Down Expand Up @@ -514,13 +499,6 @@ t_ctx1::has_deltas() const {
return m_tree->has_deltas();
}

t_minmax
t_ctx1::get_agg_min_max(t_uindex aggidx, t_depth depth) const {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
return m_tree->get_agg_min_max(aggidx, depth);
}

void
t_ctx1::notify(const t_data_table& flattened) {
PSP_TRACE_SENTINEL();
Expand Down
15 changes: 0 additions & 15 deletions cpp/perspective/src/cpp/context_two.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ t_ctx2::init() {
m_rtraversal = std::make_shared<t_traversal>(rtree());

m_ctraversal = std::make_shared<t_traversal>(ctree());
m_minmax = std::vector<t_minmax>(m_config.get_num_aggregates());
m_init = true;
}

Expand All @@ -80,7 +79,6 @@ t_ctx2::step_begin() {

void
t_ctx2::step_end() {
m_minmax = m_trees.back()->get_min_max();
if (m_row_depth_set) {
set_depth(HEADER_ROW, m_row_depth);
}
Expand Down Expand Up @@ -782,11 +780,6 @@ t_ctx2::get_rows_changed() {
return rows;
}

std::vector<t_minmax>
t_ctx2::get_min_max() const {
return m_minmax;
}

void
t_ctx2::reset() {
for (t_uindex treeidx = 0, tree_loop_end = m_trees.size(); treeidx < tree_loop_end;
Expand Down Expand Up @@ -849,14 +842,6 @@ t_ctx2::set_deltas_enabled(bool enabled_state) {
}
}

void
t_ctx2::set_minmax_enabled(bool enabled_state) {
m_features[CTX_FEAT_MINMAX] = enabled_state;
for (auto& tr : m_trees) {
tr->set_minmax_enabled(enabled_state);
}
}

std::vector<t_stree*>
t_ctx2::get_trees() {
std::vector<t_stree*> rval(m_trees.size());
Expand Down
59 changes: 1 addition & 58 deletions cpp/perspective/src/cpp/context_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ t_ctx0::t_ctx0() {}

t_ctx0::t_ctx0(const t_schema& schema, const t_config& config)
: t_ctxbase<t_ctx0>(schema, config)
, m_minmax(m_config.get_num_columns())
, m_has_delta(false)

{}
Expand Down Expand Up @@ -55,36 +54,6 @@ t_ctx0::step_end() {
}

m_traversal->step_end();
#ifndef PSP_ENABLE_WASM
t_uindex ncols = m_config.get_num_columns();
std::vector<t_minmax> rval(ncols);

auto pkeys = m_traversal->get_pkeys();
auto stbl = m_gstate->get_table();

#ifdef PSP_PARALLEL_FOR
tbb::parallel_for(0, int(ncols), 1,
[&rval, &stbl, pkeys, this](int colidx)
#else
for (t_uindex colidx = 0; colidx < ncols; ++colidx)
#endif
{
auto colname = m_config.col_at(colidx);

if (stbl->get_dtype(colname) != DTYPE_STR) {
auto v = m_gstate->reduce<std::function<std::pair<t_tscalar, t_tscalar>(
const std::vector<t_tscalar>&)>>(pkeys, colname, get_vec_min_max);

rval[colidx].m_min = v.first;
rval[colidx].m_max = v.second;
}
}
#ifdef PSP_PARALLEL_FOR
);
#endif

m_minmax = rval;
#endif
}

t_index
Expand Down Expand Up @@ -372,7 +341,6 @@ void
t_ctx0::reset() {
m_traversal->reset();
m_deltas = std::make_shared<t_zcdeltas>();
m_minmax = std::vector<t_minmax>(m_config.get_num_columns());
m_has_delta = false;
}

Expand Down Expand Up @@ -439,11 +407,6 @@ t_ctx0::notify(const t_data_table& flattened, const t_data_table& delta,
}
psp_log_time(repr() + " notify.has_filter_path.updated_traversal");

// calculate cell deltas if enabled
if (get_deltas_enabled()) {
calc_step_delta(flattened, prev, curr, transitions);
}

m_has_delta = m_deltas->size() > 0 || m_delta_pkeys.size() > 0 || delete_encountered;

psp_log_time(repr() + " notify.has_filter_path.exit");
Expand Down Expand Up @@ -479,10 +442,7 @@ t_ctx0::notify(const t_data_table& flattened, const t_data_table& delta,

psp_log_time(repr() + " notify.no_filter_path.updated_traversal");

// calculate cell deltas if enabled
if (get_deltas_enabled()) {
calc_step_delta(flattened, prev, curr, transitions);
}

m_has_delta = m_deltas->size() > 0 || m_delta_pkeys.size() > 0 || delete_encountered;

psp_log_time(repr() + " notify.no_filter_path.exit");
Expand Down Expand Up @@ -521,12 +481,6 @@ t_ctx0::notify(const t_data_table& flattened) {
add_delta_pkey(pkey);
}

// Calculate the step delta, if enabled in the context through an on_update
// callback with the "cell" or "row" mode set.
if (get_deltas_enabled()) {
calc_step_delta(flattened);
}

return;
}

Expand All @@ -545,12 +499,6 @@ t_ctx0::notify(const t_data_table& flattened) {
// Add primary key to track row delta
add_delta_pkey(pkey);
}

// Calculate the step delta, if enabled in the context through an on_update
// callback with the "cell" or "row" mode set.
if (get_deltas_enabled()) {
calc_step_delta(flattened);
}
}

void
Expand Down Expand Up @@ -633,11 +581,6 @@ t_ctx0::add_delta_pkey(t_tscalar pkey) {
m_delta_pkeys.insert(pkey);
}

std::vector<t_minmax>
t_ctx0::get_min_max() const {
return m_minmax;
}

void
t_ctx0::reset_step_state() {
m_traversal->reset_step_state();
Expand Down
4 changes: 4 additions & 0 deletions cpp/perspective/src/cpp/data_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ t_data_table::append(const t_data_table& other) {
std::vector<const t_column*> src_cols;
std::vector<t_column*> dst_cols;

src_cols.reserve(other.m_schema.m_columns.size());
dst_cols.reserve(m_schema.m_columns.size());

std::set<std::string> incoming;

for (const auto& cname : other.m_schema.m_columns) {
Expand Down Expand Up @@ -586,6 +589,7 @@ t_data_table::borrow(const std::vector<std::string>& columns) const {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
std::vector<t_dtype> dtypes;
dtypes.reserve(columns.size());

for (const auto& col : columns) {
dtypes.push_back(m_schema.get_dtype(col));
Expand Down
8 changes: 5 additions & 3 deletions cpp/perspective/src/cpp/emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,7 @@ namespace binding {
// Fill the computed columns vector with tuples
auto js_computed_columns = config.call<std::vector<std::vector<t_val>>>("get_computed_columns");
std::vector<t_computed_column_definition> computed_columns;
computed_columns.reserve(js_computed_columns.size());

for (auto c : js_computed_columns) {
std::string computed_column_name = c.at(0).as<std::string>();
Expand All @@ -1411,9 +1412,9 @@ namespace binding {
* as all lookups into `schema` must be valid for all computed
* columns on the View.
*/
std::vector<t_dtype> input_types;
for (const auto& input_column : input_columns) {
input_types.push_back(schema->get_dtype(input_column));
std::vector<t_dtype> input_types(input_columns.size());
for (auto i = 0; i < input_columns.size(); ++i) {
input_types[i] = schema->get_dtype(input_columns[i]);
}

t_computation computation = t_computed_column::get_computation(
Expand Down Expand Up @@ -1631,6 +1632,7 @@ namespace binding {
std::vector<std::vector<t_val>> j_computed_columns) {
// Convert into vector of tuples
std::vector<t_computed_column_definition> computed_columns;
computed_columns.reserve(j_computed_columns.size());

for (auto c : j_computed_columns) {
std::string computed_column_name = c.at(0).as<std::string>();
Expand Down
1 change: 1 addition & 0 deletions cpp/perspective/src/cpp/flat_traversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ t_ftrav::step_end() {
t_uindex i = 0;
t_multisorter sorter(get_sort_orders(m_sortby));
std::vector<t_mselem> new_rows;
new_rows.reserve(m_new_elems.size());

for (t_pkmselem_map::const_iterator pkelem_iter = m_new_elems.begin();
pkelem_iter != m_new_elems.end(); ++pkelem_iter) {
Expand Down
14 changes: 6 additions & 8 deletions cpp/perspective/src/cpp/gnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ t_gnode::_update_contexts_from_state(std::shared_ptr<t_data_table> tbl) {
std::vector<std::string>
t_gnode::get_registered_contexts() const {
std::vector<std::string> rval;
rval.reserve(m_contexts.size());

for (const auto& kv : m_contexts) {
std::stringstream ss;
Expand Down Expand Up @@ -1022,16 +1023,14 @@ void
t_gnode::_compute_column(
const t_computed_column_definition& computed_column,
std::shared_ptr<t_data_table> tbl) {
std::vector<t_dtype> input_types;
std::vector<std::shared_ptr<t_column>> input_columns;

std::string computed_column_name = std::get<0>(computed_column);
std::vector<std::string> input_column_names = std::get<2>(computed_column);
t_computation computation = std::get<3>(computed_column);

for (const auto& name : input_column_names) {
auto column = tbl->get_column(name);
input_columns.push_back(column);

std::vector<std::shared_ptr<t_column>> input_columns(input_column_names.size());

for (auto i = 0; i < input_column_names.size(); ++i) {
input_columns[i] = tbl->get_column(input_column_names[i]);
}

if (computation.m_name == INVALID_COMPUTED_FUNCTION) {
Expand Down Expand Up @@ -1062,7 +1061,6 @@ t_gnode::_recompute_column(
std::shared_ptr<t_data_table> table,
std::shared_ptr<t_data_table> flattened,
const std::vector<t_rlookup>& changed_rows) {
std::vector<t_dtype> input_types;
std::vector<std::shared_ptr<t_column>> table_columns;
std::vector<std::shared_ptr<t_column>> flattened_columns;

Expand Down
Loading