<commit_before>class Node {
  constructor(val) {
    this.val = val;
    this.parent = null;
    this.children = [];
  }
}

class Tree {
  constructor(val) {
    /*
    ** If the tree is initialized with a value, set the root node
    ** otherwise set the root node as null
    ** Set the size of the tree appropriately
    */
    this._head = val ? new Node(val) : null;
    this.size = val ? 1 : 0;
  }

  searchDF(cb) {
    /*
    ** Depth-first traversal to visit the nodes of the tree
    ** and invoke a callback function on each node
    */
  }

  searchBF(cb) {
    /*
    ** Breadth-first traversal to visit the nodes of the tree
    ** and invoke a callback function on each node
    */
  }

  addNode(val, parent) {
    const _node = new Node(val);

    if (!this._head) {
      /*
      ** Assign the node to the root if no root node exists in the tree
      */
      this._head = _node;
    } else {
      /*
      ** Attach the new node to the referenced node (parent -> child)
      */
      _node.parent = parent;
      parent.children.push(_node);
    }
    /*
    ** Increment the size of the tree.
    ** Return the new node to be used as a future reference if needed
    */
    this.size++;
    return _node;
  }
}<commit_msg>Tree implementation with searchDF, searchBF, addNode functions<commit_after>class Node {
  constructor(val) {
    this.val = val;
    this.parent = null;
    this.children = [];
  }
}

class Tree {
  constructor(val) {
    /*
    ** If the tree is initialized with a value, set the root node
    ** otherwise set the root node as null
    ** Set the size of the tree appropriately
    */
    this._head = val ? new Node(val) : null;
    this.size = val ? 1 : 0;
  }

  searchDF(cb, node = this._head) {
    /*
    ** Depth-first traversal to visit the nodes of the tree
    ** and invoke a callback function on each node
    */
    cb(node);
    for (let i = 0; i < node.children.length; i++) {
      searchDF(cb, node.children[i]);
    }
  }

  searchBF(cb, queue = [this._head]) {
    /*
    ** Breadth-first traversal to visit the nodes of the tree
    ** and invoke a callback function on each node
    */
    var node = queue.shift();
    for (let i = 0; i < node.children.length; i++) {
      queue.push(node.children[i]);
    }
    cb(node);
    if (queue.length) {
      this.searchBF(cb, queue);
    }
  }

  addNode(val, parent) {
    const _node = new Node(val);

    if (!this._head) {
      /*
      ** Assign the node to the root if no root node exists in the tree
      */
      this._head = _node;
    } else if (parent) {
      /*
      ** Attach the new node to the referenced node (parent -> child)
      */
      _node.parent = parent;
      parent.children.push(_node);
    } else {
      /*
      ** If there is no referenced parent node, throw Error
      */
      throw new Error('Need a parent node to add the new node to.');
    }
    /*
    ** Increment the size of the tree.
    ** Return the new node to be used as a future reference if needed
    */
    this.size++;
    return _node;
  }
}
{'fraction_non_alphanumeric': 0.11480756686236138, 'fraction_numerical': 0.0019569471624266144, 'mean_word_length': 2.054780876494024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3693695', 'n_tokens_mistral': 970, 'n_tokens_neox': 948, 'n_words': 344}