<commit_before>// External
import isFinite from '../../../node_modules/lodash-es/isFinite';

// Internal
import { collectInclClones } from './utils';

function _up (node, callback, depth, includeClones, child, visitedNodes) {
  if (visitedNodes[node.id]) {
    return;
  }

  const nodes = includeClones ? collectInclClones(node) : [node];

  for (let i = nodes.length; i--;) {
    if (child) {
      callback(nodes[i], child);
    }

    visitedNodes[nodes[i].id] = true;

    if (!isFinite(depth) || depth > 0) {
      const parentsId = Object.keys(nodes[i].parents);
      for (let j = parentsId.length; j--;) {
        _up(
          nodes[i].parents[parentsId[j]],
          callback,
          depth - 1,
          includeClones,
          nodes[i],
          visitedNodes
        );
      }
    }
  }
}

export function up (node, callback, depth, includeClones, child) {
  const visitedNodes = {};
  _up(node, callback, depth, includeClones, child, visitedNodes);
}

function _down (node, callback, depth, includeClones, visitedNodes) {
  if (visitedNodes[node.id]) {<commit_msg>Still trigger call backs for visited nodes but do not traverse the parents again.<commit_after>// External
import isFinite from '../../../node_modules/lodash-es/isFinite';

// Internal
import { collectInclClones } from './utils';

function _up (node, callback, depth, includeClones, child, visitedNodes) {
  if (visitedNodes[node.id]) {
    if (!visitedNodes[node.id][child.id]) {
      callback(node, child);
    }
    return;
  }

  const nodes = includeClones ? collectInclClones(node) : [node];

  for (let i = nodes.length; i--;) {
    visitedNodes[nodes[i].id] = {};

    if (child) {
      callback(nodes[i], child);
      visitedNodes[nodes[i].id][child.id] = true;
    }

    if (!isFinite(depth) || depth > 0) {
      const parentsId = Object.keys(nodes[i].parents);
      for (let j = parentsId.length; j--;) {
        _up(
          nodes[i].parents[parentsId[j]],
          callback,
          depth - 1,
          includeClones,
          nodes[i],
          visitedNodes
        );
      }
    }
  }
}

export function up (node, callback, depth, includeClones, child) {
  const visitedNodes = {};
  _up(node, callback, depth, includeClones, child, visitedNodes);
}

function _down (node, callback, depth, includeClones, visitedNodes) {
  if (visitedNodes[node.id]) {
{'fraction_non_alphanumeric': 0.14702154626108999, 'fraction_numerical': 0.0016899028305872412, 'mean_word_length': 2.7350157728706623, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3207189', 'n_tokens_mistral': 771, 'n_tokens_neox': 759, 'n_words': 184}