in include/PatriciaTreeSet.h [492:535]
inline bool is_subset_of(
const boost::intrusive_ptr<PatriciaTree<IntegerType>>& tree1,
const boost::intrusive_ptr<PatriciaTree<IntegerType>>& tree2) {
if (tree1 == tree2) {
// This conditions allows the inclusion test to run in sublinear time
// when comparing Patricia trees that share some structure.
return true;
}
if (tree1 == nullptr) {
return true;
}
if (tree2 == nullptr) {
return false;
}
if (tree1->is_leaf()) {
const auto& leaf =
boost::static_pointer_cast<PatriciaTreeLeaf<IntegerType>>(tree1);
return contains(leaf->key(), tree2);
}
if (tree2->is_leaf()) {
return false;
}
const auto& branch1 =
boost::static_pointer_cast<PatriciaTreeBranch<IntegerType>>(tree1);
const auto& branch2 =
boost::static_pointer_cast<PatriciaTreeBranch<IntegerType>>(tree2);
if (branch1->prefix() == branch2->prefix() &&
branch1->branching_bit() == branch2->branching_bit()) {
return is_subset_of(branch1->left_tree(), branch2->left_tree()) &&
is_subset_of(branch1->right_tree(), branch2->right_tree());
}
if (branch1->branching_bit() > branch2->branching_bit() &&
match_prefix(
branch1->prefix(), branch2->prefix(), branch2->branching_bit())) {
if (is_zero_bit(branch1->prefix(), branch2->branching_bit())) {
return is_subset_of(branch1->left_tree(), branch2->left_tree()) &&
is_subset_of(branch1->right_tree(), branch2->left_tree());
} else {
return is_subset_of(branch1->left_tree(), branch2->right_tree()) &&
is_subset_of(branch1->right_tree(), branch2->right_tree());
}
}
return false;
}