in include/PatriciaTreeMap.h [712:748]
inline bool equals(
const boost::intrusive_ptr<PatriciaTree<IntegerType, Value>>& tree1,
const boost::intrusive_ptr<PatriciaTree<IntegerType, Value>>& tree2) {
if (tree1 == tree2) {
// This conditions allows the equality test to run in sublinear time when
// comparing Patricia trees that share some structure.
return true;
}
if (tree1 == nullptr) {
return tree2 == nullptr;
}
if (tree2 == nullptr) {
return false;
}
if (tree1->is_leaf()) {
if (tree2->is_branch()) {
return false;
}
const auto& leaf1 =
boost::static_pointer_cast<PatriciaTreeLeaf<IntegerType, Value>>(tree1);
const auto& leaf2 =
boost::static_pointer_cast<PatriciaTreeLeaf<IntegerType, Value>>(tree2);
return leaf1->key() == leaf2->key() &&
Value::equals(leaf1->value(), leaf2->value());
}
if (tree2->is_leaf()) {
return false;
}
const auto& branch1 =
boost::static_pointer_cast<PatriciaTreeBranch<IntegerType, Value>>(tree1);
const auto& branch2 =
boost::static_pointer_cast<PatriciaTreeBranch<IntegerType, Value>>(tree2);
return branch1->prefix() == branch2->prefix() &&
branch1->branching_bit() == branch2->branching_bit() &&
equals(branch1->left_tree(), branch2->left_tree()) &&
equals(branch1->right_tree(), branch2->right_tree());
}