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

Expansion depth should be stable across updates #277

Merged
merged 10 commits into from
Oct 19, 2018
Prev Previous commit
Next Next commit
Change grouped context api
  • Loading branch information
nmichaud committed Oct 16, 2018
commit 6593f710fc3f7440568bcfd69ad1d0f5dfa87e37
53 changes: 38 additions & 15 deletions src/cpp/context_grouped_pkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
#include <perspective/sparse_tree_node.h>
#include <perspective/logtime.h>
#include <perspective/traversal.h>
#include <perspective/env_vars.h>
#include <perspective/filter_utils.h>
#include <queue>
#include <tuple>
#include <unordered_set>

namespace perspective {

t_ctx_grouped_pkey::t_ctx_grouped_pkey()
: m_depth_set(false) {}

t_ctx_grouped_pkey::~t_ctx_grouped_pkey() {}

void
Expand Down Expand Up @@ -69,22 +73,30 @@ t_index
t_ctx_grouped_pkey::open(t_tvidx idx) {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
// If we manually open/close a node, stop automatically expanding
m_depth_set = false;

if (idx >= t_tvidx(m_traversal->size()))
return 0;

m_rows_changed = true;
return m_traversal->expand_node(m_sortby, idx);
t_index retval = m_traversal->expand_node(m_sortby, idx);
m_rows_changed = (retval > 0);
return retval;
}

t_index
t_ctx_grouped_pkey::close(t_tvidx idx) {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
// If we manually open/close a node, stop automatically expanding
m_depth_set = false;

if (idx >= t_tvidx(m_traversal->size()))
return 0;

m_rows_changed = true;
return m_traversal->collapse_node(idx);
t_index retval = m_traversal->collapse_node(idx);
m_rows_changed = (retval > 0);
return retval;
}

t_tscalvec
Expand Down Expand Up @@ -172,6 +184,10 @@ 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);
}
}

t_aggspecvec
Expand Down Expand Up @@ -258,18 +274,19 @@ t_ctx_grouped_pkey::sort_by(const t_sortsvec& sortby) {
}

void
t_ctx_grouped_pkey::expand_to_depth(t_depth depth) {
t_ctx_grouped_pkey::set_depth(t_depth depth) {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
t_depth expand_depth = std::min<t_depth>(m_config.get_num_rpivots() - 1, depth);
m_traversal->expand_to_depth(m_sortby, expand_depth);
}

void
t_ctx_grouped_pkey::collapse_to_depth(t_depth depth) {
PSP_TRACE_SENTINEL();
PSP_VERBOSE_ASSERT(m_init, "touching uninited object");
m_traversal->collapse_to_depth(depth);
t_depth final_depth = std::min<t_depth>(m_config.get_num_rpivots() - 1, depth);
t_index retval = 0;
if (depth >= m_depth) {
retval = m_traversal->expand_to_depth(m_sortby, final_depth);
} else {
retval = m_traversal->collapse_to_depth(final_depth);
}
m_rows_changed = (retval > 0);
m_depth = depth;
m_depth_set = true;
}

t_tscalvec
Expand Down Expand Up @@ -424,7 +441,13 @@ t_ctx_grouped_pkey::reset() {
}

void
t_ctx_grouped_pkey::reset_step_state() {}
t_ctx_grouped_pkey::reset_step_state() {
m_rows_changed = false;
m_columns_changed = false;
if (t_env::log_progress()) {
std::cout << "t_ctx_grouped_pkey.reset_step_state " << repr() << std::endl;
}
}

t_streeptr_vec
t_ctx_grouped_pkey::get_trees() {
Expand Down
5 changes: 3 additions & 2 deletions src/include/perspective/context_grouped_pkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class PERSPECTIVE_EXPORT t_ctx_grouped_pkey : public t_ctxbase<t_ctx_grouped_pke
t_ftnvec get_flattened_tree(t_tvidx idx, t_depth stop_depth);
t_trav_csptr get_traversal() const;

void expand_to_depth(t_depth depth);
void collapse_to_depth(t_depth depth);
void set_depth(t_depth depth);

void expand_path(const t_tscalvec& path);

Expand All @@ -62,6 +61,8 @@ class PERSPECTIVE_EXPORT t_ctx_grouped_pkey : public t_ctxbase<t_ctx_grouped_pke
t_sortsvec m_sortby;
t_symtable m_symtable;
t_bool m_has_label;
t_depth m_depth;
t_bool m_depth_set;
};

typedef std::shared_ptr<t_ctx_grouped_pkey> t_ctx_grouped_pkey_sptr;
Expand Down