2#include "./permutation_container.hpp"
3#include "./bp_internal_node_template.hpp"
8 using ___PermutationTree = bptree::BPTree<bptree::PermutationContainer, bptree::PermutationItem, bptree::DEFAULT_MAX_DEGREE_OF_INTERNAL_NODE, bptree::PermutationContainer::___PermutationLeafSize, true, false>;
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, bptree::DEFAULT_MAX_DEGREE_OF_INTERNAL_NODE, bptree::DEFAULT_MAX_COUNT_OF_VALUES_IN_LEAF, true, false>;
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 parent->decrement_on_count_deque(parent_edge_index_of_left_node, len);
26 parent->increment_on_count_deque(parent_edge_index_of_left_node + 1, len);
35 for (uint64_t i = 0; i < len; i++)
37 bptree::PermutationItem item = this->leaf_container_vec[left_leaf].pop_back();
38 this->leaf_container_vec[right_leaf].push_front(item);
39 if (this->linked_tree_ !=
nullptr && item.pointer < this->linked_tree_->get_leaf_container_vector_size())
41 leaf_container_vec[right_leaf].update_linked_tree(0, right_leaf, left_leaf, *this->linked_tree_);
51 BPTree::BPFunctions::move_right(*left_node, *right_node, len, parent, parent_edge_index_of_left_node, this->parent_vec);
55 void ___PermutationTree::preprocess_for_the_exchange_of_two_leaves(uint64_t leaf_index1, uint64_t leaf_index2)
59 uint64_t dummy_index = this->leaf_container_vec.size();
60 if (this->parent_vec[leaf_index1] !=
nullptr)
62 bptree::PermutationContainer &leaf1 = this->leaf_container_vec[leaf_index1];
64 uint64_t x_idnex = this->parent_vec[leaf_index2] ==
nullptr ? leaf_index2 : dummy_index;
65 for (
const bptree::PermutationItem &it : leaf1)
69 bptree::PermutationContainer &leaf3 = this->linked_tree_->get_leaf_container(it.pointer);
70 int64_t idx = leaf3.get_index(bptree::PermutationItem(leaf_index1, it.key));
75 assert(tmp.pointer == leaf_index1);
80 if (this->parent_vec[leaf_index2] !=
nullptr)
82 bptree::PermutationContainer &leaf2 = this->leaf_container_vec[leaf_index2];
83 for (
const bptree::PermutationItem &it : leaf2)
87 bptree::PermutationContainer &leaf3 = this->linked_tree_->get_leaf_container(it.pointer);
88 int64_t idx = leaf3.get_index(bptree::PermutationItem(leaf_index2, it.key));
90 this->linked_tree_->print_leaves();
97 assert(tmp.pointer == leaf_index2);
102 for (
const bptree::PermutationItem &it : leaf1)
105 bptree::PermutationContainer &leaf3 = this->linked_tree_->get_leaf_container(it.pointer);
106 int64_t idx = leaf3.get_index(bptree::PermutationItem(dummy_index, it.key));
110 assert(tmp.pointer == dummy_index);
117 if (this->parent_vec[leaf_index2] !=
nullptr)
119 ___PermutationTree::preprocess_for_the_exchange_of_two_leaves(leaf_index2, leaf_index1);
126 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)
130 uint64_t left_leaf = (uint64_t)left_node;
131 uint64_t right_leaf = (uint64_t)right_node;
132 assert(left_leaf < this->leaf_container_vec.size());
134 if (parent !=
nullptr)
136 parent->decrement_on_count_deque(parent_edge_index_of_right_node, len);
137 parent->increment_on_count_deque(parent_edge_index_of_right_node - 1, len);
140 for (uint64_t i = 0; i < len; i++)
142 bptree::PermutationItem item = this->leaf_container_vec[right_leaf].pop_front();
143 this->leaf_container_vec[left_leaf].push_back(item);
144 uint64_t _size = leaf_container_vec[left_leaf].size();
145 if (this->linked_tree_ !=
nullptr && item.pointer < this->linked_tree_->get_leaf_container_vector_size())
147 leaf_container_vec[left_leaf].update_linked_tree(_size - 1, left_leaf, right_leaf, *this->linked_tree_);
158 BPTree::BPFunctions::move_left(*left_node, *right_node, len, parent, parent_edge_index_of_right_node, this->parent_vec);