Esempio n. 1
0
ptree_ptr ptree_leaf::merge(ptree_ptr other) const
{
	if (m_merkle != other->merkle()) {
		// If there is a mismatch, fail hard
		return ptree_ptr();
	}
	// Otherwise, return me
	return shared_from_this();
}
Esempio n. 2
0
ptree_ptr ptree_proxy::merge(ptree_ptr other) const
{
	if (other->merkle() != m_merkle) {
		// If there is a mismatch, fail hard
		return ptree_ptr();
	}
	// Otherwise, anything is better than me
	return other;
}
Esempio n. 3
0
ptree_ptr ptree_branch::merge(ptree_ptr other) const
{
	if (m_merkle != other->merkle()) {
		// If there is a mismatch, fail hard
		return ptree_ptr();
	}
	if (complete() || other->is_proxy()) {
		// If I am complete, or the other side is a proxy
		// pick this entry
		return shared_from_this();
	}
	// At this point, othe side should be a branch
	shared_ptr<const ptree_branch> obranch = std::dynamic_pointer_cast<const ptree_branch>(other);
	if (!obranch) {
		// If not, fail
		return ptree_ptr(); 
	}
	// Merge both children
	return make_shared<ptree_branch>(m_split_pos,
		m_branches[0]->merge(obranch->m_branches[0]),
		m_branches[1]->merge(obranch->m_branches[1]));
}
Esempio n. 4
0
static void write_proxy(writable& out, const ptree_ptr& p) {
	out.write(pid_proxy);
	out.write(p->node_count());
	out.write(p->merkle());
}