2#include "./permutation_container.hpp"
3#include "./bp_internal_node_template.hpp"
8 using ___PermutationTree = bptree::BPTree<bptree::PermutationContainer, bptree::PermutationItem, true, false, bptree::DEFAULT_MAX_DEGREE_OF_INTERNAL_NODE, bptree::PermutationContainer::___PermutationLeafSize>;
9 using ___PermutationNode = ___PermutationTree::Node;
12 void ___PermutationTree::move_values_right(___PermutationNode *left_node, ___PermutationNode *right_node, uint64_t len,
bool is_leaf, ___PermutationNode *parent, int64_t parent_edge_index_of_left_node)
14 using BPTree = BPTree<bptree::PermutationContainer, bptree::PermutationItem, true, false, bptree::DEFAULT_MAX_DEGREE_OF_INTERNAL_NODE, bptree::DEFAULT_MAX_COUNT_OF_VALUES_IN_LEAF>;
17 uint64_t left_leaf = (uint64_t)left_node;
18 uint64_t right_leaf = (uint64_t)right_node;
19 assert(left_leaf < this->leaf_container_vec.size());
20 assert(right_leaf < this->leaf_container_vec.size());
22 if (parent !=
nullptr)
25 auto &parent_count_deq = parent->get_value_count_deque();
27 parent_count_deq.decrement(parent_edge_index_of_left_node, len);
28 parent_count_deq.increment(parent_edge_index_of_left_node + 1, len);
37 for (uint64_t i = 0; i < len; i++)
39 bptree::PermutationItem item = this->leaf_container_vec[left_leaf].pop_back();
40 this->leaf_container_vec[right_leaf].push_front(item);
41 if (this->linked_tree_ !=
nullptr && item.pointer < this->linked_tree_->get_leaf_container_vector_size())
43 leaf_container_vec[right_leaf].update_linked_tree(0, right_leaf, left_leaf, *this->linked_tree_);
53 BPTree::BPFunctions::move_right(*left_node, *right_node, len, parent, parent_edge_index_of_left_node, this->parent_vec);
57 void ___PermutationTree::preprocess_for_the_exchange_of_two_leaves(uint64_t leaf_index1, uint64_t leaf_index2)
61 uint64_t dummy_index = this->leaf_container_vec.size();
62 if (this->parent_vec[leaf_index1] !=
nullptr)
64 bptree::PermutationContainer &leaf1 = this->leaf_container_vec[leaf_index1];
66 uint64_t x_idnex = this->parent_vec[leaf_index2] ==
nullptr ? leaf_index2 : dummy_index;
67 for (
const bptree::PermutationItem &it : leaf1)
71 bptree::PermutationContainer &leaf3 = this->linked_tree_->get_leaf_container(it.pointer);
72 int64_t idx = leaf3.get_index(bptree::PermutationItem(leaf_index1, it.key));
77 assert(tmp.pointer == leaf_index1);
82 if (this->parent_vec[leaf_index2] !=
nullptr)
84 bptree::PermutationContainer &leaf2 = this->leaf_container_vec[leaf_index2];
85 for (
const bptree::PermutationItem &it : leaf2)
89 bptree::PermutationContainer &leaf3 = this->linked_tree_->get_leaf_container(it.pointer);
90 int64_t idx = leaf3.get_index(bptree::PermutationItem(leaf_index2, it.key));
92 this->linked_tree_->print_leaves();
99 assert(tmp.pointer == leaf_index2);
104 for (
const bptree::PermutationItem &it : leaf1)
107 bptree::PermutationContainer &leaf3 = this->linked_tree_->get_leaf_container(it.pointer);
108 int64_t idx = leaf3.get_index(bptree::PermutationItem(dummy_index, it.key));
112 assert(tmp.pointer == dummy_index);
119 if (this->parent_vec[leaf_index2] !=
nullptr)
121 ___PermutationTree::preprocess_for_the_exchange_of_two_leaves(leaf_index2, leaf_index1);
128 void ___PermutationTree::move_values_left(___PermutationNode *left_node, ___PermutationNode *right_node, uint64_t len,
bool is_leaf, ___PermutationNode *parent, int64_t parent_edge_index_of_right_node)
132 uint64_t left_leaf = (uint64_t)left_node;
133 uint64_t right_leaf = (uint64_t)right_node;
134 assert(left_leaf < this->leaf_container_vec.size());
136 if (parent !=
nullptr)
138 auto &parent_count_deq = parent->get_value_count_deque();
139 parent_count_deq.decrement(parent_edge_index_of_right_node, len);
140 parent_count_deq.increment(parent_edge_index_of_right_node - 1, len);
143 for (uint64_t i = 0; i < len; i++)
145 bptree::PermutationItem item = this->leaf_container_vec[right_leaf].pop_front();
146 this->leaf_container_vec[left_leaf].push_back(item);
147 uint64_t _size = leaf_container_vec[left_leaf].size();
148 if (this->linked_tree_ !=
nullptr && item.pointer < this->linked_tree_->get_leaf_container_vector_size())
150 leaf_container_vec[left_leaf].update_linked_tree(_size - 1, left_leaf, right_leaf, *this->linked_tree_);
161 BPTree::BPFunctions::move_left(*left_node, *right_node, len, parent, parent_edge_index_of_right_node, this->parent_vec);