MCPcopy Create free account
hub / github.com/ceph/ceph / swap

Method swap

src/include/cpp-btree/btree.h:1689–1732  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1687
1688template <typename P>
1689void btree_node<P>::swap(btree_node *x, allocator_type *alloc) {
1690 using std::swap;
1691 assert(leaf() == x->leaf());
1692
1693 // Determine which is the smaller/larger node.
1694 btree_node *smaller = this, *larger = x;
1695 if (smaller->count() > larger->count()) {
1696 swap(smaller, larger);
1697 }
1698
1699 // Swap the values.
1700 std::swap_ranges(smaller->slot(0), smaller->slot(smaller->count()),
1701 larger->slot(0));
1702
1703 // Move values that can't be swapped.
1704 const size_type to_move = larger->count() - smaller->count();
1705 larger->uninitialized_move_n(to_move, smaller->count(), smaller->count(),
1706 smaller, alloc);
1707 larger->value_destroy_n(smaller->count(), to_move, alloc);
1708
1709 if (!leaf()) {
1710 // Swap the child pointers.
1711 auto* smaller_begin = &smaller->mutable_child(0);
1712 auto* larger_begin = &larger->mutable_child(0);
1713 auto count = smaller->count() + 1;
1714 std::swap_ranges(smaller_begin,
1715 smaller_begin + count,
1716 larger_begin);
1717 // Update swapped children's parent pointers.
1718 int i = 0;
1719 for (; i <= smaller->count(); ++i) {
1720 smaller->child(i)->set_parent(smaller);
1721 larger->child(i)->set_parent(larger);
1722 }
1723 // Move the child pointers that couldn't be swapped.
1724 for (; i <= larger->count(); ++i) {
1725 smaller->init_child(i, larger->child(i));
1726 larger->clear_child(i);
1727 }
1728 }
1729
1730 // Swap the counts.
1731 swap(mutable_count(), x->mutable_count());
1732}
1733
1734////
1735// btree_iterator methods

Callers 3

swapFunction · 0.45
swapFunction · 0.45
internal_emplaceMethod · 0.45

Calls 13

assertFunction · 0.85
allocatorFunction · 0.85
leafMethod · 0.80
uninitialized_move_nMethod · 0.80
value_destroy_nMethod · 0.80
set_parentMethod · 0.80
childMethod · 0.80
init_childMethod · 0.80
clear_childMethod · 0.80
mutable_key_compMethod · 0.80
swapFunction · 0.70
countMethod · 0.45

Tested by

no test coverage detected