<commit_before>function BST() {
this.root = null;
}

BST.prototype = {

    //searching for a value using key. this returns the object of the same key
    //return null id not exist
    Search: function (key) {
        if (this.root === null) return null;
        var current = this.root;

        while (current) {
            if (key < current.data.key) current = current.left;
            else if (key > current.data.value) current = current.right;
            else return current.data;
        }
        return null;
    },

    //checking for contains a key
    //return boolean
    Contains: function (key) {
        if (this.root === null) return false;
        var current = this.root;
        while (current) {
            if (key < current.data.key) current = current.left;
            else if (key > current.data.key) current = current.right;
            else return true; 
        }
        return false;
    },
    
    //insert a node to the tree (object must have key property on it.)
    Insert: function (data) {
        if (data.key === null)  return false;
        var node = { data: data, left: null, right: null };
        var current = null;

        if (this.root == null) this.root = node;
        else {
            current = this.root;

            while (true) {
                if (data.key < current.data.key) {
                    if (current.left === null) current.left = node;
                    else current = current.left;
                }
                else if (data.key > current.data.key) {
                    if (current.right === null) current.right = node;
                    else current = current.right;
                }
                else break;

            }
        }
    },

    //inset array of objects
    InsertRange: function (range) {
        if (range.length > 0) {
            for (i = 0; i < range.length; i++) this.Insert(range[i]);
        }
    },

    //helpful when counting 
    Traverse: function (process) {
        function InOrder(node) {
            if (node) {
                if (node.left !== null) InOrder(node.left);
                process.call(this, node);
                if (node.right !== null) InOrder(node.right);
            }
        }
        InOrder(this.root);
    },

    //get the min value of the tree
    Min: function () {
        if (this.root) {
            var Current = this.root;
            while (Current.left) Current = Current.left;
            return Current.data;
        }

    },

    //get maximum value of the tree
    Max: function () {
        if (this.root) {
            var Current = this.root;
            while (Current.right) Current = Current.right;
            return Current.data;
        }
    },

    //get number of nodes of the tree
    Size: function () {
        var length = 0;
        this.Traverse(function (node) {
            length++;
        });
        return length;
    },

    //returns tree as array
    toArray: function () {
        var result = [];

        this.Traverse(function (node) {
            result.push(node.data);
        });

        return result;
    },

    //returns tree as a string
    toString: function () {
        return this.toArray().toString();
    },

    //remove node from the tree 
    Remove: function (key) {
        var found = false,
            parent = null,
            current = this.root,
            ChildCount = null, replacement = null, replacementParent = null;

        while (!found && current) {
            if (key < current.data.key) {
                parent = current;
                current = current.left;
            }
            else if (key > current.data.key) {
                parent = current;
                current = current.right;
            }
            else found = true;
        }

        if (found) {
            ChildCount = (current.left !== null ? 1 : 0) + (current.right !== null ? 1 : 0);
            if (current === this.root) {
                switch (ChildCount) {
                    case 0:
                        this.root = null;
                        break;
                    case 1:
                        this.root = (current.right === null ? current.left : current.right);
                        break;
                    case 2:
                        replacement = this.root.left;

                        while (replacement.right !== null) {
                            replacementParent = replacement;
                            replacement = replacement.right;
                        }

                        if (replacementParent !== null) {
                            replacementParent.right = replacement.left;

                            replacement.right = this.root.right;
                            replacement.left = this.root.left;
                        }
                        else replacement.right = this.root.right;

                        this.root = replacement;
                        break;
                }
            }
            else {
                switch (ChildCount) {
                    case 0:
                        if (current.data.key < parent.data.key) parent.left = null;
                        else parent.right = null
                        break;
                    case 1:
                        if (current.data.key < parent.data.key) {
                            parent.left = (current.left === null ? current.right : current.left);
                        }
                        else {
                            parent.right = (current.left === null ? current.right : current.left);
                        }
                        break;
                    case 2:
                        replacement = current.left;
                        replacementParent = current;

                        while (replacement.right !== null) {
                            replacementParent = replacement;
                            replacement = replacement.right;
                        }

                        replacementParent.right = replacement.left;

                        replacement.right = current.right;
                        replacement.left = current.left;

                        if (current.data.key < replacement.data.key) parent.left = replacement;
                        else parent.right = replacement;

                        break;
<commit_msg>changed if statements<commit_after>function BST() {
this.root = null;
}

BST.prototype = {

    //searching for a value using key. this returns the object of the same key
    //return null id not exist
    Search: function (key) {
        if (!this.root) return null;
        var current = this.root;

        while (current) {
            if (key < current.data.key) current = current.left;
            else if (key > current.data.value) current = current.right;
            else return current.data;
        }
        return null;
    },

    //checking for contains a key
    //return boolean
    Contains: function (key) {
        if (!this.root) return false;
        var current = this.root;
        while (current) {
            if (key < current.data.key) current = current.left;
            else if (key > current.data.key) current = current.right;
            else return true; 
        }
        return false;
    },
    
    //insert a node to the tree (object must have key property on it.)
    Insert: function (data) {
        if (!data.key)  return false;
        var node = { data: data, left: null, right: null };
        var current = null;

        if (!this.root) this.root = node;
        else {
            current = this.root;

            while (true) {
                if (data.key < current.data.key) {
                    if (!current.left) current.left = node;
                    else current = current.left;
                }
                else if (data.key > current.data.key) {
                    if (!current.right) current.right = node;
                    else current = current.right;
                }
                else break;

            }
        }
    },

    //inset array of objects
    InsertRange: function (range) {
        if (range.length > 0) {
            for (i = 0; i < range.length; i++) this.Insert(range[i]);
        }
    },

    //helpful when counting 
    Traverse: function (process) {
        function InOrder(node) {
            if (node) {
                if (node.left) InOrder(node.left);
                process.call(this, node);
                if (node.right) InOrder(node.right);
            }
        }
        InOrder(this.root);
    },

    //get the min value of the tree
    Min: function () {
        if (this.root) {
            var Current = this.root;
            while (Current.left) Current = Current.left;
            return Current.data;
        }

    },

    //get maximum value of the tree
    Max: function () {
        if (this.root) {
            var Current = this.root;
            while (Current.right) Current = Current.right;
            return Current.data;
        }
    },

    //get number of nodes of the tree
    Size: function () {
        var length = 0;
        this.Traverse(function (node) {
            length++;
        });
        return length;
    },

    //returns tree as array
    toArray: function () {
        var result = [];

        this.Traverse(function (node) {
            result.push(node.data);
        });

        return result;
    },

    //returns tree as a string
    toString: function () {
        return this.toArray().toString();
    },

    //remove node from the tree 
    Remove: function (key) {
        var found = false,
            parent = null,
            current = this.root,
            ChildCount = null, replacement = null, replacementParent = null;

        while (!found && current) {
            if (key < current.data.key) {
                parent = current;
                current = current.left;
            }
            else if (key > current.data.key) {
                parent = current;
                current = current.right;
            }
            else found = true;
        }

        if (found) {
            ChildCount = (current.left ? 1 : 0) + (current.right ? 1 : 0);
            if (current === this.root) {
                switch (ChildCount) {
                    case 0:
                        this.root = null;
                        break;
                    case 1:
                        this.root = (!current.right ? current.left : current.right);
                        break;
                    case 2:
                        replacement = this.root.left;

                        while (replacement.right) {
                            replacementParent = replacement;
                            replacement = replacement.right;
                        }

                        if (replacementParent) {
                            replacementParent.right = replacement.left;

                            replacement.right = this.root.right;
                            replacement.left = this.root.left;
                        }
                        else replacement.right = this.root.right;

                        this.root = replacement;
                        break;
                }
            }
            else {
                switch (ChildCount) {
                    case 0:
                        if (current.data.key < parent.data.key) parent.left = null;
                        else parent.right = null
                        break;
                    case 1:
                        if (current.data.key < parent.data.key) {
                            parent.left = (!current.left ? current.right : current.left);
                        }
                        else {
                            parent.right = (!current.left ? current.right : current.left);
                        }
                        break;
                    case 2:
                        replacement = current.left;
                        replacementParent = current;

                        while (replacement.right) {
                            replacementParent = replacement;
                            replacement = replacement.right;
                        }

                        replacementParent.right = replacement.left;

                        replacement.right = current.right;
                        replacement.left = current.left;

                        if (current.data.key < replacement.data.key) parent.left = replacement;
                        else parent.right = replacement;

                        break;

{'fraction_non_alphanumeric': 0.0962787015043547, 'fraction_numerical': 0.002058590657165479, 'mean_word_length': 1.0908789935441152, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, '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': '6022424', 'n_tokens_mistral': 3143, 'n_tokens_neox': 2964, 'n_words': 842}