<commit_before>import random
import time


class BSTree(object):
    def __init__(self, *val):
        """Initialize a "leaf" of the tree to have a None value"""
        if val != ():
            self.val = val[0]
            self.left = BSTree()
            self.right = BSTree()
        else:
            self.val = None
            self.left = None
            self.right = None

    def __str__(self):
        """Return a string of all of the elements in the
        tree and its decendents in order"""
        result = ''
        if self.left.val is not None:
            result += str(self.left)
        result += "%s " % str(self.val)
        if self.right.val is not None:
            result += str(self.right)
        return result

    def insert(self, val):
        """Insert a value below the root of the tree"""
        if self.val is None:
            self.__init__(val)
        elif self.val > val:
            self.left.insert(val)
        elif self.val < val:
            self.right.insert(val)

    def contains(self, val):
        """Return whether the item is contained in the tree"""
        if self.val is None:
            return False
        elif self.val == val:
            return True
        elif self.val > val:
            return self.left.contains(val)
        return self.right.contains(val)

    def size(self):
        """Return the size of the tree"""
        count = 0
        if self.val is None:
            return count
        else:
            count += 1
        count += self.left.size()
        count += self.right.size()
        return count

    def depth(self):
        """Return the maximum depth of the tree"""
        result = 0
        if self.val is None:
            return result
        return max(self.left.depth() + 1, self.right.depth() + 1)

    def balance(self):
        """Return a value representing the balance of the tree"""
        if self.val is None:
            return 0
        return self.left.depth() - self.right.depth()

    def get_dot(self):
        """return the tree with root 'self' as a dot graph for visualization"""
        return "digraph G{\n%s}" % ("" if self.val is None else (
            "\t%s;\n%s\n" % (
                self.val,
                "\n".join(self._get_dot())
            )
        ))

    def _get_dot(self):
        """recursively prepare a dot graph entry for this node."""
        if self.left is not None:
            yield "\t%s -> %s;" % (self.val, self.left.val)
            for i in self.left._get_dot():
                yield i
        elif self.right is not None:
            r = random.randint(0, 1e9)
            yield "\tnull%s [shape=point];" % r
            yield "\t%s -> null%s;" % (self.val, r)
        if self.right is not None:
            yield "\t%s -> %s;" % (self.val, self.right.val)<commit_msg>Better Depth<commit_after>import random
import time


class BSTree(object):
    def __init__(self, *val):
        """Initialize a "leaf" of the tree to have a None value"""
        if val != ():
            self.val = val[0]
            self.left = BSTree()
            self.right = BSTree()
        else:
            self.val = None
            self.left = None
            self.right = None

    def __str__(self):
        """Return a string of all of the elements in the
        tree and its decendents in order"""
        result = ''
        if self.left.val is not None:
            result += str(self.left)
        result += "%s " % str(self.val)
        if self.right.val is not None:
            result += str(self.right)
        return result

    def insert(self, val):
        """Insert a value below the root of the tree"""
        if self.val is None:
            self.__init__(val)
        elif self.val > val:
            self.left.insert(val)
        elif self.val < val:
            self.right.insert(val)

    def contains(self, val):
        """Return whether the item is contained in the tree"""
        if self.val is None:
            return False
        elif self.val == val:
            return True
        elif self.val > val:
            return self.left.contains(val)
        return self.right.contains(val)

    def size(self):
        """Return the size of the tree"""
        count = 0
        if self.val is None:
            return count
        else:
            count += 1
        count += self.left.size()
        count += self.right.size()
        return count

    def depth(self):
        """Return the maximum depth of the tree"""
        result = 0
        if self.val is None:
            return result
        return max(self.left.depth(), self.right.depth()) + 1

    def balance(self):
        """Return a value representing the balance of the tree"""
        if self.val is None:
            return 0
        return self.left.depth() - self.right.depth()

    def get_dot(self):
        """return the tree with root 'self' as a dot graph for visualization"""
        return "digraph G{\n%s}" % ("" if self.val is None else (
            "\t%s;\n%s\n" % (
                self.val,
                "\n".join(self._get_dot())
            )
        ))

    def _get_dot(self):
        """recursively prepare a dot graph entry for this node."""
        if self.left is not None:
            yield "\t%s -> %s;" % (self.val, self.left.val)
            for i in self.left._get_dot():
                yield i
        elif self.right is not None:
            r = random.randint(0, 1e9)
            yield "\tnull%s [shape=point];" % r
            yield "\t%s -> null%s;" % (self.val, r)
        if self.right is not None:
            yield "\t%s -> %s;" % (self.val, self.right.val)
{'fraction_non_alphanumeric': 0.11784511784511785, 'fraction_numerical': 0.003367003367003367, 'mean_word_length': 1.5309417040358744, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1839479', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1601, 'n_words': 547}