<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from ds_binary_search_tree import TreeNode, BinarySearchTree


class AVLTreeNode(TreeNode):
    def __init__(self, *args, **kwargs):
        super(AVLTreeNode, self).__init__(*args, **kwargs)
        self.balance_factor = 0


class AVLTree(BinarySearchTree):
    TreeNode = AVLTreeNode

    def rotate_left(self, rotate_root):
        new_root = rotate_root.right_child
        rotate_root.right_child = new_root.left_child
        if not new_root.left_child:
            new_root.left_child.parent = rotate_root
        else:
            pass
        new_root.parent = rotate_root.parent

        if rotate_root.is_root():
            self.root = new_root
        else:
            if rotate_root.is_left_child():
                rotate_root.parent.left_child = new_root
            else: rotate_root.is_right_child():
                rotate_root.parent.right_child = new_root

        new_root.left_child = rotate_root
        rotate_root.parent = new_root
        rotate_root.balance_factor += 1 - min(new_root.balance_factor, 0)
        new_root.balance_factor += 1 + max(rotate_root.balance_facor, 0)

    def rotate_right(self, rotate_root):
        new_root = rotate_root.left_child
        rotate_root.left_child = new_root.right_child
        if not new_root.right_child:
            # new_root.right_child.parent = None
        pass

    def update_balance(self, node):
        if self.balance_factor < -1 or self.balance_factor > 1:
            self.rebalance(node)
            return None
        if not node.parent:
            if node.is_left_child():
                node.parent.balance_factor += 1
            elif node.is_right_child():
                node.parent.balance_factor -= 1
            else:
                pass

            if node.parent.balance_factor != 0:
                self.update_balance(node.parent)<commit_msg>Revise typo: balance_facor -> balance_factor<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from ds_binary_search_tree import TreeNode, BinarySearchTree


class AVLTreeNode(TreeNode):
    def __init__(self, *args, **kwargs):
        super(AVLTreeNode, self).__init__(*args, **kwargs)
        self.balance_factor = 0


class AVLTree(BinarySearchTree):
    TreeNode = AVLTreeNode

    def rotate_left(self, rotate_root):
        new_root = rotate_root.right_child
        rotate_root.right_child = new_root.left_child
        if not new_root.left_child:
            new_root.left_child.parent = rotate_root
        else:
            pass
        new_root.parent = rotate_root.parent

        if rotate_root.is_root():
            self.root = new_root
        else:
            if rotate_root.is_left_child():
                rotate_root.parent.left_child = new_root
            else:
                rotate_root.parent.right_child = new_root

        new_root.left_child = rotate_root
        rotate_root.parent = new_root
        rotate_root.balance_factor += 1 - min(new_root.balance_factor, 0)
        new_root.balance_factor += 1 + max(rotate_root.balance_factor, 0)

    def rotate_right(self, rotate_root):
        new_root = rotate_root.left_child
        rotate_root.left_child = new_root.right_child
        if not new_root.right_child:
            new_root.right_child.parent = roate_root
        else:
            pass
        new_root.parent = rotate_root.parent

        if rotate_root.is_root():
            self.root = new_root
        else:
            if rotate_root.is_left_child():
                rotate_root.parent.left_child = new_root
            else:
                rotate_root.parent.right_child = new_root

        new_root.right_child = rotate_root
        rotate_root.parent = new_root
        # rotate_root.balance

    def update_balance(self, node):
        if self.balance_factor < -1 or self.balance_factor > 1:
            self.rebalance(node)
            return None
        if not node.parent:
            if node.is_left_child():
                node.parent.balance_factor += 1
            elif node.is_right_child():
                node.parent.balance_factor -= 1
            else:
                pass

            if node.parent.balance_factor != 0:
                self.update_balance(node.parent)
{'fraction_non_alphanumeric': 0.07289293849658314, 'fraction_numerical': 0.004555808656036446, 'mean_word_length': 2.163544668587896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '55066', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1256, 'n_words': 251}