node_type *refresh(node_type *p) const { if(p == nullptr){ return nullptr; } value_type cache = p->value; if(p->children[0] != nullptr){ cache = m_traits(p->children[0]->cache, cache); } if(p->children[1] != nullptr){ cache = m_traits(cache, p->children[1]->cache); } p->size = 1 + size(p->children[0]) + size(p->children[1]); p->cache = m_traits.resolve(p->size, cache, p->modifier); return p; }
void propagate(node_type *p) const { if(p == nullptr){ return; } const size_t k = size(p->children[0]); const auto mod_l_cr = m_traits.split_modifier(p->modifier, k); const auto mod_c_r = m_traits.split_modifier(mod_l_cr.second, 1); if(p->children[0] != nullptr){ p->children[0]->modifier = m_traits.merge_modifier( p->children[0]->modifier, mod_l_cr.first); refresh(p->children[0]); } if(p->children[1] != nullptr){ p->children[1]->modifier = m_traits.merge_modifier( p->children[1]->modifier, mod_c_r.second); refresh(p->children[1]); } p->value = m_traits.resolve(1, p->value, mod_c_r.first); p->modifier= m_traits.default_modifier(); }