<commit_before>class GraphNode(object):
    def __init__(self, child, data, height):
        self.child = child
        self.data = data
        self.height = height


class IteratorGraph(object):
    def __init__(self, iterator):
        self.origin_iterator = iterator
        self.graph = self._construct(iterator)

    def __iter__(self):
        return IteratorGraph(self.origin_iterator)

    def next(self):
        if self.graph is None:
            raise StopIteration()
        else:
            node = self.graph
            self.graph = node.child
            return node

    def _construct(self, iterator):
        height = 0
        current_level = [iterator]
        next_level = []
        root = None

        while True:
            for it in current_level:
                next_level += it.get_parents()

            root = GraphNode(root, current_level, height)
            height += 1

            if len(next_level) < 1:
                break
            else:
                current_level = next_level
                next_level = []

        return root<commit_msg>ENH: changed draph generation<commit_after>class Node(object):
    def __init__(self, inputs, output, iterator):
        self.inputs = inputs
        self.output = output
        self.iterator = iterator


class Graph(object):
    @staticmethod
    def _construct(iterator):
        nodes = []
        queue = [(iterator, None)]  # (iterator, parent node)

        while len(queue) > 0:
            item = queue.pop()

            new_node = Node([], None, item[0])

            if item[1]:  # if this is a parent of a node, register itself as input and set the parent as output
                item[1].inputs.append(new_node)
                new_node.output = item[1]

            for parent in item[0].get_parents():
                queue.append((parent, new_node))

            nodes.append(new_node)

        return nodes

    def __init__(self, iterator):
        self.nodes = Graph._construct(iterator)
        self.origin_node = self.nodes[0]
{'fraction_non_alphanumeric': 0.09117647058823529, 'fraction_numerical': 0.004901960784313725, 'mean_word_length': 1.7997256515775035, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4845905', 'n_tokens_mistral': 565, 'n_tokens_neox': 536, 'n_words': 150}