<commit_before>package de.fosd.jdime.matcher.ordered.mceSubtree;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import de.fosd.jdime.common.Artifact;
import org.apache.commons.lang3.tuple.Pair;

/**
 * Trees can be described as balanced sequences. A balanced sequence is a sequence of even length over the alphabet
 * {0, 1} here represented by a boolean array. The balanced sequence of a leaf node is the empty sequence.
 * The balanced sequence of a non leaf node is the concatenation of the balanced sequences of its children, every
 * one preceded by a 0 and followed by a 1. The balanced sequence of a tree is the balanced sequence of its root node.
 *
 * @author <NAME>
 * @see <a href="http://www.cs.upc.edu/~antoni/subtree.pdf">This Paper</a>
 */
public class BalancedSequence {

	private static final BalancedSequence EMPTY_SEQ = new BalancedSequence(new boolean[0]);

	private boolean[] seq;

	/**
	 * Constructs a new <code>BalancedSequence</code> representing the given <code>tree</code> structure.
	 *
	 * @param tree
	 * 		the tree of <code>Artifact</code>s
	 * @param <T>
	 * 		the type of the <code>Artifact</code>
	 */
	public <T extends Artifact<T>> BalancedSequence(Artifact<T> tree) {
		this.seq = new boolean[tree.getSubtreeSize() * 2];
		initSeq(tree, 0);
	}

	/**
	 * Constructs a new <code>BalancedSequence</code> wrapping the given <code>boolean[]</code>.
	 *
	 * @param seq
	 * 		the sequence to wrap
	 */
	private BalancedSequence(boolean[] seq) {
		this.seq = seq;
	}
<commit_msg>adding method to count nodes to a given depth<commit_after>package de.fosd.jdime.matcher.ordered.mceSubtree;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import de.fosd.jdime.common.Artifact;
import org.apache.commons.lang3.tuple.Pair;

/**
 * Trees can be described as balanced sequences. A balanced sequence is a sequence of even length over the alphabet
 * {0, 1} here represented by a boolean array. The balanced sequence of a leaf node is the empty sequence.
 * The balanced sequence of a non leaf node is the concatenation of the balanced sequences of its children, every
 * one preceded by a 0 and followed by a 1. The balanced sequence of a tree is the balanced sequence of its root node.
 *
 * @author <NAME>
 * @see <a href="http://www.cs.upc.edu/~antoni/subtree.pdf">This Paper</a>
 */
public class BalancedSequence {

	private static final BalancedSequence EMPTY_SEQ = new BalancedSequence(new boolean[0]);

	private boolean[] seq;

	/**
	 * Constructs a new <code>BalancedSequence</code> representing the given <code>tree</code> structure.
	 *
	 * @param tree
	 * 		the tree of <code>Artifact</code>s
	 * @param <T>
	 * 		the type of the <code>Artifact</code>
	 */
	public <T extends Artifact<T>> BalancedSequence(Artifact<T> tree) {
		this.seq = new boolean[tree.getSubtreeSize() * 2];
		initSeq(tree, 0);
	}

	/**
	 * Constructs a new <code>BalancedSequence</code> wrapping the given <code>boolean[]</code>.
	 *
	 * @param seq
	 * 		the sequence to wrap
	 */
	private BalancedSequence(boolean[] seq) {
		this.seq = seq;
	}

    /**
     * Returns one less (the root node) than the number of nodes in the tree that have at most the given
     * <code>depth</code>.
     *
     * @param tree
     *         the tree whose nodes are to be counted
     * @param depth
     *         the maximum depth of nodes to count
     * @param <T>
     *         the type of the artifact
     *
     * @return the number of nodes
     */
    private <T extends Artifact<T>> int getSize(Artifact<T> tree, int depth) {

        if (depth == 0) {
            return 0;
        }

        int num = tree.getNumChildren();

        for (T t : tree.getChildren()) {
            num += getSize(t, depth - 1);
        }

        return num;
    }
    
{'fraction_non_alphanumeric': 0.10920554854981085, 'fraction_numerical': 0.0047919293820933165, 'mean_word_length': 3.2371794871794872, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '532938', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1204, 'n_words': 431}