bool read_subtree(int pos, Ranges &subrange, Tree &tree) { PropertyDecisionNode &n = tree[pos]; int p = n.property = coder.read_int(0,nb_properties)-1; if (p != -1) { int oldmin = subrange[p].first; int oldmax = subrange[p].second; if (oldmin >= oldmax) { e_printf( "Invalid tree. Aborting tree decoding.\n"); return false; } n.count = coder.read_int(CONTEXT_TREE_MIN_COUNT, CONTEXT_TREE_MAX_COUNT); // * CONTEXT_TREE_COUNT_QUANTIZATION; assert(oldmin < oldmax); int splitval = n.splitval = coder.read_int(oldmin, oldmax-1); int childID = n.childID = tree.size(); // e_printf( "Pos %i: prop %i splitval %i in [%i..%i]\n", pos, n.property, splitval, oldmin, oldmax-1); tree.push_back(PropertyDecisionNode()); tree.push_back(PropertyDecisionNode()); // > splitval subrange[p].first = splitval+1; if (!read_subtree(childID, subrange, tree)) return false; // <= splitval subrange[p].first = oldmin; subrange[p].second = splitval; if (!read_subtree(childID+1, subrange, tree)) return false; subrange[p].second = oldmax; } return true; }
Tree() : std::vector<PropertyDecisionNode>(1, PropertyDecisionNode()) {}
bool read_tree(Tree &tree) { Ranges rootrange(range); tree.clear(); tree.push_back(PropertyDecisionNode()); return read_subtree(0, rootrange, tree); }