abandon changes in balancing algo

This commit is contained in:
hugogogo
2022-07-06 22:19:35 +02:00
parent 3280f4a754
commit ed7d1d1ed9
3 changed files with 38 additions and 60 deletions

View File

@@ -178,7 +178,6 @@ private:
void _balance(node<value_type>* n);
short _compute_height(node<value_type>* n);
short _balance_factor(node<value_type>* n);
short _balance_f(node<value_type>* n);
node<value_type>* _rotate_left(node<value_type>* n);
node<value_type>* _rotate_right(node<value_type>* n);
};

View File

@@ -425,25 +425,20 @@ MP_TPL void MP::
while (n)
{
n->height = _compute_height(n);
// n->height = _balance_f(n);
if (_balance_factor(n) > 1) // Left Heavy
// if (n->height > 1) // Left Heavy
{
parent = n->up;
if (_balance_factor(n->left) < 0) // Left-Right Case (BF == -1)
// if (n->left->height < 0) // Left-Right Case (BF == -1)
n->left = _rotate_left(n->left);
// Left-Left Case
n = _rotate_right(n);
old_n = n->right;
}
// else if (_balance_factor(n) < -1) // Right Heavy
else if (n->height < -1) // Right Heavy
else if (_balance_factor(n) < -1) // Right Heavy
{
parent = n->up;
if (_balance_factor(n->right) > 0) // Right-Left Case (BF == 1)
// if (n->right->height > 0) // Right-Left Case (BF == 1)
n->right = _rotate_right(n->right);
// Right-Right Case
n = _rotate_left(n);
@@ -474,18 +469,6 @@ MP_TPL short MP::
else
return 1;
}
MP_TPL short MP::
_balance_f(node<value_type>* n) {
if (n->left && n->right)
return n->left->height - n->right->height;
else if (n->left)
return (n->left->height + 1);
else if (n->right)
return (-1 - (n->right->height));
else
return 0;
}
MP_TPL short MP::
_balance_factor(node<value_type>* n) {
@@ -513,8 +496,6 @@ MP_TPL node<typename MP::value_type>* MP::
n->height = _compute_height(n);
ori_right->height = _compute_height(ori_right);
// n->height = _balance_f(n);
// ori_right->height = _balance_f(ori_right);
if (n == _root)
{
@@ -539,8 +520,6 @@ MP_TPL node<typename MP::value_type>* MP::
n->height = _compute_height(n);
ori_left->height = _compute_height(ori_left);
// n->height = _balance_f(n);
// ori_left->height = _balance_f(ori_left);
if (n == _root)
{

View File

@@ -4,35 +4,35 @@
int main() {
// VECTOR
// tests_vector_constructor();
// tests_vector_operator_assignation();
// tests_vector_begin();
// tests_vector_end();
// tests_vector_rbegin();
// tests_vector_rend();
// tests_vector_size();
// tests_vector_max_size();
// tests_vector_resize();
// tests_vector_capacity();
// tests_vector_empty();
// tests_vector_reserve();
// tests_vector_operator_access();
// tests_vector_at();
// tests_vector_front();
// tests_vector_back();
// tests_vector_assign();
// tests_vector_push_back();
// tests_vector_pop_back();
// tests_vector_insert();
// tests_vector_erase();
// tests_vector_swap();
// tests_vector_clear();
// tests_vector_get_allocator();
// tests_vector_swap_non_member();
// tests_vector_reverse_iterators();
// tests_vector_relational_operators();
//
// // MAP
tests_vector_constructor();
tests_vector_operator_assignation();
tests_vector_begin();
tests_vector_end();
tests_vector_rbegin();
tests_vector_rend();
tests_vector_size();
tests_vector_max_size();
tests_vector_resize();
tests_vector_capacity();
tests_vector_empty();
tests_vector_reserve();
tests_vector_operator_access();
tests_vector_at();
tests_vector_front();
tests_vector_back();
tests_vector_assign();
tests_vector_push_back();
tests_vector_pop_back();
tests_vector_insert();
tests_vector_erase();
tests_vector_swap();
tests_vector_clear();
tests_vector_get_allocator();
tests_vector_swap_non_member();
tests_vector_reverse_iterators();
tests_vector_relational_operators();
// MAP
tests_map_simple();
tests_map_constructor();
tests_map_operator_assignation();
@@ -58,14 +58,14 @@ int main() {
tests_map_get_allocator();
tests_map_swap_non_member();
tests_map_relational_operators();
//
// // STACK
// tests_stack_constructor();
// tests_stack_empty();
// tests_stack_size();
// tests_stack_top();
// tests_stack_push();
// tests_stack_pop();
// STACK
tests_stack_constructor();
tests_stack_empty();
tests_stack_size();
tests_stack_top();
tests_stack_push();
tests_stack_pop();
// execute tests and print them :
int size = test_list.size();